aboutsummaryrefslogtreecommitdiff
path: root/gdb/infptrace.c
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@gnu.org>2004-08-22 19:03:41 +0000
committerMark Kettenis <kettenis@gnu.org>2004-08-22 19:03:41 +0000
commit8cbba7c88185e1f9775509402b24639eb3018e45 (patch)
treef2a6fe7989baea9f6c07967f4261d004efdbb801 /gdb/infptrace.c
parentc5fa424560dd1098617ee6df456a7d4b4fb5f9f1 (diff)
downloadgdb-8cbba7c88185e1f9775509402b24639eb3018e45.zip
gdb-8cbba7c88185e1f9775509402b24639eb3018e45.tar.gz
gdb-8cbba7c88185e1f9775509402b24639eb3018e45.tar.bz2
* infptrace.c: Remove #ifdef'ed out inclusion of gdb_stat.h.
Reorder includes. (fetch_register, store_register): Remove prototypes. (child_resume): Reorganize code and comments such that it is grouped a bit more logically. (attach): Explicitly compare errno against 0. (detach): Likewise. Use perror_with_name instead of print_sys_errmsg. * Makefile.in (infptrace.o): Update dependencies.
Diffstat (limited to 'gdb/infptrace.c')
-rw-r--r--gdb/infptrace.c81
1 files changed, 32 insertions, 49 deletions
diff --git a/gdb/infptrace.c b/gdb/infptrace.c
index 7473781..0c59d8f 100644
--- a/gdb/infptrace.c
+++ b/gdb/infptrace.c
@@ -21,15 +21,16 @@
Boston, MA 02111-1307, USA. */
#include "defs.h"
+#include "command.h"
#include "frame.h"
+#include "gdbcore.h"
#include "inferior.h"
-#include "target.h"
-#include "gdb_string.h"
#include "regcache.h"
+#include "target.h"
+#include "gdb_assert.h"
#include "gdb_wait.h"
-
-#include "command.h"
+#include "gdb_string.h"
#ifdef USG
#include <sys/types.h>
@@ -42,18 +43,9 @@
#include "gdb_ptrace.h"
-#include "gdbcore.h"
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
-#if 0
-/* Don't think this is used anymore. On the sequent (not sure whether it's
- dynix or ptx or both), it is included unconditionally by sys/user.h and
- not protected against multiple inclusion. */
-#include "gdb_stat.h"
-#endif
-
-#include "gdb_assert.h"
#if !defined (FETCH_INFERIOR_REGISTERS)
#include <sys/user.h> /* Probably need to poke the user structure */
@@ -63,11 +55,6 @@
static void udot_info (char *, int);
#endif
-#if !defined (FETCH_INFERIOR_REGISTERS)
-static void fetch_register (int);
-static void store_register (int);
-#endif
-
void _initialize_infptrace (void);
@@ -198,52 +185,48 @@ kill_inferior (void)
void
child_resume (ptid_t ptid, int step, enum target_signal signal)
{
+ int request = PT_CONTINUE;
int pid = PIDGET (ptid);
- errno = 0;
-
if (pid == -1)
/* Resume all threads. */
/* I think this only gets used in the non-threaded case, where "resume
all threads" and "resume inferior_ptid" are the same. */
pid = PIDGET (inferior_ptid);
- /* An address of (PTRACE_TYPE_ARG3)1 tells ptrace to continue from where
- it was. (If GDB wanted it to start some other way, we have already
- written a new PC value to the child.)
-
- If this system does not support PT_STEP, a higher level function will
- have called single_step() to transmute the step request into a
- continue request (by setting breakpoints on all possible successor
- instructions), so we don't have to worry about that here. */
-
if (step)
{
- if (SOFTWARE_SINGLE_STEP_P ())
- internal_error (__FILE__, __LINE__, "failed internal consistency check"); /* Make sure this doesn't happen. */
- else
- ptrace (PT_STEP, pid, (PTRACE_TYPE_ARG3) 1,
- target_signal_to_host (signal));
+ /* If this system does not support PT_STEP, a higher level
+ function will have called single_step() to transmute the step
+ request into a continue request (by setting breakpoints on
+ all possible successor instructions), so we don't have to
+ worry about that here. */
+
+ gdb_assert (!SOFTWARE_SINGLE_STEP_P ());
+ request = PT_STEP;
}
- else
- ptrace (PT_CONTINUE, pid, (PTRACE_TYPE_ARG3) 1,
- target_signal_to_host (signal));
- if (errno)
- {
- perror_with_name ("ptrace");
- }
+ /* An address of (PTRACE_TYPE_ARG3)1 tells ptrace to continue from
+ where it was. If GDB wanted it to start some other way, we have
+ already written a new PC value to the child. */
+
+ errno = 0;
+ ptrace (request, pid, (PTRACE_TYPE_ARG3)1, target_signal_to_host (signal));
+ if (errno != 0)
+ perror_with_name ("ptrace");
}
#endif /* CHILD_RESUME */
+
/* Start debugging the process whose number is PID. */
+
int
attach (int pid)
{
#ifdef PT_ATTACH
errno = 0;
ptrace (PT_ATTACH, pid, (PTRACE_TYPE_ARG3) 0, 0);
- if (errno)
+ if (errno != 0)
perror_with_name ("ptrace");
attach_flag = 1;
return pid;
@@ -252,19 +235,19 @@ attach (int pid)
#endif
}
-/* Stop debugging the process whose number is PID
- and continue it with signal number SIGNAL.
- SIGNAL = 0 means just continue it. */
+/* Stop debugging the process whose number is PID and continue it with
+ signal number SIGNAL. SIGNAL = 0 means just continue it. */
void
detach (int signal)
{
#ifdef PT_DETACH
+ int pid = PIDGET (inferior_ptid);
+
errno = 0;
- ptrace (PT_DETACH, PIDGET (inferior_ptid), (PTRACE_TYPE_ARG3) 1,
- signal);
- if (errno)
- print_sys_errmsg ("ptrace", errno);
+ ptrace (PT_DETACH, pid, (PTRACE_TYPE_ARG3) 1, signal);
+ if (errno != 0)
+ perror_with_name ("ptrace");
attach_flag = 0;
#else
error ("This system does not support detaching from a process");