2004-12-05 Randolph Chung <tausq@debian.org>
[deliverable/binutils-gdb.git] / gdb / infptrace.c
index 74737810fde583e305e97a56f681b885888138dc..1a1502950b1a876d1bbbb0db15afb9a8b6eab8c6 100644 (file)
    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"
-
-#ifdef USG
-#include <sys/types.h>
-#endif
+#include "gdb_string.h"
 
 #include <sys/param.h>
 #include "gdb_dirent.h"
 
 #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 */
 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);
 \f
 
-/* This function simply calls ptrace with the given arguments.  
-   It exists so that all calls to ptrace are isolated in this 
-   machine-dependent file. */
 int
 call_ptrace (int request, int pid, PTRACE_ARG3_TYPE addr, int data)
 {
-  int pt_status = 0;
-
-#if 0
-  int saved_errno;
-
-  printf ("call_ptrace(request=%d, pid=%d, addr=0x%x, data=0x%x)",
-         request, pid, addr, data);
-#endif
-#if defined(PT_SETTRC)
-  /* If the parent can be told to attach to us, try to do it.  */
-  if (request == PT_SETTRC)
-    {
-      errno = 0;
-#ifndef PTRACE_TYPE_ARG5
-      pt_status = ptrace (PT_SETTRC, pid, addr, data);
-#else
-      /* Deal with HPUX 8.0 braindamage.  We never use the
-         calls which require the fifth argument.  */
-      pt_status = ptrace (PT_SETTRC, pid, addr, data, 0);
-#endif
-      if (errno)
-       perror_with_name ("ptrace");
-#if 0
-      printf (" = %d\n", pt_status);
-#endif
-      if (pt_status < 0)
-       return pt_status;
-      else
-       return parent_attach_all (pid, addr, data);
-    }
-#endif
-
-#if defined(PT_CONTIN1)
-  /* On HPUX, PT_CONTIN1 is a form of continue that preserves pending
-     signals.  If it's available, use it.  */
-  if (request == PT_CONTINUE)
-    request = PT_CONTIN1;
-#endif
-
-#if defined(PT_SINGLE1)
-  /* On HPUX, PT_SINGLE1 is a form of step that preserves pending
-     signals.  If it's available, use it.  */
-  if (request == PT_STEP)
-    request = PT_SINGLE1;
-#endif
-
-#if 0
-  saved_errno = errno;
-  errno = 0;
-#endif
-#ifndef PTRACE_TYPE_ARG5
-  pt_status = ptrace (request, pid, addr, data);
-#else
-  /* Deal with HPUX 8.0 braindamage.  We never use the
-     calls which require the fifth argument.  */
-  pt_status = ptrace (request, pid, addr, data, 0);
-#endif
-
-#if 0
-  if (errno)
-    printf (" [errno = %d]", errno);
-
-  errno = saved_errno;
-  printf (" = 0x%x\n", pt_status);
-#endif
-  return pt_status;
+  return ptrace (request, pid, addr, data);
 }
 
-
-#if defined (DEBUG_PTRACE) || defined (PTRACE_TYPE_ARG5)
-/* For the rest of the file, use an extra level of indirection */
-/* This lets us breakpoint usefully on call_ptrace. */
-#define ptrace call_ptrace
-#endif
-
 /* Wait for a process to finish, possibly running a target-specific
    hook before returning.  */
 
+/* NOTE: cagney: 2004-09-29: Dependant on the native configuration,
+   "hppah-nat.c" may either call this or infttrace.c's implementation
+   of ptrace_wait.  See "hppahpux.mh".  */
+
 int
 ptrace_wait (ptid_t ptid, int *status)
 {
   int wstate;
 
   wstate = wait (status);
-  target_post_wait (pid_to_ptid (wstate), *status);
   return wstate;
 }
 
-#ifndef KILL_INFERIOR
+#ifndef DEPRECATED_KILL_INFERIOR
+/* NOTE: cagney/2004-09-12: Instead of definining this macro, code
+   should call inf_ptrace_target to get a basic ptrace target and then
+   locally update any necessary methods.  See ppcnbsd-nat.c.  */
+
 void
 kill_inferior (void)
 {
@@ -184,12 +99,15 @@ kill_inferior (void)
      The kill call causes problems under hpux10, so it's been removed;
      if this causes problems we'll deal with them as they arise.  */
   ptrace (PT_KILL, pid, (PTRACE_TYPE_ARG3) 0, 0);
-  ptrace_wait (null_ptid, &status);
+  wait (&status);
   target_mourn_inferior ();
 }
-#endif /* KILL_INFERIOR */
+#endif /* DEPRECATED_KILL_INFERIOR */
 
-#ifndef CHILD_RESUME
+#ifndef DEPRECATED_CHILD_RESUME
+/* NOTE: cagney/2004-09-12: Instead of definining this macro, code
+   should call inf_ptrace_target to get a basic ptrace target and then
+   locally update any necessary methods.  See ppcnbsd-nat.c.  */
 
 /* Resume execution of the inferior process.
    If STEP is nonzero, single-step it.
@@ -198,52 +116,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 */
+#endif /* DEPRECATED_CHILD_RESUME */
 \f
+
 /* 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 +166,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");
@@ -414,8 +328,8 @@ store_inferior_registers (int regnum)
 
    Returns the length copied, which is either the LEN argument or
    zero.  This xfer function does not do partial moves, since
-   child_ops doesn't allow memory operations to cross below us in the
-   target stack anyway.  */
+   deprecated_child_ops doesn't allow memory operations to cross below
+   us in the target stack anyway.  */
 
 int
 child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
This page took 0.027141 seconds and 4 git commands to generate.