20000-05-18 H.J. Lu (hjl@gnu.org)
[binutils-gdb.git] / gdb / procfs.c
index 2dfde70e5c1459c99f95fb2af55af0ec66c6fe26..2fa825b41bc3a6b8a567d3f8b85fbb821e437b53 100644 (file)
@@ -38,8 +38,6 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include <signal.h>
 #include <ctype.h>
 
-#include "proc-utils.h"
-
 /* 
  * PROCFS.C
  *
@@ -85,6 +83,12 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include <unistd.h>    /* for "X_OK" */
 #include "gdb_stat.h"  /* for struct stat */
 
+/* Note: procfs-utils.h must be included after the above system header
+   files, because it redefines various system calls using macros.
+   This may be incompatible with the prototype declarations.  */
+
+#include "proc-utils.h"
+
 /* =================== TARGET_OPS "MODULE" =================== */
 
 /*
@@ -154,8 +158,8 @@ init_procfs_ops ()
   procfs_ops.to_thread_alive       = procfs_thread_alive;
   procfs_ops.to_pid_to_str         = procfs_pid_to_str;
 
-  procfs_ops.to_has_all_memory    = 1;
-  procfs_ops.to_has_memory        = 1;
+  procfs_ops.to_has_all_memory     = 1;
+  procfs_ops.to_has_memory         = 1;
   procfs_ops.to_has_execution      = 1;
   procfs_ops.to_has_stack          = 1;
   procfs_ops.to_has_registers      = 1;
@@ -166,36 +170,6 @@ init_procfs_ops ()
 
 /* =================== END, TARGET_OPS "MODULE" =================== */
 
-/*
- * Temporary debugging code:
- *
- * These macros allow me to trace the system calls that we make
- * to control the child process.  This is quite handy for comparing
- * with the older version of procfs.
- */
-
-#ifdef TRACE_PROCFS
-#ifdef NEW_PROC_API
-extern  int   write_with_trace PARAMS ((int, void *, size_t, char *, int));
-extern  off_t lseek_with_trace PARAMS ((int, off_t,  int,    char *, int));
-#define write(X,Y,Z)   write_with_trace (X, Y, Z, __FILE__, __LINE__)
-#define lseek(X,Y,Z)   lseek_with_trace (X, Y, Z, __FILE__, __LINE__)
-#else
-extern  int ioctl_with_trace PARAMS ((int, long, void *, char *, int));
-#define ioctl(X,Y,Z)   ioctl_with_trace (X, Y, Z, __FILE__, __LINE__)
-#endif
-#define open(X,Y)      open_with_trace  (X, Y,    __FILE__, __LINE__)
-#define close(X)       close_with_trace (X,       __FILE__, __LINE__)
-#define wait(X)        wait_with_trace  (X,       __FILE__, __LINE__)
-#define PROCFS_NOTE(X) procfs_note      (X,       __FILE__, __LINE__)
-#define PROC_PRETTYFPRINT_STATUS(X,Y,Z,T) \
-proc_prettyfprint_status (X, Y, Z, T)
-#else
-#define PROCFS_NOTE(X)
-#define PROC_PRETTYFPRINT_STATUS(X,Y,Z,T)
-#endif
-
-
 /*
  * World Unification:
  *
@@ -1391,7 +1365,7 @@ proc_stop_process (pi)
   else
     {
 #ifdef NEW_PROC_API
-      int cmd = PCSTOP;
+      long cmd = PCSTOP;
       win = (write (pi->ctl_fd, (char *) &cmd, sizeof (cmd)) == sizeof (cmd));
 #else  /* ioctl method */
       win = (ioctl (pi->ctl_fd, PIOCSTOP, &pi->prstatus) >= 0);
