Sun Aug 1 22:58:18 1993 Stu Grossman (grossman at cygnus.com)
[deliverable/binutils-gdb.git] / gdb / hppab-nat.c
index c0c49b8c204962685683bc9223a416b91a6ec0c9..42fe316606d70c9d06191381e32b7d27292801f6 100644 (file)
@@ -1,7 +1,7 @@
 /* Machine-dependent hooks for the unix child process stratum.  This
    code is for the HP PA-RISC cpu.
 
-   Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
+   Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
 
    Contributed by the Center for Software Science at the
    University of Utah (pa-gdb-bugs@cs.utah.edu).
@@ -24,10 +24,20 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include "defs.h"
 #include "inferior.h"
+#include "target.h"
+#include <sys/ptrace.h>
+
+#ifdef FIVE_ARG_PTRACE
+
+/* Deal with HPUX 8.0 braindamage.  */
+#define ptrace(a,b,c,d) ptrace(a,b,c,d,0)
+
+#endif
 
 #ifndef PT_ATTACH
 #define PT_ATTACH PTRACE_ATTACH
 #endif
+
 #ifndef PT_DETACH
 #define PT_DETACH PTRACE_DETACH
 #endif
@@ -35,7 +45,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* This function simply calls ptrace with the given arguments.  
    It exists so that all calls to ptrace are isolated in this 
    machine-dependent file. */
-#ifdef WANT_NATIVE_TARGET
+
 int
 call_ptrace (request, pid, addr, data)
      int request, pid;
@@ -44,7 +54,6 @@ call_ptrace (request, pid, addr, data)
 {
   return ptrace (request, pid, addr, data);
 }
-#endif /* WANT_NATIVE_TARGET */
 
 #ifdef DEBUG_PTRACE
 /* For the rest of the file, use an extra level of indirection */
@@ -95,8 +104,6 @@ detach (signal)
 \f
 
 
-#if !defined (FETCH_INFERIOR_REGISTERS)
-
 /* KERNEL_U_ADDR is the amount to subtract from u.u_ar0
    to get the offset in the core file of the register values.  */
 #if defined (KERNEL_U_ADDR_BSD)
@@ -154,11 +161,6 @@ void _initialize_kernel_u_addr ()
     - KERNEL_U_ADDR
 #endif
 
-/* Registers we shouldn't try to fetch.  */
-#if !defined (CANNOT_FETCH_REGISTER)
-#define CANNOT_FETCH_REGISTER(regno) 0
-#endif
-
 /* Fetch one register.  */
 
 static void
@@ -167,19 +169,11 @@ fetch_register (regno)
 {
   register unsigned int regaddr;
   char buf[MAX_REGISTER_RAW_SIZE];
-  char mess[128];                              /* For messages */
   register int i;
 
   /* Offset of registers within the u area.  */
   unsigned int offset;
 
-  if (CANNOT_FETCH_REGISTER (regno))
-    {
-      bzero (buf, REGISTER_RAW_SIZE (regno));  /* Supply zeroes */
-      supply_register (regno, buf);
-      return;
-    }
-
   offset = U_REGS_OFFSET;
 
   regaddr = register_addr (regno, offset);
@@ -191,17 +185,21 @@ fetch_register (regno)
       regaddr += sizeof (int);
       if (errno != 0)
        {
-         sprintf (mess, "reading register %s (#%d)", reg_names[regno], regno);
-         perror_with_name (mess);
+         /* Warning, not error, in case we are attached; sometimes the
+            kernel doesn't let us at the registers.  */
+         char *err = safe_strerror (errno);
+         char *msg = alloca (strlen (err) + 128);
+         sprintf (msg, "reading register %s: %s", reg_names[regno], err);
+         warning (msg);
+         goto error_exit;
        }
     }
   supply_register (regno, buf);
+ error_exit:;
 }
 
-#endif /* !defined (FETCH_INFERIOR_REGISTERS).  */
 /* Fetch all registers, or just one, from the child process.  */
 
-#ifndef FETCH_INFERIOR_REGISTERS
 void
 fetch_inferior_registers (regno)
      int regno;
@@ -213,11 +211,6 @@ fetch_inferior_registers (regno)
     fetch_register (regno);
 }
 
-/* Registers we shouldn't try to store.  */
-#if !defined (CANNOT_STORE_REGISTER)
-#define CANNOT_STORE_REGISTER(regno) 0
-#endif
-
 /* Store our register values back into the inferior.
    If REGNO is -1, do this for all registers.
    Otherwise, REGNO specifies which register (so we can save time).  */
@@ -227,7 +220,6 @@ store_inferior_registers (regno)
      int regno;
 {
   register unsigned int regaddr;
-  char buf[80];
   extern char registers[];
   register int i;
 
@@ -239,12 +231,14 @@ store_inferior_registers (regno)
       for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof(int))
        {
          errno = 0;
-         ptrace (PT_WRITE_U, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
+         ptrace (PT_WUREGS, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
                  *(int *) &registers[REGISTER_BYTE (regno) + i]);
          if (errno != 0)
            {
-             sprintf (buf, "writing register number %d(%d)", regno, i);
-             perror_with_name (buf);
+             char *err = safe_strerror (errno);
+             char *msg = alloca (strlen (err) + 128);
+             sprintf (msg, "writing register %s: %s", reg_names[regno], err);
+             warning (msg);
            }
          regaddr += sizeof(int);
        }
@@ -255,31 +249,19 @@ store_inferior_registers (regno)
        {
          if (CANNOT_STORE_REGISTER (regno))
            continue;
-         regaddr = register_addr (regno, offset);
-         for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof(int))
-           {
-             errno = 0;
-             ptrace (PT_WRITE_U, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
-                     *(int *) &registers[REGISTER_BYTE (regno) + i]);
-             if (errno != 0)
-               {
-                 sprintf (buf, "writing register number %d(%d)", regno, i);
-                 perror_with_name (buf);
-               }
-             regaddr += sizeof(int);
-           }
+         store_inferior_registers (regno);
        }
     }
   return;
 }
-#endif /* !defined(FETCH_INFERIOR_REGISTERS) */
 
-/* Resume execution of the inferior process.
+/* Resume execution of process PID.
    If STEP is nonzero, single-step it.
    If SIGNAL is nonzero, give it that signal.  */
 
 void
-child_resume (step, signal)
+child_resume (pid, step, signal)
+     int pid;
      int step;
      int signal;
 {
@@ -290,9 +272,9 @@ child_resume (step, signal)
      written a new PC value to the child.)  */
 
   if (step)
-    ptrace (PT_STEP, inferior_pid, (PTRACE_ARG3_TYPE) 1, signal);
+    ptrace (PT_STEP, pid, (PTRACE_ARG3_TYPE) 1, signal);
   else
-    ptrace (PT_CONTINUE, inferior_pid, (PTRACE_ARG3_TYPE) 1, signal);
+    ptrace (PT_CONTINUE, pid, (PTRACE_ARG3_TYPE) 1, signal);
 
   if (errno)
     perror_with_name ("ptrace");
This page took 0.026153 seconds and 4 git commands to generate.