aboutsummaryrefslogtreecommitdiff
path: root/gdb/procfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/procfs.c')
-rw-r--r--gdb/procfs.c222
1 files changed, 113 insertions, 109 deletions
diff --git a/gdb/procfs.c b/gdb/procfs.c
index c0d3277..53f0489 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -106,26 +106,26 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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 void procfs_resume (ptid_t, 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_notice_signals (ptid_t);
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 ptid_t procfs_wait (ptid_t, struct target_waitstatus *);
static int procfs_xfer_memory (CORE_ADDR, char *, int, int,
struct mem_attrib *attrib,
struct target_ops *);
-static int procfs_thread_alive (int);
+static int procfs_thread_alive (ptid_t);
void procfs_find_new_threads (void);
-char *procfs_pid_to_str (int);
+char *procfs_pid_to_str (ptid_t);
struct target_ops procfs_ops; /* the target vector */
@@ -2904,7 +2904,7 @@ proc_iterate_over_mappings (int (*func) (int, CORE_ADDR))
int funcstat = 0;
int fd;
- pi = find_procinfo_or_die (PIDGET (inferior_pid), 0);
+ pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
#ifdef NEW_PROC_API
/* Open map fd. */
@@ -3450,7 +3450,7 @@ proc_iterate_over_threads (procinfo *pi,
* Here are all of the gdb target vector functions and their friends.
*/
-static int do_attach (int pid);
+static ptid_t do_attach (ptid_t ptid);
static void do_detach (int signo);
static int register_gdb_signals (procinfo *, gdb_sigset_t *);
@@ -3602,13 +3602,14 @@ procfs_attach (char *args, int from_tty)
if (exec_file)
printf_filtered ("Attaching to program `%s', %s\n",
- exec_file, target_pid_to_str (pid));
+ exec_file, target_pid_to_str (pid_to_ptid (pid)));
else
- printf_filtered ("Attaching to %s\n", target_pid_to_str (pid));
+ printf_filtered ("Attaching to %s\n",
+ target_pid_to_str (pid_to_ptid (pid)));
fflush (stdout);
}
- inferior_pid = do_attach (pid);
+ inferior_ptid = do_attach (pid_to_ptid (pid));
push_target (&procfs_ops);
}
@@ -3624,31 +3625,31 @@ procfs_detach (char *args, int from_tty)
if (exec_file == 0)
exec_file = "";
printf_filtered ("Detaching from program: %s %s\n",
- exec_file, target_pid_to_str (inferior_pid));
+ exec_file, target_pid_to_str (inferior_ptid));
fflush (stdout);
}
if (args)
signo = atoi (args);
do_detach (signo);
- inferior_pid = 0;
+ inferior_ptid = null_ptid;
unpush_target (&procfs_ops); /* Pop out of handling an inferior */
}
-static int
-do_attach (int pid)
+static ptid_t
+do_attach (ptid_t ptid)
{
procinfo *pi;
int fail;
- if ((pi = create_procinfo (pid, 0)) == NULL)
+ if ((pi = create_procinfo (PIDGET (ptid), 0)) == NULL)
perror ("procfs: out of memory in 'attach'");
if (!open_procinfo_files (pi, FD_CTL))
{
fprintf_filtered (gdb_stderr, "procfs:%d -- ", __LINE__);
sprintf (errmsg, "do_attach: couldn't open /proc file for process %d",
- pid);
+ PIDGET (ptid));
dead_procinfo (pi, errmsg, NOKILL);
}
@@ -3698,7 +3699,7 @@ do_detach (int signo)
procinfo *pi;
/* Find procinfo for the main process */
- pi = find_procinfo_or_die (PIDGET (inferior_pid), 0); /* FIXME: threads */
+ pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0); /* FIXME: threads */
if (signo)
if (!proc_set_current_signal (pi, signo))
proc_warn (pi, "do_detach, set_current_signal", __LINE__);
@@ -3754,14 +3755,14 @@ procfs_fetch_registers (int regno)
int pid;
int tid;
- pid = PIDGET (inferior_pid);
- tid = TIDGET (inferior_pid);
+ pid = PIDGET (inferior_ptid);
+ tid = TIDGET (inferior_ptid);
/* First look up procinfo for the main process. */
pi = find_procinfo_or_die (pid, 0);
/* If the event thread is not the same as GDB's requested thread
- (ie. inferior_pid), then look up procinfo for the requested
+ (ie. inferior_ptid), then look up procinfo for the requested
thread. */
if ((tid != 0) &&
(tid != proc_get_current_thread (pi)))
@@ -3769,7 +3770,7 @@ procfs_fetch_registers (int regno)
if (pi == NULL)
error ("procfs: fetch_registers failed to find procinfo for %s",
- target_pid_to_str (inferior_pid));
+ target_pid_to_str (inferior_ptid));
if ((gregs = proc_get_gregs (pi)) == NULL)
proc_error (pi, "fetch_registers, get_gregs", __LINE__);
@@ -3826,14 +3827,14 @@ procfs_store_registers (int regno)
int pid;
int tid;
- pid = PIDGET (inferior_pid);
- tid = TIDGET (inferior_pid);
+ pid = PIDGET (inferior_ptid);
+ tid = TIDGET (inferior_ptid);
/* First find procinfo for main process */
pi = find_procinfo_or_die (pid, 0);
/* If current lwp for process is not the same as requested thread
- (ie. inferior_pid), then find procinfo for the requested thread. */
+ (ie. inferior_ptid), then find procinfo for the requested thread. */
if ((tid != 0) &&
(tid != proc_get_current_thread (pi)))
@@ -3841,7 +3842,7 @@ procfs_store_registers (int regno)
if (pi == NULL)
error ("procfs: store_registers: failed to find procinfo for %s",
- target_pid_to_str (inferior_pid));
+ target_pid_to_str (inferior_ptid));
if ((gregs = proc_get_gregs (pi)) == NULL)
proc_error (pi, "store_registers, get_gregs", __LINE__);
@@ -3947,13 +3948,14 @@ syscall_is_lwp_create (procinfo *pi, int scall)
* event codes are returned thru a pointer parameter.
*/
-static int
-procfs_wait (int pid, struct target_waitstatus *status)
+static ptid_t
+procfs_wait (ptid_t ptid, struct target_waitstatus *status)
{
/* First cut: loosely based on original version 2.1 */
procinfo *pi;
- int temp, wstat;
- int retval;
+ int wstat;
+ int temp_tid;
+ ptid_t retval, temp_ptid;
int why, what, flags;
int retry = 0;
@@ -3961,10 +3963,10 @@ wait_again:
retry++;
wstat = 0;
- retval = -1;
+ retval = pid_to_ptid (-1);
/* Find procinfo for main process */
- pi = find_procinfo_or_die (PIDGET (inferior_pid), 0);
+ pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
if (pi)
{
/* We must assume that the status is stale now... */
@@ -3985,14 +3987,17 @@ wait_again:
/* wait_for_stop failed: has the child terminated? */
if (errno == ENOENT)
{
+ int wait_retval;
+
/* /proc file not found; presumably child has terminated. */
- retval = wait (&wstat); /* "wait" for the child's exit */
+ wait_retval = wait (&wstat); /* "wait" for the child's exit */
- if (retval != PIDGET (inferior_pid)) /* wrong child? */
+ if (wait_retval != PIDGET (inferior_ptid)) /* wrong child? */
error ("procfs: couldn't stop process %d: wait returned %d\n",
- inferior_pid, retval);
+ PIDGET (inferior_ptid), wait_retval);
/* FIXME: might I not just use waitpid?
Or try find_procinfo to see if I know about this child? */
+ retval = pid_to_ptid (wait_retval);
}
else if (errno == EINTR)
goto wait_again;
@@ -4069,7 +4074,7 @@ wait_again:
return a "success" exit code. Bogus: what if
it returns something else? */
wstat = 0;
- retval = inferior_pid; /* ? ? ? */
+ retval = inferior_ptid; /* ? ? ? */
}
else
{
@@ -4084,7 +4089,7 @@ wait_again:
/* If wait returns -1, that's what we return to GDB. */
if (temp < 0)
- retval = temp;
+ retval = pid_to_ptid (temp);
}
}
else
@@ -4111,12 +4116,12 @@ wait_again:
{
/* How to exit gracefully, returning "unknown event" */
status->kind = TARGET_WAITKIND_SPURIOUS;
- return inferior_pid;
+ return inferior_ptid;
}
else
{
/* How to keep going without returning to wfi: */
- target_resume (pid, 0, TARGET_SIGNAL_0);
+ target_resume (ptid, 0, TARGET_SIGNAL_0);
goto wait_again;
}
}
@@ -4142,20 +4147,21 @@ wait_again:
*/
/* If not in procinfo list, add it. */
- temp = proc_get_current_thread (pi);
- if (!find_procinfo (pi->pid, temp))
- create_procinfo (pi->pid, temp);
+ temp_tid = proc_get_current_thread (pi);
+ if (!find_procinfo (pi->pid, temp_tid))
+ create_procinfo (pi->pid, temp_tid);
- temp = MERGEPID (pi->pid, temp);
+ temp_ptid = MERGEPID (pi->pid, temp_tid);
/* If not in GDB's thread list, add it. */
- if (!in_thread_list (temp))
+ if (!in_thread_list (temp_ptid))
{
- printf_filtered ("[New %s]\n", target_pid_to_str (temp));
- add_thread (temp);
+ printf_filtered ("[New %s]\n",
+ target_pid_to_str (temp_ptid));
+ add_thread (temp_ptid);
}
/* Return to WFI, but tell it to immediately resume. */
status->kind = TARGET_WAITKIND_SPURIOUS;
- return inferior_pid;
+ return inferior_ptid;
}
else if (syscall_is_lwp_exit (pi, what))
{
@@ -4194,7 +4200,7 @@ wait_again:
}
#endif
status->kind = TARGET_WAITKIND_SPURIOUS;
- return inferior_pid;
+ return inferior_ptid;
}
break;
case PR_REQUESTED:
@@ -4211,17 +4217,17 @@ wait_again:
else
{
/* If not in procinfo list, add it. */
- temp = proc_get_current_thread (pi);
- if (!find_procinfo (pi->pid, temp))
- create_procinfo (pi->pid, temp);
+ temp_tid = proc_get_current_thread (pi);
+ if (!find_procinfo (pi->pid, temp_tid))
+ create_procinfo (pi->pid, temp_tid);
/* If not in GDB's thread list, add it. */
- temp = MERGEPID (pi->pid, temp);
- if (!in_thread_list (temp))
+ temp_ptid = MERGEPID (pi->pid, temp_tid);
+ if (!in_thread_list (temp_ptid))
{
printf_filtered ("[New %s]\n",
- target_pid_to_str (temp));
- add_thread (temp);
+ target_pid_to_str (temp_ptid));
+ add_thread (temp_ptid);
}
status->kind = TARGET_WAITKIND_STOPPED;
@@ -4273,7 +4279,7 @@ wait_again:
break;
case FLTPAGE: /* Recoverable page fault */
default: /* FIXME: use si_signo if possible for fault */
- retval = -1;
+ retval = pid_to_ptid (-1);
printf_filtered ("procfs:%d -- ", __LINE__);
printf_filtered ("child stopped for unknown reason:\n");
proc_prettyprint_why (why, what, 1);
@@ -4292,8 +4298,8 @@ wait_again:
* Got this far without error:
* If retval isn't in the threads database, add it.
*/
- if (retval > 0 &&
- retval != inferior_pid &&
+ if (PIDGET (retval) > 0 &&
+ !ptid_equal (retval, inferior_ptid) &&
!in_thread_list (retval))
{
/*
@@ -4309,16 +4315,16 @@ wait_again:
/* In addition, it's possible that this is the first
* new thread we've seen, in which case we may not
- * have created entries for inferior_pid yet.
+ * have created entries for inferior_ptid yet.
*/
- if (TIDGET (inferior_pid) != 0)
+ if (TIDGET (inferior_ptid) != 0)
{
- if (!in_thread_list (inferior_pid))
- add_thread (inferior_pid);
- if (find_procinfo (PIDGET (inferior_pid),
- TIDGET (inferior_pid)) == NULL)
- create_procinfo (PIDGET (inferior_pid),
- TIDGET (inferior_pid));
+ if (!in_thread_list (inferior_ptid))
+ add_thread (inferior_ptid);
+ if (find_procinfo (PIDGET (inferior_ptid),
+ TIDGET (inferior_ptid)) == NULL)
+ create_procinfo (PIDGET (inferior_ptid),
+ TIDGET (inferior_ptid));
}
}
}
@@ -4357,7 +4363,7 @@ procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int dowrite,
int nbytes = 0;
/* Find procinfo for main process */
- pi = find_procinfo_or_die (PIDGET (inferior_pid), 0);
+ pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
if (pi->as_fd == 0 &&
open_procinfo_files (pi, FD_AS) == 0)
{
@@ -4495,7 +4501,7 @@ make_signal_thread_runnable (procinfo *process, procinfo *pi, void *ptr)
*/
static void
-procfs_resume (int pid, int step, enum target_signal signo)
+procfs_resume (ptid_t ptid, int step, enum target_signal signo)
{
procinfo *pi, *thread;
int native_signo;
@@ -4517,7 +4523,7 @@ procfs_resume (int pid, int step, enum target_signal signo)
to proc_run_process (for use in the prrun struct by ioctl). */
/* Find procinfo for main process */
- pi = find_procinfo_or_die (PIDGET (inferior_pid), 0);
+ pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
/* First cut: ignore pid argument */
errno = 0;
@@ -4537,13 +4543,13 @@ procfs_resume (int pid, int step, enum target_signal signo)
/* Void the process procinfo's caches. */
invalidate_cache (NULL, pi, NULL);
- if (pid != -1)
+ if (PIDGET (ptid) != -1)
{
/* Resume a specific thread, presumably suppressing the others. */
- thread = find_procinfo (PIDGET (pid), TIDGET (pid));
+ thread = find_procinfo (PIDGET (ptid), TIDGET (ptid));
if (thread == NULL)
- warning ("procfs: resume can't find thread %d -- resuming all.",
- TIDGET (pid));
+ warning ("procfs: resume can't find thread %ld -- resuming all.",
+ TIDGET (ptid));
else
{
if (thread->tid != 0)
@@ -4607,10 +4613,10 @@ register_gdb_signals (procinfo *pi, gdb_sigset_t *signals)
*/
static void
-procfs_notice_signals (int pid)
+procfs_notice_signals (ptid_t ptid)
{
gdb_sigset_t signals;
- procinfo *pi = find_procinfo_or_die (PIDGET (pid), 0);
+ procinfo *pi = find_procinfo_or_die (PIDGET (ptid), 0);
if (proc_get_traced_signals (pi, &signals) &&
register_gdb_signals (pi, &signals))
@@ -4630,7 +4636,7 @@ procfs_files_info (struct target_ops *ignore)
{
printf_filtered ("\tUsing the running image of %s %s via /proc.\n",
attach_flag? "attached": "child",
- target_pid_to_str (inferior_pid));
+ target_pid_to_str (inferior_ptid));
}
/*
@@ -4762,10 +4768,10 @@ unconditionally_kill_inferior (procinfo *pi)
static void
procfs_kill_inferior (void)
{
- if (inferior_pid != 0) /* ? */
+ if (!ptid_equal (inferior_ptid, null_ptid)) /* ? */
{
/* Find procinfo for main process */
- procinfo *pi = find_procinfo (PIDGET (inferior_pid), 0);
+ procinfo *pi = find_procinfo (PIDGET (inferior_ptid), 0);
if (pi)
unconditionally_kill_inferior (pi);
@@ -4784,10 +4790,10 @@ procfs_mourn_inferior (void)
{
procinfo *pi;
- if (inferior_pid != 0)
+ if (!ptid_equal (inferior_ptid, null_ptid))
{
/* Find procinfo for main process */
- pi = find_procinfo (PIDGET (inferior_pid), 0);
+ pi = find_procinfo (PIDGET (inferior_ptid), 0);
if (pi)
destroy_procinfo (pi);
}
@@ -4872,7 +4878,7 @@ procfs_init_inferior (int pid)
/* The 'process ID' we return to GDB is composed of
the actual process ID plus the lwp ID. */
- inferior_pid = MERGEPID (pi->pid, proc_get_current_thread (pi));
+ inferior_ptid = MERGEPID (pi->pid, proc_get_current_thread (pi));
#ifdef START_INFERIOR_TRAPS_EXPECTED
startup_inferior (START_INFERIOR_TRAPS_EXPECTED);
@@ -5101,7 +5107,7 @@ procfs_create_inferior (char *exec_file, char *allargs, char **env)
static int
procfs_notice_thread (procinfo *pi, procinfo *thread, void *ptr)
{
- int gdb_threadid = MERGEPID (pi->pid, thread->tid);
+ ptid_t gdb_threadid = MERGEPID (pi->pid, thread->tid);
if (!in_thread_list (gdb_threadid))
add_thread (gdb_threadid);
@@ -5122,7 +5128,7 @@ procfs_find_new_threads (void)
procinfo *pi;
/* Find procinfo for main process */
- pi = find_procinfo_or_die (PIDGET (inferior_pid), 0);
+ pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
proc_update_threads (pi);
proc_iterate_over_threads (pi, procfs_notice_thread, NULL);
}
@@ -5137,13 +5143,13 @@ procfs_find_new_threads (void)
*/
static int
-procfs_thread_alive (int pid)
+procfs_thread_alive (ptid_t ptid)
{
int proc, thread;
procinfo *pi;
- proc = PIDGET (pid);
- thread = TIDGET (pid);
+ proc = PIDGET (ptid);
+ thread = TIDGET (ptid);
/* If I don't know it, it ain't alive! */
if ((pi = find_procinfo (proc, thread)) == NULL)
return 0;
@@ -5167,14 +5173,14 @@ procfs_thread_alive (int pid)
*/
char *
-procfs_pid_to_str (int pid)
+procfs_pid_to_str (ptid_t ptid)
{
static char buf[80];
int proc, thread;
procinfo *pi;
- proc = PIDGET (pid);
- thread = TIDGET (pid);
+ proc = PIDGET (ptid);
+ thread = TIDGET (ptid);
pi = find_procinfo (proc, thread);
if (thread == 0)
@@ -5190,15 +5196,16 @@ procfs_pid_to_str (int pid)
*/
int
-procfs_set_watchpoint (int pid, CORE_ADDR addr, int len, int rwflag, int after)
+procfs_set_watchpoint (ptid_t ptid, CORE_ADDR addr, int len, int rwflag,
+ int after)
{
#ifndef UNIXWARE
#ifndef AIX5
int pflags = 0;
procinfo *pi;
- pi = find_procinfo_or_die (pid == -1 ?
- PIDGET (inferior_pid) : PIDGET (pid), 0);
+ pi = find_procinfo_or_die (PIDGET (ptid) == -1 ?
+ PIDGET (inferior_ptid) : PIDGET (ptid), 0);
/* Translate from GDB's flags to /proc's */
if (len > 0) /* len == 0 means delete watchpoint */
@@ -5246,12 +5253,12 @@ procfs_set_watchpoint (int pid, CORE_ADDR addr, int len, int rwflag, int after)
*/
int
-procfs_stopped_by_watchpoint (int pid)
+procfs_stopped_by_watchpoint (ptid_t ptid)
{
procinfo *pi;
- pi = find_procinfo (pid == -1 ?
- PIDGET (inferior_pid) : PIDGET (pid), 0);
+ pi = find_procinfo_or_die (PIDGET (ptid) == -1 ?
+ PIDGET (inferior_ptid) : PIDGET (ptid), 0);
if (!pi) /* If no process, then not stopped by watchpoint! */
return 0;
@@ -5278,31 +5285,31 @@ procfs_stopped_by_watchpoint (int pid)
* Function: procfs_find_LDT_entry
*
* Input:
- * int pid; // The GDB-style pid-plus-LWP.
+ * ptid_t ptid; // The GDB-style pid-plus-LWP.
*
* Return:
* pointer to the corresponding LDT entry.
*/
struct ssd *
-procfs_find_LDT_entry (int pid)
+procfs_find_LDT_entry (ptid_t ptid)
{
gdb_gregset_t *gregs;
int key;
procinfo *pi;
/* Find procinfo for the lwp. */
- if ((pi = find_procinfo (PIDGET (pid), TIDGET (pid))) == NULL)
+ if ((pi = find_procinfo (PIDGET (ptid), TIDGET (ptid))) == NULL)
{
- warning ("procfs_find_LDT_entry: could not find procinfi for %d.",
- pid);
+ warning ("procfs_find_LDT_entry: could not find procinfo for %d:%d.",
+ PIDGET (ptid), TIDGET (ptid));
return NULL;
}
/* get its general registers. */
if ((gregs = proc_get_gregs (pi)) == NULL)
{
- warning ("procfs_find_LDT_entry: could not read gregs for %d.",
- pid);
+ warning ("procfs_find_LDT_entry: could not read gregs for %d:%d.",
+ PIDGET (ptid), TIDGET (ptid));
return NULL;
}
/* Now extract the GS register's lower 16 bits. */
@@ -5353,7 +5360,7 @@ info_proc_cmd (char *args, int from_tty)
argv++;
}
if (pid == 0)
- pid = PIDGET (inferior_pid);
+ pid = PIDGET (inferior_ptid);
if (pid == 0)
error ("No current process: you must name one.");
else
@@ -5402,13 +5409,13 @@ proc_trace_syscalls (char *args, int from_tty, int entry_or_exit, int mode)
sysset_t *sysset;
int syscallnum = 0;
- if (inferior_pid <= 0)
+ if (PIDGET (inferior_ptid) <= 0)
error ("you must be debugging a process to use this command.");
if (args == NULL || args[0] == 0)
error_no_arg ("system call to trace");
- pi = find_procinfo_or_die (PIDGET (inferior_pid), 0);
+ pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
if (isdigit (args[0]))
{
syscallnum = atoi (args);
@@ -5495,11 +5502,8 @@ Default is the process being debugged.");
* we will be able to find a 'live' procinfo.
*/
-int
+ptid_t
procfs_first_available (void)
{
- if (procinfo_list)
- return procinfo_list->pid;
- else
- return -1;
+ return pid_to_ptid (procinfo_list ? procinfo_list->pid : -1);
}