@@ -1435,7 +1409,7 @@ proc_wait_for_stop (pi)
 
 #ifdef NEW_PROC_API
   {
-    int cmd = PCWSTOP;
+    long cmd = PCWSTOP;
     win = (write (pi->ctl_fd, (char *) &cmd, sizeof (cmd)) == sizeof (cmd));
     /* We been runnin' and we stopped -- need to update status.  */
     pi->status_valid = 0;
@@ -1512,7 +1486,7 @@ proc_run_process (pi, step, signo)
 
 #ifdef NEW_PROC_API
   {
-    int cmd[2];
+    long cmd[2];
 
     cmd[0]  = PCRUN;
     cmd[1]  = runflags;
@@ -1558,7 +1532,7 @@ proc_set_traced_signals (pi, sigset)
 #ifdef NEW_PROC_API
   {
     struct {
-      int cmd;
+      long cmd;
       /* Use char array to avoid alignment issues.  */
       char sigset[sizeof (sigset_t)];
     } arg;
@@ -1606,7 +1580,7 @@ proc_set_traced_faults (pi, fltset)
 #ifdef NEW_PROC_API
   {
     struct {
-      int cmd;
+      long cmd;
       /* Use char array to avoid alignment issues.  */
       char fltset[sizeof (fltset_t)];
     } arg;
@@ -1652,7 +1626,7 @@ proc_set_traced_sysentry (pi, sysset)
 #ifdef NEW_PROC_API
   {
     struct {
-      int cmd;
+      long cmd;
       /* Use char array to avoid alignment issues.  */
       char sysset[sizeof (sysset_t)];
     } arg;
@@ -1698,7 +1672,7 @@ proc_set_traced_sysexit (pi, sysset)
 #ifdef NEW_PROC_API
   {
     struct {
-      int cmd;
+      long cmd;
       /* Use char array to avoid alignment issues.  */
       char sysset[sizeof (sysset_t)];
     } arg;
@@ -1744,7 +1718,7 @@ proc_set_held_signals (pi, sighold)
 #ifdef NEW_PROC_API
   {
     struct {
-      int cmd;
+      long cmd;
       /* Use char array to avoid alignment issues.  */
       char hold[sizeof (sigset_t)];
     } arg;
@@ -2162,7 +2136,7 @@ proc_clear_current_fault (pi)
 
 #ifdef NEW_PROC_API
   {
-    int cmd = PCCFAULT;
+    long cmd = PCCFAULT;
     win = (write (pi->ctl_fd, (void *) &cmd, sizeof (cmd)) == sizeof (cmd));
   }
 #else
@@ -2192,7 +2166,7 @@ proc_set_current_signal (pi, signo)
 {
   int win;
   struct {
-    int cmd;
+    long cmd;
     /* Use char array to avoid alignment issues.  */
     char sinfo[sizeof (struct siginfo)];
   } arg;
@@ -2262,7 +2236,7 @@ proc_clear_current_signal (pi)
 #ifdef NEW_PROC_API
   {
     struct {
-      int cmd;
+      long cmd;
       /* Use char array to avoid alignment issues.  */
       char sinfo[sizeof (struct siginfo)];
     } arg;
@@ -2422,7 +2396,7 @@ proc_set_gregs (pi)
     {
 #ifdef NEW_PROC_API
       struct {
-       int cmd;
+       long cmd;
        /* Use char array to avoid alignment issues.  */
        char gregs[sizeof (gdb_gregset_t)];
       } arg;
@@ -2466,7 +2440,7 @@ proc_set_fpregs (pi)
     {
 #ifdef NEW_PROC_API
       struct {
-       int cmd;
+       long cmd;
        /* Use char array to avoid alignment issues.  */
        char fpregs[sizeof (gdb_fpregset_t)];
       } arg;
@@ -2530,7 +2504,7 @@ proc_kill (pi, signo)
   else
     {
 #ifdef NEW_PROC_API
-      int cmd[2];
+      long cmd[2];
 
       cmd[0] = PCKILL;
       cmd[1] = signo;
@@ -2594,7 +2568,7 @@ proc_set_watchpoint (pi, addr, len, wflags)
   return 0;
 #else
   struct {
-    int cmd;
+    long cmd;
     char watch[sizeof (prwatch_t)];
   } arg;
   prwatch_t *pwatch;
@@ -3528,19 +3502,20 @@ procfs_fetch_registers (regno)
 
   supply_gregset (gregs);
 
-#if defined (FP0_REGNUM)       /* need floating point? */
-  if ((regno >= 0 && regno < FP0_REGNUM) ||
-      regno == PC_REGNUM  ||
-      (NPC_REGNUM >= 0 && regno == NPC_REGNUM) ||
-      regno == FP_REGNUM  ||
-      regno == SP_REGNUM)
-    return;                    /* not a floating point register */
+  if (FP0_REGNUM >= 0) /* need floating point? */
+    {
+      if ((regno >= 0 && regno < FP0_REGNUM) ||
+         regno == PC_REGNUM  ||
+         (NPC_REGNUM >= 0 && regno == NPC_REGNUM) ||
+         regno == FP_REGNUM  ||
+         regno == SP_REGNUM)
+       return;                 /* not a floating point register */
 
-  if ((fpregs = proc_get_fpregs (pi)) == NULL)
-    proc_error (pi, "fetch_registers, get_fpregs", __LINE__);
+      if ((fpregs = proc_get_fpregs (pi)) == NULL)
+       proc_error (pi, "fetch_registers, get_fpregs", __LINE__);
 
-  supply_fpregset (fpregs);
-#endif
+      supply_fpregset (fpregs);
+    }
 }
 
 /* Get ready to modify the registers array.  On machines which store
@@ -3602,21 +3577,22 @@ procfs_store_registers (regno)
   if (!proc_set_gregs (pi))
     proc_error (pi, "store_registers, set_gregs", __LINE__);
 
-#if defined (FP0_REGNUM)       /* need floating point? */
-  if ((regno >= 0 && regno < FP0_REGNUM) ||
-      regno == PC_REGNUM  ||
-      (NPC_REGNUM >= 0 && regno == NPC_REGNUM) ||
-      regno == FP_REGNUM  ||
-      regno == SP_REGNUM)
-    return;                    /* not a floating point register */
-
-  if ((fpregs = proc_get_fpregs (pi)) == NULL)
-    proc_error (pi, "store_registers, get_fpregs", __LINE__);
-
-  fill_fpregset (fpregs, regno);
-  if (!proc_set_fpregs (pi))
-    proc_error (pi, "store_registers, set_fpregs", __LINE__);
-#endif
+  if (FP0_REGNUM >= 0)         /* need floating point? */
+    {
+      if ((regno >= 0 && regno < FP0_REGNUM) ||
+         regno == PC_REGNUM  ||
+         (NPC_REGNUM >= 0 && regno == NPC_REGNUM) ||
+         regno == FP_REGNUM  ||
+         regno == SP_REGNUM)
+       return;                 /* not a floating point register */
+
+      if ((fpregs = proc_get_fpregs (pi)) == NULL)
+       proc_error (pi, "store_registers, get_fpregs", __LINE__);
+
+      fill_fpregset (fpregs, regno);
+      if (!proc_set_fpregs (pi))
+       proc_error (pi, "store_registers, set_fpregs", __LINE__);
+    }
 }
 
 /*
@@ -4137,14 +4113,13 @@ invalidate_cache (parent, pi, ptr)
       if (!proc_set_gregs (pi))        /* flush gregs cache */
        proc_warn (pi, "target_resume, set_gregs",
                   __LINE__);
-#ifdef FP0_REGNUM
-  if (pi->fpregs_dirty)
-    if (parent == NULL ||
-       proc_get_current_thread (parent) != pi->tid)
-      if (!proc_set_fpregs (pi))       /* flush fpregs cache */
-       proc_warn (pi, "target_resume, set_fpregs", 
-                  __LINE__);
-#endif
+  if (FP0_REGNUM >= 0)
+    if (pi->fpregs_dirty)
+      if (parent == NULL ||
+         proc_get_current_thread (parent) != pi->tid)
+       if (!proc_set_fpregs (pi))      /* flush fpregs cache */
+         proc_warn (pi, "target_resume, set_fpregs", 
+                    __LINE__);
 #endif
 
   if (parent != NULL)
@@ -4460,7 +4435,7 @@ unconditionally_kill_inferior (pi)
   }
 #else /* PROCFS_NEED_PIOCSSIG_FOR_KILL */
   if (!proc_kill (pi, SIGKILL))
-    proc_warn (pi, "unconditionally_kill, proc_kill", __LINE__);
+    proc_error (pi, "unconditionally_kill, proc_kill", __LINE__);
 #endif /* PROCFS_NEED_PIOCSSIG_FOR_KILL */
   destroy_procinfo (pi);