Fix my last change to actually compile.
[deliverable/binutils-gdb.git] / gdb / procfs.c
index 67d1c3ccd168f4ababfea0d59e4447cb70d63665..5675edab480b98acdcc3b5372128d5e9764bcaf0 100644 (file)
@@ -1,5 +1,5 @@
 /* Machine independent support for SVR4 /proc (process file system) for GDB.
-   Copyright 1999 Free Software Foundation, Inc.
+   Copyright 1999-2000 Free Software Foundation, Inc.
    Written by Michael Snyder at Cygnus Solutions.
    Based on work by Fred Fish, Stu Grossman, Geoff Noer, and others.
 
@@ -24,6 +24,7 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "target.h"
 #include "gdbcore.h"
 #include "gdbcmd.h"
+#include "gdbthread.h"
 
 #if defined (NEW_PROC_API)
 #define _STRUCTURED_PROC 1     /* Should be done by configure script. */
@@ -33,6 +34,9 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include <sys/fault.h>
 #include <sys/syscall.h>
 #include <sys/errno.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include <ctype.h>
 
 /* 
  * PROCFS.C
@@ -72,48 +76,55 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #ifdef NEW_PROC_API
 #include <sys/types.h>
-#include <dirent.h>    /* opendir/readdir, for listing the LWP's */
+#include "gdb_dirent.h"        /* opendir/readdir, for listing the LWP's */
 #endif
 
 #include <fcntl.h>     /* for O_RDONLY */
 #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"
+
+/* Prototypes for supply_gregset etc. */
+#include "gregset.h"
+
 /* =================== TARGET_OPS "MODULE" =================== */
 
 /*
  * This module defines the GDB target vector and its methods.
  */
 
-static void procfs_open              PARAMS((char *, int));
-static void procfs_attach            PARAMS ((char *, int));
-static void procfs_detach            PARAMS ((char *, int));
-static void procfs_resume            PARAMS ((int, int, enum target_signal));
-static int  procfs_can_run           PARAMS ((void));
-static void procfs_stop              PARAMS ((void));
-static void procfs_files_info        PARAMS ((struct target_ops *));
-static void procfs_fetch_registers   PARAMS ((int));
-static void procfs_store_registers   PARAMS ((int));
-static void procfs_notice_signals    PARAMS ((int));
-static void procfs_prepare_to_store  PARAMS ((void));
-static void procfs_kill_inferior     PARAMS ((void));
-static void procfs_mourn_inferior    PARAMS ((void));
-static void procfs_create_inferior   PARAMS ((char *, char *, char **));
-static int  procfs_wait              PARAMS ((int, 
-                                              struct target_waitstatus *));
-static int  procfs_xfer_memory       PARAMS ((CORE_ADDR, 
-                                              char *, int, int, 
-                                              struct target_ops *));
-
-static int  procfs_thread_alive      PARAMS ((int));
-
-void procfs_find_new_threads         PARAMS ((void));
-char *procfs_pid_to_str              PARAMS ((int));
+static void procfs_open (char *, int);
+static void procfs_attach (char *, int);
+static void procfs_detach (char *, int);
+static void procfs_resume (int, int, enum target_signal);
+static int procfs_can_run (void);
+static void procfs_stop (void);
+static void procfs_files_info (struct target_ops *);
+static void procfs_fetch_registers (int);
+static void procfs_store_registers (int);
+static void procfs_notice_signals (int);
+static void procfs_prepare_to_store (void);
+static void procfs_kill_inferior (void);
+static void procfs_mourn_inferior (void);
+static void procfs_create_inferior (char *, char *, char **);
+static int procfs_wait (int, struct target_waitstatus *);
+static int procfs_xfer_memory (CORE_ADDR,
+                              char *, int, int, struct target_ops *);
+
+static int procfs_thread_alive (int);
+
+void procfs_find_new_threads (void);
+char *procfs_pid_to_str (int);
 
 struct target_ops procfs_ops;          /* the target vector */
 
 static void
-init_procfs_ops ()
+init_procfs_ops (void)
 {
   procfs_ops.to_shortname          = "procfs";
   procfs_ops.to_longname           = "Unix /proc child process";
@@ -148,6 +159,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_execution      = 1;
   procfs_ops.to_has_stack          = 1;
   procfs_ops.to_has_registers      = 1;
@@ -158,52 +171,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));
-
-#if 0
-#define write(X,Y,Z)   write_with_trace (X, Y, Z, __FILE__, __LINE__)
-#endif
-
-#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__)
-
-#if 0
-#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
-
-#else
-#define PROCFS_NOTE(X)
-#define PROC_PRETTYFPRINT_STATUS(X,Y,Z,T)
-#endif
-
-     /* temp: */
-#undef  PROCFS_NOTE
-#define PROCFS_NOTE(X)
-     /* suppress */
-
-
 /*
  * World Unification:
  *
@@ -279,38 +246,15 @@ typedef prstatus_t gdb_prstatus_t;
 typedef prstatus_t gdb_lwpstatus_t;
 #endif /* NEW_PROC_API */
 
-
-/* These #ifdefs are for sol2.x in particular.  sol2.x has
-   both a "gregset_t" and a "prgregset_t", which have
-   similar uses but different layouts.  sol2.x gdb tries to
-   use prgregset_t (and prfpregset_t) everywhere. */
-
-#ifdef GDB_GREGSET_TYPE
-  typedef GDB_GREGSET_TYPE gdb_gregset_t;
-#else
-  typedef gregset_t gdb_gregset_t;
-#endif
-
-#ifdef GDB_FPREGSET_TYPE
-  typedef GDB_FPREGSET_TYPE gdb_fpregset_t;
-#else
-  typedef fpregset_t gdb_fpregset_t;
-#endif
-
-/* The PIDs that we pass to and from GDB will be composed from
-   the actual PID plus the LWPID.  These macros will be used to
-   compose and decompose them.  */
+/* Provide default composite pid manipulation macros for systems that
+   don't have threads. */
 
 #ifndef PIDGET
-#define PIDGET(PID)            (((PID) & 0xffff))
-#endif
-
-#ifndef TIDGET
-#define TIDGET(PID)            (((PID) & 0x7fffffff) >> 16)
+#define PIDGET(PID)            (PID)
+#define TIDGET(PID)            (PID)
 #endif
-
 #ifndef MERGEPID
