/* 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.
#include <signal.h>
#include <ctype.h>
-#include "proc-utils.h"
-
/*
* PROCFS.C
*
#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";
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;
/* =================== 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:
*
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
-
/* Provide default composite pid manipulation macros for systems that
don't have threads. */
/* 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;
*/
static procinfo *
-find_procinfo (pid, tid)
- int pid;
- int tid;
+find_procinfo (int pid, int tid)
{
procinfo *pi;
*/
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);
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];
* 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;
*/
static void
-close_procinfo_files (pi)
- procinfo *pi;
+close_procinfo_files (procinfo *pi)
{
if (pi->ctl_fd > 0)
close (pi->ctl_fd);
*/
static void
-destroy_one_procinfo (list, pi)
- procinfo **list;
- procinfo *pi;
+destroy_one_procinfo (procinfo **list, procinfo *pi)
{
procinfo *ptr;
close_procinfo_files (pi);
/* Step three: free the memory. */
- free (pi);
+ xfree (pi);
}
static void
-destroy_procinfo (pi)
- procinfo *pi;
+destroy_procinfo (procinfo *pi)
{
procinfo *tmp;
}
}
+static void
+do_destroy_procinfo_cleanup (void *pi)
+{
+ destroy_procinfo (pi);
+}
+
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];
* 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);
*/
int
-proc_get_status (pi)
- procinfo *pi;
+proc_get_status (procinfo *pi)
{
/* Status file descriptor is opened "lazily" */
if (pi->status_fd == 0 &&
*/
long
-proc_flags (pi)
- procinfo *pi;
+proc_flags (procinfo *pi)
{
if (!pi->status_valid)
if (!proc_get_status (pi))
*/
int
-proc_why (pi)
- procinfo *pi;
+proc_why (procinfo *pi)
{
if (!pi->status_valid)
if (!proc_get_status (pi))
*/
int
-proc_what (pi)
- procinfo *pi;
+proc_what (procinfo *pi)
{
if (!pi->status_valid)
if (!proc_get_status (pi))
*/
int
-proc_nsysarg (pi)
- procinfo *pi;
+proc_nsysarg (procinfo *pi)
{
if (!pi->status_valid)
if (!proc_get_status (pi))
*/
long *
-proc_sysargs (pi)
- procinfo *pi;
+proc_sysargs (procinfo *pi)
{
if (!pi->status_valid)
if (!proc_get_status (pi))
*/
int
-proc_syscall (pi)
- procinfo *pi;
+proc_syscall (procinfo *pi)
{
if (!pi->status_valid)
if (!proc_get_status (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 */
*/
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);
}
*/
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);
}
*/
int
-proc_set_kill_on_last_close (pi)
- procinfo *pi;
+proc_set_kill_on_last_close (procinfo *pi)
{
return proc_modify_flag (pi, PR_KLC, FLAG_SET);
}
*/
int
-proc_unset_kill_on_last_close (pi)
- procinfo *pi;
+proc_unset_kill_on_last_close (procinfo *pi)
{
return proc_modify_flag (pi, PR_KLC, FLAG_RESET);
}
*/
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);
}
*/
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);
}
*/
int
-proc_set_async (pi)
- procinfo *pi;
+proc_set_async (procinfo *pi)
{
return proc_modify_flag (pi, PR_ASYNC, FLAG_SET);
}
*/
int
-proc_unset_async (pi)
- procinfo *pi;
+proc_unset_async (procinfo *pi)
{
return proc_modify_flag (pi, PR_ASYNC, FLAG_RESET);
}
*/
int
-proc_stop_process (pi)
- procinfo *pi;
+proc_stop_process (procinfo *pi)
{
int win;
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);
*/
int
-proc_wait_for_stop (pi)
- procinfo *pi;
+proc_wait_for_stop (procinfo *pi)
{
int win;
#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;
*/
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;
#ifdef NEW_PROC_API
{
- int cmd[2];
+ long cmd[2];
cmd[0] = PCRUN;
cmd[1] = runflags;
*/
int
-proc_set_traced_signals (pi, sigset)
- procinfo *pi;
- sigset_t *sigset;
+proc_set_traced_signals (procinfo *pi, sigset_t *sigset)
{
int win;
#ifdef NEW_PROC_API
{
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char sigset[sizeof (sigset_t)];
} arg;
*/
int
-proc_set_traced_faults (pi, fltset)
- procinfo *pi;
- fltset_t *fltset;
+proc_set_traced_faults (procinfo *pi, fltset_t *fltset)
{
int win;
#ifdef NEW_PROC_API
{
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char fltset[sizeof (fltset_t)];
} arg;
*/
int
-proc_set_traced_sysentry (pi, sysset)
- procinfo *pi;
- sysset_t *sysset;
+proc_set_traced_sysentry (procinfo *pi, sysset_t *sysset)
{
int win;
#ifdef NEW_PROC_API
{
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char sysset[sizeof (sysset_t)];
} arg;
*/
int
-proc_set_traced_sysexit (pi, sysset)
- procinfo *pi;
- sysset_t *sysset;
+proc_set_traced_sysexit (procinfo *pi, sysset_t *sysset)
{
int win;
#ifdef NEW_PROC_API
{
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char sysset[sizeof (sysset_t)];
} arg;
*/
int
-proc_set_held_signals (pi, sighold)
- procinfo *pi;
- sigset_t *sighold;
+proc_set_held_signals (procinfo *pi, sigset_t *sighold)
{
int win;
#ifdef NEW_PROC_API
{
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char hold[sizeof (sigset_t)];
} arg;
*/
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;
*/
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;
*/
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;
*/
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;
*/
int
-proc_trace_signal (pi, signo)
- procinfo *pi;
- int signo;
+proc_trace_signal (procinfo *pi, int signo)
{
sigset_t temp;
*/
int
-proc_ignore_signal (pi, signo)
- procinfo *pi;
- int signo;
+proc_ignore_signal (procinfo *pi, int signo)
{
sigset_t temp;
*/
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;
*/
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;
*/
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;
*/
int
-proc_clear_current_fault (pi)
- procinfo *pi;
+proc_clear_current_fault (procinfo *pi)
{
int win;
#ifdef NEW_PROC_API
{
- int cmd = PCCFAULT;
+ long cmd = PCCFAULT;
win = (write (pi->ctl_fd, (void *) &cmd, sizeof (cmd)) == sizeof (cmd));
}
#else
*/
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;
*/
int
-proc_clear_current_signal (pi)
- procinfo *pi;
+proc_clear_current_signal (procinfo *pi)
{
int win;
#ifdef NEW_PROC_API
{
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char sinfo[sizeof (struct siginfo)];
} arg;
*/
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))
*/
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)
*/
int
-proc_set_gregs (pi)
- procinfo *pi;
+proc_set_gregs (procinfo *pi)
{
gdb_gregset_t *gregs;
int win;
{
#ifdef NEW_PROC_API
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char gregs[sizeof (gdb_gregset_t)];
} arg;
*/
int
-proc_set_fpregs (pi)
- procinfo *pi;
+proc_set_fpregs (procinfo *pi)
{
gdb_fpregset_t *fpregs;
int win;
{
#ifdef NEW_PROC_API
struct {
- int cmd;
+ long cmd;
/* Use char array to avoid alignment issues. */
char fpregs[sizeof (gdb_fpregset_t)];
} arg;
*/
int
-proc_kill (pi, signo)
- procinfo *pi;
- int signo;
+proc_kill (procinfo *pi, int signo)
{
int win;
else
{
#ifdef NEW_PROC_API
- int cmd[2];
+ long cmd[2];
cmd[0] = PCKILL;
cmd[1] = signo;
*/
int
-proc_parent_pid (pi)
- procinfo *pi;
+proc_parent_pid (procinfo *pi)
{
/*
* We should never have to apply this operation to any procinfo
*/
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;
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)
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;
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));
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
*/
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
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))
* OSF version
*/
int
-proc_get_nthreads (pi)
- procinfo *pi;
+proc_get_nthreads (procinfo *pi)
{
int nthreads = 0;
* 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))
* Default version
*/
int
-proc_get_nthreads (pi)
- procinfo *pi;
+proc_get_nthreads (procinfo *pi)
{
return 0;
}
* 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,
* 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;
* Default version
*/
int
-proc_get_current_thread (pi)
- procinfo *pi;
+proc_get_current_thread (procinfo *pi)
{
return 0;
}
*/
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 */
{
* 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;
malloc (sizeof (gdb_prstatus_t) * (nlwp + 1))) == 0)
perror_with_name ("procfs: malloc failed in update_threads");
- old_chain = make_cleanup (free, prstatus);
+ old_chain = make_cleanup (xfree, prstatus);
if (ioctl (pi->ctl_fd, PIOCLSTATUS, prstatus) < 0)
proc_error (pi, "update_threads (PIOCLSTATUS)", __LINE__);
/*
* 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;
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 '..' */
{
* OSF version
*/
int
-proc_update_threads (pi)
- procinfo *pi;
+proc_update_threads (procinfo *pi)
{
int nthreads, i;
tid_t *threads;
* Default version
*/
int
-proc_update_threads (pi)
- procinfo *pi;
+proc_update_threads (procinfo *pi)
{
return 0;
}
*/
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;
* 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
*/
static int
-procfs_debug_inferior (pi)
- procinfo *pi;
+procfs_debug_inferior (procinfo *pi)
{
fltset_t traced_faults;
sigset_t traced_signals;
}
static void
-procfs_attach (args, from_tty)
- char *args;
- int from_tty;
+procfs_attach (char *args, int from_tty)
{
char *exec_file;
int pid;
}
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;
}
static int
-do_attach (pid)
- int pid;
+do_attach (int pid)
{
procinfo *pi;
int fail;
}
static void
-do_detach (signo)
- int signo;
+do_detach (int signo)
{
procinfo *pi;
*/
static void
-procfs_fetch_registers (regno)
- int regno;
+procfs_fetch_registers (int regno)
{
gdb_fpregset_t *fpregs;
gdb_gregset_t *gregs;
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
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 ();
*/
static void
-procfs_store_registers (regno)
- int regno;
+procfs_store_registers (int regno)
{
gdb_fpregset_t *fpregs;
gdb_gregset_t *gregs;
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__);
+ }
}
/*
*/
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;
return a "success" exit code. Bogus: what if
it returns something else? */
wstat = 0;
- retval = inferior_pid; /* ??? */
+ retval = inferior_pid; /* ? ? ? */
}
else
{
{
printf_filtered ("%ld syscall arguments:\n", nsysargs);
for (i = 0; i < nsysargs; i++)
- printf_filtered ("#%ld: 0x%08x\n",
+ printf_filtered ("#%ld: 0x%08lx\n",
i, sysargs[i]);
}
{
printf_filtered ("%ld syscall arguments:\n", nsysargs);
for (i = 0; i < nsysargs; i++)
- printf_filtered ("#%ld: 0x%08x\n",
+ printf_filtered ("#%ld: 0x%08lx\n",
i, sysargs[i]);
}
}
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;
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.
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)
*/
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)
*/
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;
*/
static int
-register_gdb_signals (pi, signals)
- procinfo *pi;
- sigset_t *signals;
+register_gdb_signals (procinfo *pi, sigset_t *signals)
{
int signo;
*/
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);
*/
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",
*/
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.");
}
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.
*/
static void
-procfs_stop ()
+procfs_stop (void)
{
extern pid_t inferior_process_group;
*/
static void
-unconditionally_kill_inferior (pi)
- procinfo *pi;
+unconditionally_kill_inferior (procinfo *pi)
{
int parent_pid;
}
#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);
*/
static void
-procfs_kill_inferior ()
+procfs_kill_inferior (void)
{
if (inferior_pid != 0) /* ? */
{
*/
static void
-procfs_mourn_inferior ()
+procfs_mourn_inferior (void)
{
procinfo *pi;
*/
static void
-procfs_init_inferior (pid)
- int pid;
+procfs_init_inferior (int pid)
{
procinfo *pi;
sigset_t signals;
*/
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,
*/
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;
*/
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);
*/
void
-procfs_find_new_threads ()
+procfs_find_new_threads (void)
{
procinfo *pi;
*/
static int
-procfs_thread_alive (pid)
- int pid;
+procfs_thread_alive (int pid)
{
int proc, thread;
procinfo *pi;
*/
char *
-procfs_pid_to_str (pid)
- int pid;
+procfs_pid_to_str (int pid)
{
static char buf[80];
int proc, thread;
*/
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;
*/
int
-procfs_stopped_by_watchpoint (pid)
- int pid;
+procfs_stopped_by_watchpoint (int pid)
{
procinfo *pi;
- pi = find_procinfo_or_die (pid == -1 ?
- PIDGET (inferior_pid) : PIDGET (pid), 0);
+ pi = find_procinfo (pid == -1 ?
+ PIDGET (inferior_pid) : PIDGET (pid), 0);
+
+ if (!pi) /* If no process, then not stopped by watchpoint! */
+ return 0;
+
if (proc_flags (pi) & (PR_STOPPED | PR_ISTOP))
{
if (proc_why (pi) == PR_FAULTED)
*/
struct ssd *
-procfs_find_LDT_entry (pid)
- int pid;
+procfs_find_LDT_entry (int pid)
{
gdb_gregset_t *gregs;
int key;
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;
if ((argv = buildargv (args)) == NULL)
nomem (0);
else
- make_cleanup ((make_cleanup_func) freeargv, argv);
+ make_cleanup_freeargv (argv);
}
while (argv != NULL && *argv != NULL)
{
/* 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__);
}
}
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;
}
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);
"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" =================== */
*/
int
-procfs_first_available ()
+procfs_first_available (void)
{
if (procinfo_list)
return procinfo_list->pid;