-#define MERGEPID(PID, TID)     (((PID) & 0xffff) | ((TID) << 16))
+#define MERGEPID(PID, TID)     (PID)
 #endif
 
 typedef struct procinfo {
@@ -363,14 +307,14 @@ static char errmsg[128];  /* shared error msg buffer */
 
 /* Function prototypes for procinfo module: */
 
-static procinfo *find_procinfo_or_die PARAMS ((int pid, int tid));
-static procinfo *find_procinfo        PARAMS ((int pid, int tid));
-static procinfo *create_procinfo      PARAMS ((int pid, int tid));
-static void      destroy_procinfo     PARAMS ((procinfo *p));
-static void      dead_procinfo        PARAMS ((procinfo *p, 
-                                              char *msg, int killp));
-static int       open_procinfo_files  PARAMS ((procinfo *p, int which));
-static void      close_procinfo_files PARAMS ((procinfo *p));
+static procinfo *find_procinfo_or_die (int pid, int tid);
+static procinfo *find_procinfo (int pid, int tid);
+static procinfo *create_procinfo (int pid, int tid);
+static void destroy_procinfo (procinfo * p);
+static void do_destroy_procinfo_cleanup (void *);
+static void dead_procinfo (procinfo * p, char *msg, int killp);
+static int open_procinfo_files (procinfo * p, int which);
+static void close_procinfo_files (procinfo * p);
 
 /* The head of the procinfo list: */
 static procinfo * procinfo_list;
@@ -384,9 +328,7 @@ static procinfo * procinfo_list;
  */
 
 static procinfo * 
-find_procinfo (pid, tid)
-     int pid;
-     int tid;
+find_procinfo (int pid, int tid)
 {
   procinfo *pi;
 
@@ -419,18 +361,18 @@ find_procinfo (pid, tid)
  */
 
 static procinfo *
-find_procinfo_or_die (pid, tid)
-     int pid;
-     int tid;
+find_procinfo_or_die (int pid, int tid)
 {
   procinfo *pi = find_procinfo (pid, tid);
 
   if (pi == NULL)
-    if (tid)
-      error ("procfs: couldn't find pid %d (kernel thread %d) in procinfo list.", 
-            pid, tid);
-    else
-      error ("procfs: couldn't find pid %d in procinfo list.", pid);
+    {
+      if (tid)
+       error ("procfs: couldn't find pid %d (kernel thread %d) in procinfo list.", 
+              pid, tid);
+      else
+       error ("procfs: couldn't find pid %d in procinfo list.", pid);
+    }
   return pi;
 }
 
@@ -450,11 +392,11 @@ find_procinfo_or_die (pid, tid)
 enum { FD_CTL, FD_STATUS, FD_AS };
 
 static int
-open_procinfo_files (pi, which)
-     procinfo *pi;
-     int       which;
+open_procinfo_files (procinfo *pi, int which)
 {
+#ifdef NEW_PROC_API
   char tmp[MAX_PROC_NAME_SIZE];
+#endif
   int  fd;
 
   /* 
@@ -599,19 +541,17 @@ open_procinfo_files (pi, which)
  * Function: create_procinfo
  *
  * Allocate a data structure and link it into the procinfo list.
- * (First tries to find a pre-existing one (FIXME: why???)
+ * (First tries to find a pre-existing one (FIXME: why?)
  *
  * Return: pointer to new procinfo struct.
  */
 
 static procinfo *
-create_procinfo (pid, tid)
-     int pid;
-     int tid;
+create_procinfo (int pid, int tid)
 {
   procinfo *pi, *parent;
 
-  if (pi = find_procinfo (pid, tid))
+  if ((pi = find_procinfo (pid, tid)))
     return pi;                 /* Already exists, nothing to do. */
 
   /* find parent before doing malloc, to save having to cleanup */
@@ -652,8 +592,7 @@ create_procinfo (pid, tid)
  */
 
 static void
-close_procinfo_files (pi)
-     procinfo *pi;
+close_procinfo_files (procinfo *pi)
 {
   if (pi->ctl_fd > 0)
     close (pi->ctl_fd);
@@ -673,9 +612,7 @@ close_procinfo_files (pi)
  */
 
 static void
-destroy_one_procinfo (list, pi)
-     procinfo **list;
-     procinfo  *pi;
+destroy_one_procinfo (procinfo **list, procinfo *pi)
 {
   procinfo *ptr;
 
@@ -698,8 +635,7 @@ destroy_one_procinfo (list, pi)
 }
 
 static void
-destroy_procinfo (pi)
-     procinfo *pi;
+destroy_procinfo (procinfo *pi)
 {
   procinfo *tmp;
 
@@ -718,6 +654,12 @@ destroy_procinfo (pi)
     }
 }
 
+static void
+do_destroy_procinfo_cleanup (void *pi)
+{
+  destroy_procinfo (pi);
+}
+
 enum { NOKILL, KILL };
 
 /*
@@ -729,10 +671,7 @@ enum { NOKILL, KILL };
  */
 
 static void
-dead_procinfo (pi, msg, kill_p)
-     procinfo *pi;
-     char     *msg;
-     int       kill_p;
+dead_procinfo (procinfo *pi, char *msg, int kill_p)
 {
   char procfile[80];
 
@@ -768,72 +707,64 @@ dead_procinfo (pi, msg, kill_p)
  * functions, we do our best to hide them all in here.
  */
 
-int proc_get_status PARAMS ((procinfo *pi));
-long proc_flags     PARAMS ((procinfo *pi));
-int proc_why        PARAMS ((procinfo *pi));
-int proc_what       PARAMS ((procinfo *pi));
-int proc_set_run_on_last_close   PARAMS ((procinfo *pi));
-int proc_unset_run_on_last_close PARAMS ((procinfo *pi));
-int proc_set_inherit_on_fork     PARAMS ((procinfo *pi));
-int proc_unset_inherit_on_fork   PARAMS ((procinfo *pi));
-int proc_set_async            PARAMS ((procinfo *pi));
-int proc_unset_async          PARAMS ((procinfo *pi));
-int proc_stop_process         PARAMS ((procinfo *pi));
-int proc_trace_signal         PARAMS ((procinfo *pi, int signo));
-int proc_ignore_signal        PARAMS ((procinfo *pi, int signo));
-int proc_clear_current_fault  PARAMS ((procinfo *pi));
-int proc_set_current_signal   PARAMS ((procinfo *pi, int signo));
-int proc_clear_current_signal PARAMS ((procinfo *pi));
-int proc_set_gregs            PARAMS ((procinfo *pi));
-int proc_set_fpregs           PARAMS ((procinfo *pi));
-int proc_wait_for_stop        PARAMS ((procinfo *pi));
-int proc_run_process          PARAMS ((procinfo *pi, int step, int signo));
-int proc_kill                 PARAMS ((procinfo *pi, int signo));
-int proc_parent_pid           PARAMS ((procinfo *pi));
-int proc_get_nthreads         PARAMS ((procinfo *pi));
-int proc_get_current_thread   PARAMS ((procinfo *pi));
-int proc_set_held_signals     PARAMS ((procinfo *pi, sigset_t *sighold));
-int proc_set_traced_sysexit   PARAMS ((procinfo *pi, sysset_t *sysset));
-int proc_set_traced_sysentry  PARAMS ((procinfo *pi, sysset_t *sysset));
-int proc_set_traced_faults    PARAMS ((procinfo *pi, fltset_t *fltset));
-int proc_set_traced_signals   PARAMS ((procinfo *pi, sigset_t *sigset));
-
-int proc_update_threads       PARAMS ((procinfo *pi));
-int proc_iterate_over_threads PARAMS ((procinfo *pi,
-                                      int     (*func) PARAMS ((procinfo *, 
-                                                               procinfo *, 
-                                                               void *)),
-                                      void     *ptr));
-
-gdb_gregset_t   *proc_get_gregs     PARAMS ((procinfo *pi));
-gdb_fpregset_t  *proc_get_fpregs    PARAMS ((procinfo *pi));
-sysset_t *proc_get_traced_sysexit   PARAMS ((procinfo *pi, sysset_t *save));
-sysset_t *proc_get_traced_sysentry  PARAMS ((procinfo *pi, sysset_t *save));
-fltset_t *proc_get_traced_faults    PARAMS ((procinfo *pi, fltset_t *save));
-sigset_t *proc_get_traced_signals   PARAMS ((procinfo *pi, sigset_t *save));
-sigset_t *proc_get_held_signals     PARAMS ((procinfo *pi, sigset_t *save));
-sigset_t *proc_get_pending_signals  PARAMS ((procinfo *pi, sigset_t *save));
-struct sigaction *proc_get_signal_actions PARAMS ((procinfo *pi, 
-                                                  struct sigaction *save));
-
-void proc_warn  PARAMS ((procinfo *pi, char *func, int line));
-void proc_error PARAMS ((procinfo *pi, char *func, int line));
+int proc_get_status (procinfo * pi);
+long proc_flags (procinfo * pi);
+int proc_why (procinfo * pi);
+int proc_what (procinfo * pi);
+int proc_set_run_on_last_close (procinfo * pi);
+int proc_unset_run_on_last_close (procinfo * pi);
+int proc_set_inherit_on_fork (procinfo * pi);
+int proc_unset_inherit_on_fork (procinfo * pi);
+int proc_set_async (procinfo * pi);
+int proc_unset_async (procinfo * pi);
+int proc_stop_process (procinfo * pi);
+int proc_trace_signal (procinfo * pi, int signo);
+int proc_ignore_signal (procinfo * pi, int signo);
+int proc_clear_current_fault (procinfo * pi);
+int proc_set_current_signal (procinfo * pi, int signo);
+int proc_clear_current_signal (procinfo * pi);
+int proc_set_gregs (procinfo * pi);
+int proc_set_fpregs (procinfo * pi);
+int proc_wait_for_stop (procinfo * pi);
+int proc_run_process (procinfo * pi, int step, int signo);
+int proc_kill (procinfo * pi, int signo);
+int proc_parent_pid (procinfo * pi);
+int proc_get_nthreads (procinfo * pi);
+int proc_get_current_thread (procinfo * pi);
+int proc_set_held_signals (procinfo * pi, sigset_t * sighold);
+int proc_set_traced_sysexit (procinfo * pi, sysset_t * sysset);
+int proc_set_traced_sysentry (procinfo * pi, sysset_t * sysset);
+int proc_set_traced_faults (procinfo * pi, fltset_t * fltset);
+int proc_set_traced_signals (procinfo * pi, sigset_t * sigset);
+
+int proc_update_threads (procinfo * pi);
+int proc_iterate_over_threads (procinfo * pi,
+                              int (*func) (procinfo *, procinfo *, void *),
+                              void *ptr);
+
+gdb_gregset_t *proc_get_gregs (procinfo * pi);
+gdb_fpregset_t *proc_get_fpregs (procinfo * pi);
+sysset_t *proc_get_traced_sysexit (procinfo * pi, sysset_t * save);
+sysset_t *proc_get_traced_sysentry (procinfo * pi, sysset_t * save);
+fltset_t *proc_get_traced_faults (procinfo * pi, fltset_t * save);
+sigset_t *proc_get_traced_signals (procinfo * pi, sigset_t * save);
+sigset_t *proc_get_held_signals (procinfo * pi, sigset_t * save);
+sigset_t *proc_get_pending_signals (procinfo * pi, sigset_t * save);
+struct sigaction *proc_get_signal_actions (procinfo * pi,
+                                          struct sigaction *save);
+
+void proc_warn (procinfo * pi, char *func, int line);
+void proc_error (procinfo * pi, char *func, int line);
 
 void
-proc_warn (pi, func, line)
-     procinfo *pi;
-     char     *func;
-     int      line;
+proc_warn (procinfo *pi, char *func, int line)
 {
   sprintf (errmsg, "procfs: %s line %d, %s", func, line, pi->pathname);
   print_sys_errmsg (errmsg, errno);
 }
 
 void
-proc_error (pi, func, line)
-     procinfo *pi;
-     char     *func;
-     int      line;
+proc_error (procinfo *pi, char *func, int line)
 {
   sprintf (errmsg, "procfs: %s line %d, %s", func, line, pi->pathname);
   perror_with_name (errmsg);
@@ -852,8 +783,7 @@ proc_error (pi, func, line)
  */
 
 int
-proc_get_status (pi)
-     procinfo *pi;
+proc_get_status (procinfo *pi)
 {
   /* Status file descriptor is opened "lazily" */
   if (pi->status_fd == 0 &&
@@ -951,15 +881,21 @@ proc_get_status (pi)
  */ 
 
 long
-proc_flags (pi)
-     procinfo *pi;
+proc_flags (procinfo *pi)
 {
   if (!pi->status_valid)
     if (!proc_get_status (pi))
       return 0;        /* FIXME: not a good failure value (but what is?) */
 
 #ifdef NEW_PROC_API
+# ifdef UNIXWARE
+  /* UnixWare 7.1 puts process status flags, e.g. PR_ASYNC, in
+     pstatus_t and LWP status flags, e.g. PR_STOPPED, in lwpstatus_t.
+     The two sets of flags don't overlap. */
+  return pi->prstatus.pr_flags | pi->prstatus.pr_lwp.pr_flags;
+# else
   return pi->prstatus.pr_lwp.pr_flags;
+# endif
 #else
   return pi->prstatus.pr_flags;
 #endif
@@ -972,8 +908,7 @@ proc_flags (pi)
  */
 
 int
-proc_why (pi)
-     procinfo *pi;
+proc_why (procinfo *pi)
 {
   if (!pi->status_valid)
     if (!proc_get_status (pi))
@@ -993,8 +928,7 @@ proc_why (pi)
  */
 
 int
-proc_what (pi)
-     procinfo *pi;
+proc_what (procinfo *pi)
 {
   if (!pi->status_valid)
     if (!proc_get_status (pi))
@@ -1015,8 +949,7 @@ proc_what (pi)
  */
 
 int
-proc_nsysarg (pi)
-     procinfo *pi;
+proc_nsysarg (procinfo *pi)
 {
   if (!pi->status_valid)
     if (!proc_get_status (pi))
@@ -1036,8 +969,7 @@ proc_nsysarg (pi)
  */
 
 long *
-proc_sysargs (pi)
-     procinfo *pi;
+proc_sysargs (procinfo *pi)
 {
   if (!pi->status_valid)
     if (!proc_get_status (pi))
@@ -1057,8 +989,7 @@ proc_sysargs (pi)
  */
 
 int
-proc_syscall (pi)
-     procinfo *pi;
+proc_syscall (procinfo *pi)
 {
   if (!pi->status_valid)
     if (!proc_get_status (pi))
@@ -1093,7 +1024,7 @@ proc_cursig (struct procinfo *pi)
 }
 
 /*
- * Function: proc_modify_flags 
+ * Function: proc_modify_flag 
  *
  *  === I appologize for the messiness of this function. 
  *  === This is an area where the different versions of
@@ -1102,6 +1033,7 @@ proc_cursig (struct procinfo *pi)
  * Set or reset any of the following process flags:
  *    PR_FORK  -- forked child will inherit trace flags
  *    PR_RLC   -- traced process runs when last /proc file closed.
+ *    PR_KLC    -- traced process is killed when last /proc file closed.
  *    PR_ASYNC -- LWP's get to run/stop independently.
  *
  * There are three methods for doing this function:
@@ -1113,7 +1045,8 @@ proc_cursig (struct procinfo *pi)
  *    [OSF, Sol5]
  *
  * Note: Irix does not define PR_ASYNC.
- * Note: OSF is the only one that can ONLY use the oldest method.
+ * Note: OSF  does not define PR_KLC.
+ * Note: OSF  is the only one that can ONLY use the oldest method.
  *
  * Arguments: 
  *    pi   -- the procinfo
@@ -1126,10 +1059,7 @@ proc_cursig (struct procinfo *pi)
 enum { FLAG_RESET, FLAG_SET };
 
 static int
-proc_modify_flag (pi, flag, mode)
-     procinfo *pi;
-     long flag;
-     long mode;
+proc_modify_flag (procinfo *pi, long flag, long mode)
 {
   long win = 0;                /* default to fail */
 
@@ -1217,6 +1147,9 @@ proc_modify_flag (pi, flag, mode)
             flag == PR_RLC   ? "PR_RLC"   :
 #ifdef PR_ASYNC
             flag == PR_ASYNC ? "PR_ASYNC" :
+#endif
+#ifdef PR_KLC
+            flag == PR_KLC   ? "PR_KLC"   :
 #endif
             "<unknown flag>",
             mode == FLAG_RESET ? "off" : "on");
@@ -1235,8 +1168,7 @@ proc_modify_flag (pi, flag, mode)
  */
 
 int
-proc_set_run_on_last_close (pi)
-     procinfo *pi;
+proc_set_run_on_last_close (procinfo *pi)
 {
   return proc_modify_flag (pi, PR_RLC, FLAG_SET);
 }
@@ -1252,12 +1184,45 @@ proc_set_run_on_last_close (pi)
  */
 
 int
-proc_unset_run_on_last_close (pi)
-     procinfo *pi;
+proc_unset_run_on_last_close (procinfo *pi)
 {
   return proc_modify_flag (pi, PR_RLC, FLAG_RESET);
 }
 
+#ifdef PR_KLC
+/*
+ * Function: proc_set_kill_on_last_close
+ *
+ * Set the kill_on_last_close flag.
+ * Process with all threads will be killed when debugger
+ * closes all /proc fds (or debugger exits or dies).
+ *
+ * Returns non-zero for success, zero for failure.
+ */
+
+int
+proc_set_kill_on_last_close (procinfo *pi)
+{
+  return proc_modify_flag (pi, PR_KLC, FLAG_SET);
+}
+
+/*
+ * Function: proc_unset_kill_on_last_close
+ *
+ * Reset the kill_on_last_close flag.
+ * Process will NOT be killed when debugger 
+ * closes its file handles (or exits or dies).
+ *
+ * Returns non-zero for success, zero for failure.
+ */
+
+int
+proc_unset_kill_on_last_close (procinfo *pi)
+{
+  return proc_modify_flag (pi, PR_KLC, FLAG_RESET);
+}
+#endif /* PR_KLC */
+
 /*
  * Function: proc_set_inherit_on_fork
  *
@@ -1269,8 +1234,7 @@ proc_unset_run_on_last_close (pi)
  */
 
 int
-proc_set_inherit_on_fork (pi)
-     procinfo *pi;
+proc_set_inherit_on_fork (procinfo *pi)
 {
   return proc_modify_flag (pi, PR_FORK, FLAG_SET);
 }
@@ -1286,8 +1250,7 @@ proc_set_inherit_on_fork (pi)
  */
 
 int
-proc_unset_inherit_on_fork (pi)
-     procinfo *pi;
+proc_unset_inherit_on_fork (procinfo *pi)
 {
   return proc_modify_flag (pi, PR_FORK, FLAG_RESET);
 }
@@ -1304,8 +1267,7 @@ proc_unset_inherit_on_fork (pi)
  */
 
 int
-proc_set_async (pi)
-     procinfo *pi;
+proc_set_async (procinfo *pi)
 {
   return proc_modify_flag (pi, PR_ASYNC, FLAG_SET);
 }
@@ -1321,8 +1283,7 @@ proc_set_async (pi)
  */
 
 int
-proc_unset_async (pi)
-     procinfo *pi;
+proc_unset_async (procinfo *pi)
 {
   return proc_modify_flag (pi, PR_ASYNC, FLAG_RESET);
 }
@@ -1336,8 +1297,7 @@ proc_unset_async (pi)
  */
 
 int
-proc_stop_process (pi)
-     procinfo *pi;
+proc_stop_process (procinfo *pi)
 {
   int win;
 
@@ -1352,7 +1312,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);
@@ -1379,8 +1339,7 @@ proc_stop_process (pi)
  */
 
 int
-proc_wait_for_stop (pi)
-     procinfo *pi;
+proc_wait_for_stop (procinfo *pi)
 {
   int win;
 
@@ -1396,7 +1355,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;
@@ -1444,10 +1403,7 @@ proc_wait_for_stop (pi)
  */
 
 int
-proc_run_process (pi, step, signo)
-     procinfo *pi;
-     int step;
-     int signo;
+proc_run_process (procinfo *pi, int step, int signo)
 {
   int win;
   int runflags;
@@ -1473,7 +1429,7 @@ proc_run_process (pi, step, signo)
 
 #ifdef NEW_PROC_API
   {
-    int cmd[2];
+    long cmd[2];
 
     cmd[0]  = PCRUN;
     cmd[1]  = runflags;
@@ -1500,9 +1456,7 @@ proc_run_process (pi, step, signo)
  */
 
 int
-proc_set_traced_signals (pi, sigset)
-     procinfo *pi;
-     sigset_t *sigset;
+proc_set_traced_signals (procinfo *pi, sigset_t *sigset)
 {
   int win;
 
@@ -1519,7 +1473,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;
@@ -1548,9 +1502,7 @@ proc_set_traced_signals (pi, sigset)
  */
 
 int
-proc_set_traced_faults (pi, fltset)
-     procinfo *pi;
-     fltset_t *fltset;
+proc_set_traced_faults (procinfo *pi, fltset_t *fltset)
 {
   int win;
 
@@ -1567,7 +1519,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;
@@ -1594,9 +1546,7 @@ proc_set_traced_faults (pi, fltset)
  */
 
 int
-proc_set_traced_sysentry (pi, sysset)
-     procinfo *pi;
-     sysset_t *sysset;
+proc_set_traced_sysentry (procinfo *pi, sysset_t *sysset)
 {
   int win;
 
@@ -1613,7 +1563,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;
@@ -1640,9 +1590,7 @@ proc_set_traced_sysentry (pi, sysset)
  */
 
 int
-proc_set_traced_sysexit (pi, sysset)
-     procinfo *pi;
-     sysset_t *sysset;
+proc_set_traced_sysexit (procinfo *pi, sysset_t *sysset)
 {
   int win;
 
@@ -1659,7 +1607,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;
@@ -1686,9 +1634,7 @@ proc_set_traced_sysexit (pi, sysset)
  */
 
 int
-proc_set_held_signals (pi, sighold)
-     procinfo *pi;
-     sigset_t *sighold;
+proc_set_held_signals (procinfo *pi, sigset_t *sighold)
 {
   int win;
 
@@ -1705,7 +1651,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;
@@ -1731,9 +1677,7 @@ proc_set_held_signals (pi, sighold)
  */
 
 sigset_t *
-proc_get_pending_signals (pi, save)
-     procinfo *pi;
-     sigset_t *save;
+proc_get_pending_signals (procinfo *pi, sigset_t *save)
 {
   sigset_t *ret = NULL;
 
@@ -1770,9 +1714,7 @@ proc_get_pending_signals (pi, save)
  */
 
 struct sigaction *
-proc_get_signal_actions (pi, save)
-     procinfo         *pi;
-     struct sigaction *save;
+proc_get_signal_actions (procinfo *pi, struct sigaction *save)
 {
   struct sigaction *ret = NULL;
 
@@ -1809,9 +1751,7 @@ proc_get_signal_actions (pi, save)
  */
 
 sigset_t *
-proc_get_held_signals (pi, save)
-     procinfo *pi;
-     sigset_t *save;
+proc_get_held_signals (procinfo *pi, sigset_t *save)
 {
   sigset_t *ret = NULL;
 
@@ -1857,9 +1797,7 @@ proc_get_held_signals (pi, save)
  */
 
 sigset_t *
-proc_get_traced_signals (pi, save)
-     procinfo *pi;
-     sigset_t *save;
+proc_get_traced_signals (procinfo *pi, sigset_t *save)
 {
   sigset_t *ret = NULL;
 
@@ -1901,9 +1839,7 @@ proc_get_traced_signals (pi, save)
  */
 
 int
-proc_trace_signal (pi, signo)
-     procinfo *pi;
-     int signo;
+proc_trace_signal (procinfo *pi, int signo)
 {
   sigset_t temp;
 
@@ -1937,9 +1873,7 @@ proc_trace_signal (pi, signo)
  */
 
 int
-proc_ignore_signal (pi, signo)
-     procinfo *pi;
-     int signo;
+proc_ignore_signal (procinfo *pi, int signo)
 {
   sigset_t temp;
 
@@ -1973,9 +1907,7 @@ proc_ignore_signal (pi, signo)
  */
 
 fltset_t *
-proc_get_traced_faults (pi, save)
-     procinfo *pi;
-     fltset_t *save;
+proc_get_traced_faults (procinfo *pi, fltset_t *save)
 {
   fltset_t *ret = NULL;
 
@@ -2017,9 +1949,7 @@ proc_get_traced_faults (pi, save)
  */
 
 sysset_t *
-proc_get_traced_sysentry (pi, save)
-     procinfo *pi;
-     sysset_t *save;
+proc_get_traced_sysentry (procinfo *pi, sysset_t *save)
 {
   sysset_t *ret = NULL;
 
@@ -2061,9 +1991,7 @@ proc_get_traced_sysentry (pi, save)
  */
 
 sysset_t *
-proc_get_traced_sysexit (pi, save)
-     procinfo *pi;
-     sysset_t *save;
+proc_get_traced_sysexit (procinfo *pi, sysset_t *save)
 {
   sysset_t * ret = NULL;
 
@@ -2106,8 +2034,7 @@ proc_get_traced_sysexit (pi, save)
  */
 
 int
-proc_clear_current_fault (pi)
-     procinfo *pi;
+proc_clear_current_fault (procinfo *pi)
 {
   int win;
 
@@ -2123,7 +2050,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
@@ -2147,13 +2074,11 @@ proc_clear_current_fault (pi)
  */
 
 int
-proc_set_current_signal (pi, signo)
-     procinfo *pi;
-     int signo;
+proc_set_current_signal (procinfo *pi, int signo)
 {
   int win;
   struct {
-    int cmd;
+    long cmd;
     /* Use char array to avoid alignment issues.  */
     char sinfo[sizeof (struct siginfo)];
   } arg;
@@ -2205,8 +2130,7 @@ proc_set_current_signal (pi, signo)
  */
 
 int
-proc_clear_current_signal (pi)
-     procinfo *pi;
+proc_clear_current_signal (procinfo *pi)
 {
   int win;
 
@@ -2223,7 +2147,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;
@@ -2255,8 +2179,7 @@ proc_clear_current_signal (pi)
  */
 
 gdb_gregset_t *
-proc_get_gregs (pi)
-     procinfo *pi;
+proc_get_gregs (procinfo *pi)
 {
   if (!pi->status_valid || !pi->gregs_valid)
     if (!proc_get_status (pi))
@@ -2287,8 +2210,7 @@ proc_get_gregs (pi)
  */
 
 gdb_fpregset_t *
-proc_get_fpregs (pi)
-     procinfo *pi;
+proc_get_fpregs (procinfo *pi)
 {
 #ifdef NEW_PROC_API
   if (!pi->status_valid || !pi->fpregs_valid)
@@ -2365,8 +2287,7 @@ proc_get_fpregs (pi)
  */
 
 int
-proc_set_gregs (pi)
-     procinfo *pi;
+proc_set_gregs (procinfo *pi)
 {
   gdb_gregset_t *gregs;
   int win;
@@ -2383,7 +2304,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;
@@ -2409,8 +2330,7 @@ proc_set_gregs (pi)
  */
 
 int
-proc_set_fpregs (pi)
-     procinfo *pi;
+proc_set_fpregs (procinfo *pi)
 {
   gdb_fpregset_t *fpregs;
   int win;
@@ -2427,7 +2347,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;
@@ -2472,9 +2392,7 @@ proc_set_fpregs (pi)
  */
 
 int
-proc_kill (pi, signo)
-     procinfo *pi;
-     int signo;
+proc_kill (procinfo *pi, int signo)
 {
   int win;
 
@@ -2491,7 +2409,7 @@ proc_kill (pi, signo)
   else
     {
 #ifdef NEW_PROC_API
-      int cmd[2];
+      long cmd[2];
 
       cmd[0] = PCKILL;
       cmd[1] = signo;
@@ -2514,8 +2432,7 @@ proc_kill (pi, signo)
  */
 
 int
-proc_parent_pid (pi)
-     procinfo *pi;
+proc_parent_pid (procinfo *pi)
 {
   /*
    * We should never have to apply this operation to any procinfo
@@ -2541,11 +2458,7 @@ proc_parent_pid (pi)
  */
 
 int
-proc_set_watchpoint (pi, addr, len, wflags)
-     procinfo *pi;
-     void     *addr;
-     int       len;
-     int       wflags;
+proc_set_watchpoint (procinfo *pi, CORE_ADDR addr, int len, int wflags)
 {
 #if !defined (TARGET_HAS_HARDWARE_WATCHPOINTS)  
   return 0;
@@ -2555,13 +2468,13 @@ proc_set_watchpoint (pi, addr, len, wflags)
   return 0;
 #else
   struct {
-    int cmd;
+    long cmd;
     char watch[sizeof (prwatch_t)];
   } arg;
   prwatch_t *pwatch;
 
   pwatch            = (prwatch_t *) &arg.watch;
-  pwatch->pr_vaddr  = addr;
+  pwatch->pr_vaddr  = address_to_host_pointer (addr);
   pwatch->pr_size   = len;
   pwatch->pr_wflags = wflags;
 #if defined(NEW_PROC_API) && defined (PCWATCH)
@@ -2596,15 +2509,19 @@ proc_set_watchpoint (pi, addr, len, wflags)
    It doesn't get called that often... and if I open it
    every time, I don't need to lseek it.  */
 int
-proc_iterate_over_mappings (func)
-     int (*func) PARAMS ((int, CORE_ADDR));
+proc_iterate_over_mappings (int (*func) (int, CORE_ADDR))
 {
   struct prmap *map;
   procinfo *pi;
-  int nmaps = 0, i;
-  int funcstat = 0;
-  int fd, map_fd;
+#ifndef NEW_PROC_API   /* avoid compiler warning */
+  int nmaps = 0;
+  int i;
+#else
+  int map_fd;
   char pathname[MAX_PROC_NAME_SIZE];
+#endif
+  int funcstat = 0;
+  int fd;
 
   pi = find_procinfo_or_die (PIDGET (inferior_pid), 0);
 
@@ -2615,7 +2532,7 @@ proc_iterate_over_mappings (func)
     proc_error (pi, "proc_iterate_over_mappings (open)", __LINE__);
 
   /* Make sure it gets closed again.  */
-  make_cleanup ((make_cleanup_func) close, (void *) map_fd);
+  make_cleanup_close (map_fd);
 
   /* Allocate space for mapping (lifetime only for this function). */
   map = alloca (sizeof (struct prmap));
@@ -2677,7 +2594,8 @@ proc_iterate_over_mappings (func)
         not a problem.  */
 
       /* Stop looping if the callback returns non-zero.  */
-      if ((funcstat = (*func) (fd, (CORE_ADDR) map[i].pr_vaddr)) != 0)
+      funcstat = (*func) (fd, host_pointer_to_address (map[i].pr_vaddr));
+      if (funcstat != 0)
        break;
     }
 #endif
@@ -2703,9 +2621,7 @@ proc_iterate_over_mappings (func)
  */
 
 struct ssd *
-proc_get_LDT_entry (pi, key)
-     procinfo *pi;
-     int       key;
+proc_get_LDT_entry (procinfo *pi, int key)
 {
   static struct ssd *ldt_entry = NULL;
 #ifdef NEW_PROC_API
@@ -2726,7 +2642,7 @@ proc_get_LDT_entry (pi, key)
       return NULL;
     }
   /* Make sure it gets closed again! */
-  old_chain = make_cleanup ((make_cleanup_func) close, (void *) fd);
+  old_chain = make_cleanup_close (fd);
 
   /* Now 'read' thru the table, find a match and return it.  */
   while (read (fd, ldt_entry, sizeof (struct ssd)) == sizeof (struct ssd))
@@ -2799,8 +2715,7 @@ proc_get_LDT_entry (pi, key)
  * OSF version
  */
 int 
-proc_get_nthreads (pi)
-     procinfo *pi;
+proc_get_nthreads (procinfo *pi)
 {
   int nthreads = 0;
 
@@ -2816,8 +2731,7 @@ proc_get_nthreads (pi)
  * Solaris and Unixware version
  */
 int
-proc_get_nthreads (pi)
-     procinfo *pi;
+proc_get_nthreads (procinfo *pi)
 {
   if (!pi->status_valid)
     if (!proc_get_status (pi))
@@ -2839,8 +2753,7 @@ proc_get_nthreads (pi)
  * Default version
  */
 int
-proc_get_nthreads (pi)
-     procinfo *pi;
+proc_get_nthreads (procinfo *pi)
 {
   return 0;
 }
@@ -2861,8 +2774,7 @@ proc_get_nthreads (pi)
  * Solaris and Unixware version
  */
 int
-proc_get_current_thread (pi)
-     procinfo *pi;
+proc_get_current_thread (procinfo *pi)
 {
   /*
    * Note: this should be applied to the root procinfo for the process,
@@ -2891,8 +2803,7 @@ proc_get_current_thread (pi)
  * OSF version
  */
 int 
-proc_get_current_thread (pi)
-     procinfo *pi;
+proc_get_current_thread (procinfo *pi)
 {
 #if 0  /* FIXME: not ready for prime time? */
   return pi->prstatus.pr_tid;
@@ -2906,8 +2817,7 @@ proc_get_current_thread (pi)
  * Default version
  */
 int 
-proc_get_current_thread (pi)
-     procinfo *pi;
+proc_get_current_thread (procinfo *pi)
 {
   return 0;
 }
@@ -2927,10 +2837,7 @@ proc_get_current_thread (pi)
  */
 
 int
-proc_delete_dead_threads (parent, thread, ignore)
-     procinfo *parent;
-     procinfo *thread;
-     void     *ignore;
+proc_delete_dead_threads (procinfo *parent, procinfo *thread, void *ignore)
 {
   if (thread && parent)        /* sanity */
     {
@@ -2946,8 +2853,7 @@ proc_delete_dead_threads (parent, thread, ignore)
  * Solaris 2.5 (ioctl) version
  */
 int
-proc_update_threads (pi)
-     procinfo *pi;
+proc_update_threads (procinfo *pi)
 {
   gdb_prstatus_t *prstatus;
   struct cleanup *old_chain = NULL;
@@ -2995,9 +2901,14 @@ proc_update_threads (pi)
 /*
  * Unixware and Solaris 6 (and later) version
  */
+static void
+do_closedir_cleanup (void *dir)
+{
+  closedir (dir);
+}
+
 int
-proc_update_threads (pi)
-     procinfo *pi;
+proc_update_threads (procinfo *pi)
 {
   char pathname[MAX_PROC_NAME_SIZE + 16];
   struct dirent *direntry;
@@ -3033,7 +2944,7 @@ proc_update_threads (pi)
   if ((dirp = opendir (pathname)) == NULL)
     proc_error (pi, "update_threads, opendir", __LINE__);
 
-  old_chain = make_cleanup ((make_cleanup_func) closedir, dirp);
+  old_chain = make_cleanup (do_closedir_cleanup, dirp);
   while ((direntry = readdir (dirp)) != NULL)
     if (direntry->d_name[0] != '.')            /* skip '.' and '..' */
       {
@@ -3051,8 +2962,7 @@ proc_update_threads (pi)
  * OSF version
  */
 int 
-proc_update_threads (pi)
-     procinfo *pi;
+proc_update_threads (procinfo *pi)
 {
   int nthreads, i;
   tid_t *threads;
@@ -3093,8 +3003,7 @@ proc_update_threads (pi)
  * Default version
  */
 int
-proc_update_threads (pi)
-     procinfo *pi;
+proc_update_threads (procinfo *pi)
 {
   return 0;
 }
@@ -3126,10 +3035,9 @@ proc_update_threads (pi)
  */
 
 int
-proc_iterate_over_threads (pi, func, ptr)
-     procinfo *pi;
-     int     (*func) PARAMS ((procinfo *, procinfo *, void *));
-     void     *ptr;
+proc_iterate_over_threads (procinfo *pi,
+                          int (*func) (procinfo *, procinfo *, void *),
+                          void *ptr)
 {
   procinfo *thread, *next;
   int retval = 0;
@@ -3164,9 +3072,9 @@ proc_iterate_over_threads (pi, func, ptr)
  * Here are all of the gdb target vector functions and their friends.
  */
 
-static int  do_attach PARAMS ((int pid));
-static void do_detach PARAMS ((int signo));
-static int register_gdb_signals PARAMS ((procinfo *, sigset_t *));
+static int do_attach (int pid);
+static void do_detach (int signo);
+static int register_gdb_signals (procinfo *, sigset_t *);
 
 /*
  * Function: procfs_debug_inferior
@@ -3180,8 +3088,7 @@ static int register_gdb_signals PARAMS ((procinfo *, sigset_t *));
  */
 
 static int
-procfs_debug_inferior (pi)
-     procinfo *pi;
+procfs_debug_inferior (procinfo *pi)
 {
   fltset_t traced_faults;
   sigset_t traced_signals;
@@ -3272,9 +3179,7 @@ procfs_debug_inferior (pi)
 }
 
 static void 
-procfs_attach (args, from_tty)
-     char *args;
-     int from_tty;
+procfs_attach (char *args, int from_tty)
 {
   char *exec_file;
   int   pid;
@@ -3303,9 +3208,7 @@ procfs_attach (args, from_tty)
 }
 
 static void 
-procfs_detach (args, from_tty)
-     char *args;
-     int from_tty;
+procfs_detach (char *args, int from_tty)
 {
   char *exec_file;
   int   signo = 0;
@@ -3328,8 +3231,7 @@ procfs_detach (args, from_tty)
 }
 
 static int
-do_attach (pid)
-     int pid;
+do_attach (int pid)
 {
   procinfo *pi;
   int fail;
@@ -3386,11 +3288,9 @@ do_attach (pid)
 }
 
 static void
-do_detach (signo)
-     int signo;
+do_detach (int signo)
 {
   procinfo *pi;
-  long      pflags;
 
   /* Find procinfo for the main process */
   pi = find_procinfo_or_die (PIDGET (inferior_pid), 0);        /* FIXME: threads */
@@ -3441,8 +3341,7 @@ do_detach (signo)
  */
 
 static void
-procfs_fetch_registers (regno)
-     int regno;
+procfs_fetch_registers (int regno)
 {
   gdb_fpregset_t *fpregs;
   gdb_gregset_t  *gregs;
@@ -3472,21 +3371,20 @@ procfs_fetch_registers (regno)
 
   supply_gregset (gregs);
 
-#if defined (FP0_REGNUM)       /* need floating point? */
-  if ((regno >= 0 && regno < FP0_REGNUM) ||
-      regno == PC_REGNUM  ||
-#ifdef NPC_REGNUM
-      regno == NPC_REGNUM ||
-#endif
-      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
@@ -3496,7 +3394,7 @@ procfs_fetch_registers (regno)
    from the program being debugged.  */
 
 static void
-procfs_prepare_to_store ()
+procfs_prepare_to_store (void)
 {
 #ifdef CHILD_PREPARE_TO_STORE
   CHILD_PREPARE_TO_STORE ();
@@ -3515,8 +3413,7 @@ procfs_prepare_to_store ()
  */
 
 static void
-procfs_store_registers (regno)
-     int regno;
+procfs_store_registers (int regno)
 {
   gdb_fpregset_t *fpregs;
   gdb_gregset_t  *gregs;
@@ -3548,23 +3445,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  ||
-#ifdef NPC_REGNUM
-      regno == NPC_REGNUM ||
-#endif
-      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__);
+    }
 }
 
 /*
@@ -3580,9 +3476,7 @@ procfs_store_registers (regno)
  */
 
 static int  
-procfs_wait (pid, status)
-     int pid;
-     struct target_waitstatus *status;
+procfs_wait (int pid, struct target_waitstatus *status)
 {
   /* First cut: loosely based on original version 2.1 */
   procinfo *pi;
@@ -3650,18 +3544,6 @@ wait_again:
          why   = proc_why (pi);
          what  = proc_what (pi);
 
-#if 0
-         {
-           int stopped_pc = read_pc ();
-           if (stopped_pc != 0x10c68 &&
-               stopped_pc != 0x10c6c &&
-               stopped_pc != 0x10c70 &&
-               stopped_pc != 0x22768 &&
-               stopped_pc != 0x10c74)
-             printf ("%x,%d,%d\n", stopped_pc, why, what);
-         }
-#endif
-
          if (flags & (PR_STOPPED | PR_ISTOP))
            {
 #ifdef PR_ASYNC
@@ -3719,7 +3601,7 @@ wait_again:
                         return a "success" exit code.  Bogus: what if
                         it returns something else?  */
                      wstat = 0;
-                     retval = inferior_pid;  /* ??? */
+                     retval = inferior_pid;  /* ? ? ? */
                    }
                  else
                    {
@@ -3748,9 +3630,9 @@ wait_again:
                    if ((nsysargs = proc_nsysarg (pi)) > 0 &&
                        (sysargs  = proc_sysargs (pi)) != NULL)
                      {
-                       printf_filtered ("%d syscall arguments:\n", nsysargs);
+                       printf_filtered ("%ld syscall arguments:\n", nsysargs);
                        for (i = 0; i < nsysargs; i++)
-                         printf_filtered ("#%d: 0x%08x\n", 
+                         printf_filtered ("#%ld: 0x%08lx\n", 
                                           i, sysargs[i]);
                      }
 
@@ -3862,9 +3744,9 @@ wait_again:
                    if ((nsysargs = proc_nsysarg (pi)) > 0 &&
                        (sysargs  = proc_sysargs (pi)) != NULL)
                      {
-                       printf_filtered ("%d syscall arguments:\n", nsysargs);
+                       printf_filtered ("%ld syscall arguments:\n", nsysargs);
                        for (i = 0; i < nsysargs; i++)
-                         printf_filtered ("#%d: 0x%08x\n", 
+                         printf_filtered ("#%ld: 0x%08lx\n", 
                                           i, sysargs[i]);
                      }
                  }
@@ -3895,7 +3777,7 @@ wait_again:
                    temp = MERGEPID (pi->pid, temp);
                    if (!in_thread_list (temp))
                      {
-                       printf_filtered ("[*New %s]\n", 
+                       printf_filtered ("[New %s]\n", 
                                         target_pid_to_str (temp));
                        add_thread (temp);
                      }
@@ -4015,13 +3897,19 @@ wait_again:
   return retval;
 }
 
+/* Transfer LEN bytes between GDB address MYADDR and target address
+   MEMADDR.  If DOWRITE is non-zero, transfer them to the target,
+   otherwise transfer them from the target.  TARGET is unused.
+
+   The return value is 0 if an error occurred or no bytes were
+   transferred.  Otherwise, it will be a positive value which
+   indicates the number of bytes transferred between gdb and the
+   target.  (Note that the interface also makes provisions for
+   negative values, but this capability isn't implemented here.) */
+
 static int
-procfs_xfer_memory (memaddr, myaddr, len, dowrite, target)
-     CORE_ADDR memaddr;
-     char *myaddr;
-     int len;
-     int dowrite;
-     struct target_ops *target; /* ignored */
+procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int dowrite,
+                   struct target_ops *target)
 {
   procinfo *pi;
   int nbytes = 0;
@@ -4081,10 +3969,7 @@ procfs_xfer_memory (memaddr, myaddr, len, dowrite, target)
 
 
 static int
-invalidate_cache (parent, pi, ptr)
-     procinfo *parent;
-     procinfo *pi;
-     void     *ptr;
+invalidate_cache (procinfo *parent, procinfo *pi, void *ptr)
 {
   /*
    * About to run the child; invalidate caches and do any other cleanup.
@@ -4097,14 +3982,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)
@@ -4127,6 +4011,7 @@ invalidate_cache (parent, pi, ptr)
   return 0;
 }
 
+#if 0
 /*
  * Function: make_signal_thread_runnable
  *
@@ -4136,10 +4021,7 @@ invalidate_cache (parent, pi, ptr)
  */
 
 static int
-make_signal_thread_runnable (process, pi, ptr)
-     procinfo *process;
-     procinfo *pi;
-     void     *ptr;
+make_signal_thread_runnable (procinfo *process, procinfo *pi, void *ptr)
 {
 #ifdef PR_ASLWP
   if (proc_flags (pi) & PR_ASLWP)
@@ -4151,6 +4033,7 @@ make_signal_thread_runnable (process, pi, ptr)
 #endif
   return 0;
 }
+#endif
 
 /*
  * Function: target_resume
@@ -4170,10 +4053,7 @@ make_signal_thread_runnable (process, pi, ptr)
  */
 
 static void
-procfs_resume (pid, step, signo)
-     int pid;
-     int step;
-     enum target_signal signo;
+procfs_resume (int pid, int step, enum target_signal signo)
 {
   procinfo *pi, *thread;
   int native_signo;
@@ -4202,7 +4082,7 @@ procfs_resume (pid, step, signo)
 
   /* Convert signal to host numbering.  */
   if (signo == 0 ||
-      signo == TARGET_SIGNAL_STOP && pi->ignore_next_sigstop)
+      (signo == TARGET_SIGNAL_STOP && pi->ignore_next_sigstop))
     native_signo = 0;
   else
     native_signo = target_signal_to_host (signo);
@@ -4263,9 +4143,7 @@ procfs_resume (pid, step, signo)
  */
 
 static int
-register_gdb_signals (pi, signals)
-     procinfo *pi;
-     sigset_t *signals;
+register_gdb_signals (procinfo *pi, sigset_t *signals)
 {
   int signo;
 
@@ -4287,8 +4165,7 @@ register_gdb_signals (pi, signals)
  */
 
 static void
-procfs_notice_signals (pid)
-     int pid;
+procfs_notice_signals (int pid)
 {
   sigset_t signals;
   procinfo *pi = find_procinfo_or_die (PIDGET (pid), 0);
@@ -4307,8 +4184,7 @@ procfs_notice_signals (pid)
  */
 
 static void
-procfs_files_info (ignore)
-     struct target_ops *ignore;
+procfs_files_info (struct target_ops *ignore)
 {
   printf_filtered ("\tUsing the running image of %s %s via /proc.\n",
                   attach_flag? "attached": "child", 
@@ -4322,9 +4198,7 @@ procfs_files_info (ignore)
  */
 
 static void
-procfs_open (args, from_tty)
-     char *args;
-     int from_tty;
+procfs_open (char *args, int from_tty)
 {
   error ("Use the \"run\" command to start a Unix child process.");
 }
@@ -4343,7 +4217,7 @@ int procfs_suppress_run = 0;      /* Non-zero if procfs should pretend not to
 
 
 static int
-procfs_can_run ()
+procfs_can_run (void)
 {
   /* This variable is controlled by modules that sit atop procfs that
      may layer their own process structure atop that provided here.
@@ -4365,7 +4239,7 @@ procfs_can_run ()
  */
 
 static void
-procfs_stop ()
+procfs_stop (void)
 {
   extern pid_t inferior_process_group;
 
@@ -4382,8 +4256,7 @@ procfs_stop ()
  */
 
 static void
-unconditionally_kill_inferior (pi)
-     procinfo *pi;
+unconditionally_kill_inferior (procinfo *pi)
 {
   int parent_pid;
 
@@ -4418,7 +4291,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);
 
@@ -4427,9 +4300,9 @@ unconditionally_kill_inferior (pi)
     /* FIXME: should we use waitpid to make sure we get the right event?  
        Should we check the returned event?  */
     {
+#if 0
       int status, ret;
 
-#if 0
       ret = waitpid (pi->pid, &status, 0);
 #else
       wait (NULL);
@@ -4445,7 +4318,7 @@ unconditionally_kill_inferior (pi)
  */
 
 static void 
-procfs_kill_inferior ()
+procfs_kill_inferior (void)
 {
   if (inferior_pid != 0) /* ? */
     {
@@ -4465,7 +4338,7 @@ procfs_kill_inferior ()
  */
 
 static void 
-procfs_mourn_inferior ()
+procfs_mourn_inferior (void)
 {
   procinfo *pi;
 
@@ -4490,8 +4363,7 @@ procfs_mourn_inferior ()
  */
 
 static void 
-procfs_init_inferior (pid)
-     int pid;
+procfs_init_inferior (int pid)
 {
   procinfo *pi;
   sigset_t signals;
@@ -4547,6 +4419,10 @@ procfs_init_inferior (pid)
   if ((fail = procfs_debug_inferior (pi)) != 0)
     proc_error (pi, "init_inferior (procfs_debug_inferior)", fail);
 
+  /* FIXME: logically, we should really be turning OFF run-on-last-close,
+     and possibly even turning ON kill-on-last-close at this point.  But
+     I can't make that change without careful testing which I don't have
+     time to do right now...  */
   /* Turn on run-on-last-close flag so that the child
      will die if GDB goes away for some reason.  */
   if (!proc_set_run_on_last_close (pi))
@@ -4561,7 +4437,7 @@ procfs_init_inferior (pid)
 #else
   /* One trap to exec the shell, one to exec the program being debugged.  */
   startup_inferior (2);
-#endif
+#endif /* START_INFERIOR_TRAPS_EXPECTED */
 }
 
 /*
@@ -4577,7 +4453,7 @@ procfs_init_inferior (pid)
  */
 
 static void
-procfs_set_exec_trap ()
+procfs_set_exec_trap (void)
 {
   /* This routine called on the child side (inferior side)
      after GDB forks the inferior.  It must use only local variables,
@@ -4585,7 +4461,6 @@ procfs_set_exec_trap ()
 
   procinfo *pi;
   sysset_t exitset;
-  sysset_t entryset;
 
   if ((pi = create_procinfo (getpid (), 0)) == NULL)
     perror_with_name ("procfs: create_procinfo failed in child.");
@@ -4680,10 +4555,7 @@ procfs_set_exec_trap ()
  */
 
 static void
-procfs_create_inferior (exec_file, allargs, env)
-     char *exec_file;
-     char *allargs;
-     char **env;
+procfs_create_inferior (char *exec_file, char *allargs, char **env)
 {
   char *shell_file = getenv ("SHELL");
   char *tryname;
@@ -4772,10 +4644,7 @@ procfs_create_inferior (exec_file, allargs, env)
  */
 
 static int
-procfs_notice_thread (pi, thread, ptr)
-     procinfo *pi;
-     procinfo *thread;
-     void *ptr;
+procfs_notice_thread (procinfo *pi, procinfo *thread, void *ptr)
 {
   int gdb_threadid = MERGEPID (pi->pid, thread->tid);
 
@@ -4793,7 +4662,7 @@ procfs_notice_thread (pi, thread, ptr)
  */
 
 void
-procfs_find_new_threads ()
+procfs_find_new_threads (void)
 {
   procinfo *pi;
 
@@ -4813,8 +4682,7 @@ procfs_find_new_threads ()
  */
 
 static int
-procfs_thread_alive (pid)
-     int pid;
+procfs_thread_alive (int pid)
 {
   int proc, thread;
   procinfo *pi;
@@ -4844,8 +4712,7 @@ procfs_thread_alive (pid)
  */
 
 char *
-procfs_pid_to_str (pid)
-     int pid;
+procfs_pid_to_str (int pid)
 {
   static char buf[80];
   int proc, thread;
@@ -4868,12 +4735,7 @@ procfs_pid_to_str (pid)
  */
 
 int 
-procfs_set_watchpoint (pid, addr, len, rwflag, after)
-     int       pid;
-     CORE_ADDR addr;
-     int       len;
-     int       rwflag;
-     int       after;
+procfs_set_watchpoint (int pid, CORE_ADDR addr, int len, int rwflag, int after)
 {
 #ifndef UNIXWARE
   int       pflags = 0;
@@ -4927,8 +4789,7 @@ procfs_set_watchpoint (pid, addr, len, rwflag, after)
  */
 
 int
-procfs_stopped_by_watchpoint (pid)
-    int    pid;
+procfs_stopped_by_watchpoint (int pid)
 {
   procinfo *pi;
 
@@ -4963,8 +4824,7 @@ procfs_stopped_by_watchpoint (pid)
  */
 
 struct ssd *
-procfs_find_LDT_entry (pid)
-     int pid;
+procfs_find_LDT_entry (int pid)
 {
   gdb_gregset_t *gregs;
   int            key;
@@ -4995,9 +4855,7 @@ procfs_find_LDT_entry (pid)
 
 
 static void
-info_proc_cmd (args, from_tty)
-     char *args;
-     int from_tty;
+info_proc_cmd (char *args, int from_tty)
 {
   struct cleanup *old_chain;
   procinfo *process = NULL;
@@ -5009,11 +4867,12 @@ info_proc_cmd (args, from_tty)
 
   old_chain = make_cleanup (null_cleanup, 0);
   if (args)
-    if ((argv = buildargv (args)) == NULL)
-      nomem (0);
-    else
-      make_cleanup ((make_cleanup_func) freeargv, argv);
-
+    {
+      if ((argv = buildargv (args)) == NULL)
+       nomem (0);
+      else
+       make_cleanup_freeargv (argv);
+    }
   while (argv != NULL && *argv != NULL)
     {
       if (isdigit (argv[0][0]))
@@ -5046,7 +4905,7 @@ info_proc_cmd (args, from_tty)
           /* No.  So open a procinfo for it, but 
              remember to close it again when finished.  */
           process = create_procinfo (pid, 0);
-          make_cleanup ((make_cleanup_func) destroy_procinfo, process);
+          make_cleanup (do_destroy_procinfo_cleanup, process);
           if (!open_procinfo_files (process, FD_CTL))
             proc_error (process, "info proc, open_procinfo_files", __LINE__);
         }
@@ -5076,11 +4935,7 @@ info_proc_cmd (args, from_tty)
 }
 
 static void
-proc_trace_syscalls (args, from_tty, entry_or_exit, mode)
-     char *args;
-     int   from_tty;
-     int   entry_or_exit;
-     int   mode;
+proc_trace_syscalls (char *args, int from_tty, int entry_or_exit, int mode)
 {
   procinfo *pi;
   sysset_t *sysset;
@@ -5123,61 +4978,32 @@ proc_trace_syscalls (args, from_tty, entry_or_exit, mode)
 }
 
 static void 
-proc_trace_sysentry_cmd (args, from_tty)
-     char *args;
-     int   from_tty;
+proc_trace_sysentry_cmd (char *args, int from_tty)
 {
   proc_trace_syscalls (args, from_tty, PR_SYSENTRY, FLAG_SET);
 }
 
 static void 
-proc_trace_sysexit_cmd (args, from_tty)
-     char *args;
-     int   from_tty;
+proc_trace_sysexit_cmd (char *args, int from_tty)
 {
   proc_trace_syscalls (args, from_tty, PR_SYSEXIT, FLAG_SET);
 }
 
 static void 
-proc_untrace_sysentry_cmd (args, from_tty)
-     char *args;
-     int   from_tty;
+proc_untrace_sysentry_cmd (char *args, int from_tty)
 {
   proc_trace_syscalls (args, from_tty, PR_SYSENTRY, FLAG_RESET);
 }
 
 static void 
-proc_untrace_sysexit_cmd (args, from_tty)
-     char *args;
-     int   from_tty;
+proc_untrace_sysexit_cmd (char *args, int from_tty)
 {
   proc_trace_syscalls (args, from_tty, PR_SYSEXIT, FLAG_RESET);
 }
 
 
-int
-mapping_test (fd, core_addr)
-     int fd;
-     CORE_ADDR core_addr;
-{
-  printf ("File descriptor %d, base address 0x%08x\n", fd, core_addr);
-  if (fd > 0)
-    close (fd);
-  return 0;
-}
-
-void
-test_mapping_cmd (args, from_tty)
-     char *args;
-     int from_tty;
-{
-  int ret;
-  ret = proc_iterate_over_mappings (mapping_test);
-  printf ("iterate_over_mappings returned %d.\n", ret);
-}
-
 void
-_initialize_procfs ()
+_initialize_procfs (void)
 {
   init_procfs_ops ();
   add_target (&procfs_ops);
@@ -5192,9 +5018,6 @@ Default is the process being debugged.");
           "Cancel a trace of entries into the syscall.");
   add_com ("proc-untrace-exit", no_class, proc_untrace_sysexit_cmd, 
           "Cancel a trace of exits from the syscall.");
-
-  add_com ("test-mapping", no_class, test_mapping_cmd, 
-          "test iterate-over-mappings");
 }
 
 /* =================== END, GDB  "MODULE" =================== */
@@ -5212,27 +5035,10 @@ Default is the process being debugged.");
  */
 
 int
-procfs_first_available ()
+procfs_first_available (void)
 {
   if (procinfo_list)
     return procinfo_list->pid;
   else
     return -1;
 }
-
-int
-procfs_get_pid_fd (pid)
-     int pid;
-{
-  procinfo *pi;
-
-  if (pid == -1 && inferior_pid != 0)
-    pi = find_procinfo (PIDGET (inferior_pid), 0);
-  else
-    pi = find_procinfo (PIDGET (pid), 0);
-
-  if (pi)
-    return pi->ctl_fd;
-  else
-    return -1;
-}
This page took 0.046162 seconds and 4 git commands to generate.