* [5/7] procfs (solaris, iris, osf, unixware, aix5)
@ 2008-08-08 1:37 Pedro Alves
2008-08-15 17:38 ` Daniel Jacobowitz
0 siblings, 1 reply; 4+ messages in thread
From: Pedro Alves @ 2008-08-08 1:37 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1454 bytes --]
This patch adjusts the procfs target, so that it registers the main thread in
GDB's thread table.
The biggest change here is, that on a single-threaded inferior,
we would set inferior_ptid as:
/* The 'process ID' we return to GDB is composed of the actual
process ID plus the lwp ID. */
... but, we'd not store the lwp id of the main lwp/process' in its
procinfo (a target private structure holding info about lwps).
If we always add the main thread to GDB's thread table, we should
also keep the lwpid of the main thread around. The current
code assumes that a procfind with tid == 0 represents the main
process. To be able to still store a valid tid for the main
process, I added a new main_proc flag to struct procinfo, and
use that instead of relying on tid == 0.
Always adding the main thread actually uncovered a bug in
the sol-thread.c. The sol_thread_active flag wasn't being
reset, which means that a second time we started an inferior,
and we added its main thread to GDB's tables, and this new inferior
hasn't loaded pthread support, sol_thread_create_inferior and
sol_thread_attach would still try to get info on this thread,
and fail. The second run should just behave the same as the
first.
Tested on i386-pc-solaris2.11 (OpenSolaris 10), with all the
stty trouble I've had, but still, adding the manual testing
I've done, I think I managed to get good coverage.
This patch depends only on patch 1.
OK?
--
Pedro Alves
[-- Attachment #2: 005-procfs_always_a_thread.diff --]
[-- Type: text/x-diff, Size: 19933 bytes --]
2008-08-08 Pedro Alves <pedro@codesourcery.com>
* procfs.c (struct procinfo): Add main_proc member.
(find_procinfo): Adjust for the main process having a tid member
as well.
(open_procinfo_files): Check for the main process with main_proc,
instead of checking for tid being 0.
(create_procinfo): If tid is 0, mark this proc as the main
process.
(destroy_procinfo, proc_get_status, proc_wait_for_stop)
(proc_set_traced_signals, proc_set_traced_sysentry)
(proc_set_traced_sysexit, proc_set_held_signals)
(proc_get_pending_signals, proc_get_signal_actions)
(proc_get_held_signals, proc_get_traced_signals)
(proc_trace_signal, proc_ignore_signal, proc_get_traced_faults)
(proc_get_traced_sysentry, proc_get_traced_sysexit)
(proc_clear_current_fault, proc_set_current_signal)
(proc_clear_current_signal, proc_get_fpregs, proc_set_fpregs)
(proc_parent_pid, proc_get_nthreads, proc_get_current_thread)
(proc_update_threads, proc_iterate_over_threads, procfs_attach):
Check for the main process with main_proc, instead of checking for
tid being 0.
(procfs_fetch_registers, procfs_store_registers): Remove special
handling of the main proc.
(procfs_resume): Check for the main process with main_proc,
instead of checking for tid being 0.
(procfs_init_inferior): Set the tid member on the main process as
well. Change the main thread ptid with thread_change_ptid.
(procfs_notice_thread): Check for exited threads.
* sol-thread.c (sol_thread_attach): Clear sol_thread_active before
attaching. Change the main thread ptid with thread_change_ptid.
(sol_thread_detach): Clear sol_thread_active.
(sol_thread_wait): Check for exited threads.
(sol_thread_create_inferior): Clear sol_thread_active before
creating a new inferior. Change the main thread ptid with
thread_change_ptid.
(sol_thread_mourn_inferior): Clear sol_thread_active.
(sol_find_new_threads_callback): Check for exited threads.
---
gdb/procfs.c | 132 +++++++++++++++++++++++++++----------------------------
gdb/sol-thread.c | 33 +++++++------
2 files changed, 84 insertions(+), 81 deletions(-)
Index: src/gdb/procfs.c
===================================================================
--- src.orig/gdb/procfs.c 2008-08-07 22:53:44.000000000 +0100
+++ src/gdb/procfs.c 2008-08-07 22:53:58.000000000 +0100
@@ -426,6 +426,8 @@ typedef struct procinfo {
int gregs_valid : 1;
int fpregs_valid : 1;
int threads_valid: 1;
+
+ int main_proc: 1; /* is this lwp the main process? */
} procinfo;
static char errmsg[128]; /* shared error msg buffer */
@@ -478,9 +480,13 @@ find_procinfo (int pid, int tid)
calling find_procinfo, if the caller wants to find a new
thread. */
- for (pi = pi->thread_list; pi; pi = pi->next)
- if (pi->tid == tid)
- break;
+ if (pi->tid == tid)
+ /* This is the main lwp, we're done. */
+ ;
+ else
+ for (pi = pi->thread_list; pi; pi = pi->next)
+ if (pi->tid == tid)
+ break;
}
return pi;
@@ -623,17 +629,17 @@ open_procinfo_files (procinfo *pi, int w
strcpy (tmp, pi->pathname);
switch (which) { /* which file descriptor to open? */
case FD_CTL:
- if (pi->tid)
- strcat (tmp, "/lwpctl");
- else
+ if (pi->main_proc)
strcat (tmp, "/ctl");
+ else
+ strcat (tmp, "/lwpctl");
fd = open_with_retry (tmp, O_WRONLY);
if (fd <= 0)
return 0; /* fail */
pi->ctl_fd = fd;
break;
case FD_AS:
- if (pi->tid)
+ if (!pi->main_proc)
return 0; /* there is no 'as' file descriptor for an lwp */
strcat (tmp, "/as");
fd = open_with_retry (tmp, O_RDWR);
@@ -642,10 +648,10 @@ open_procinfo_files (procinfo *pi, int w
pi->as_fd = fd;
break;
case FD_STATUS:
- if (pi->tid)
- strcat (tmp, "/lwpstatus");
- else
+ if (pi->main_proc)
strcat (tmp, "/status");
+ else
+ strcat (tmp, "/lwpstatus");
fd = open_with_retry (tmp, O_RDONLY);
if (fd <= 0)
return 0; /* fail */
@@ -674,7 +680,7 @@ open_procinfo_files (procinfo *pi, int w
if ((fd = open_with_retry (pi->pathname, O_RDWR)) == 0)
return 0;
#else /* Sol 2.5, Irix, other? */
- if (pi->tid == 0) /* Master procinfo for the process */
+ if (pi->main_proc) /* Master procinfo for the process */
{
fd = open_with_retry (pi->pathname, O_RDWR);
if (fd <= 0)
@@ -732,6 +738,10 @@ create_procinfo (int pid, int tid)
pi->pid = pid;
pi->tid = tid;
+ /* We'll update the tid field later, and we need to remember this is
+ the main proc. */
+ pi->main_proc = (pi->tid == 0);
+
#ifdef DYNAMIC_SYSCALLS
load_syscalls (pi);
#endif
@@ -740,7 +750,7 @@ create_procinfo (int pid, int tid)
pi->saved_exitset = sysset_t_alloc (pi);
/* Chain into list. */
- if (tid == 0)
+ if (pi->main_proc)
{
sprintf (pi->pathname, MAIN_PROC_NAME_FMT, pid);
pi->next = procinfo_list;
@@ -818,7 +828,7 @@ destroy_procinfo (procinfo *pi)
{
procinfo *tmp;
- if (pi->tid != 0) /* destroy a thread procinfo */
+ if (!pi->main_proc) /* destroy a thread procinfo */
{
tmp = find_procinfo (pi->pid, 0); /* find the parent process */
destroy_one_procinfo (&tmp->thread_list, pi);
@@ -1162,7 +1172,7 @@ proc_get_status (procinfo *pi)
{
/* Sigh... I have to read a different data structure,
depending on whether this is a main process or an LWP. */
- if (pi->tid)
+ if (!pi->main_proc)
pi->status_valid = (read (pi->status_fd,
(char *) &pi->prstatus.pr_lwp,
sizeof (lwpstatus_t))
@@ -1187,7 +1197,7 @@ proc_get_status (procinfo *pi)
}
#else /* ioctl method */
#ifdef PIOCTSTATUS /* osf */
- if (pi->tid == 0) /* main process */
+ if (pi->main_proc)
{
/* Just read the danged status. Now isn't that simple? */
pi->status_valid =
@@ -1434,7 +1444,7 @@ proc_modify_flag (procinfo *pi, long fla
* unnecessarily.
*/
- if (pi->pid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef NEW_PROC_API /* Newest method: UnixWare and newer Solarii */
@@ -1713,7 +1723,7 @@ proc_wait_for_stop (procinfo *pi)
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef NEW_PROC_API
@@ -1830,7 +1840,7 @@ proc_set_traced_signals (procinfo *pi, g
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef NEW_PROC_API
@@ -1876,7 +1886,7 @@ proc_set_traced_faults (procinfo *pi, fl
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef NEW_PROC_API
@@ -1920,7 +1930,7 @@ proc_set_traced_sysentry (procinfo *pi,
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef NEW_PROC_API
@@ -1970,7 +1980,7 @@ proc_set_traced_sysexit (procinfo *pi, s
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef NEW_PROC_API
@@ -2020,7 +2030,7 @@ proc_set_held_signals (procinfo *pi, gdb
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef NEW_PROC_API
@@ -2063,7 +2073,7 @@ proc_get_pending_signals (procinfo *pi,
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
if (!pi->status_valid)
@@ -2100,7 +2110,7 @@ proc_get_signal_actions (procinfo *pi, g
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
if (!pi->status_valid)
@@ -2137,7 +2147,7 @@ proc_get_held_signals (procinfo *pi, gdb
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef NEW_PROC_API
@@ -2183,7 +2193,7 @@ proc_get_traced_signals (procinfo *pi, g
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef NEW_PROC_API
@@ -2225,7 +2235,7 @@ proc_trace_signal (procinfo *pi, int sig
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
if (pi)
@@ -2259,7 +2269,7 @@ proc_ignore_signal (procinfo *pi, int si
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
if (pi)
@@ -2293,7 +2303,7 @@ proc_get_traced_faults (procinfo *pi, fl
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef NEW_PROC_API
@@ -2335,7 +2345,7 @@ proc_get_traced_sysentry (procinfo *pi,
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef NEW_PROC_API
@@ -2408,7 +2418,7 @@ proc_get_traced_sysexit (procinfo *pi, s
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef NEW_PROC_API
@@ -2481,7 +2491,7 @@ proc_clear_current_fault (procinfo *pi)
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef NEW_PROC_API
@@ -2529,7 +2539,7 @@ proc_set_current_signal (procinfo *pi, i
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef PROCFS_DONT_PIOCSSIG_CURSIG
@@ -2600,7 +2610,7 @@ proc_clear_current_signal (procinfo *pi)
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#ifdef NEW_PROC_API
@@ -2692,13 +2702,13 @@ proc_get_fpregs (procinfo *pi)
thread_fpregs.pr_count = 1;
thread_fpregs.thread_1.tid = pi->tid;
- if (pi->tid == 0
+ if (pi->main_proc
&& ioctl (pi->ctl_fd, PIOCGFPREG, &pi->fpregset) >= 0)
{
pi->fpregs_valid = 1;
return &pi->fpregset; /* Got 'em now! */
}
- else if (pi->tid != 0
+ else if (!pi->main_proc
&& ioctl (pi->ctl_fd, PIOCTGFPREG, &thread_fpregs) >= 0)
{
memcpy (&pi->fpregset, &thread_fpregs.thread_1.pr_fpregs,
@@ -2798,7 +2808,7 @@ proc_set_fpregs (procinfo *pi)
win = (write (pi->ctl_fd, (void *) &arg, sizeof (arg)) == sizeof (arg));
#else
# ifdef PIOCTSFPREG
- if (pi->tid == 0)
+ if (pi->main_proc)
win = (ioctl (pi->ctl_fd, PIOCSFPREG, fpregs) >= 0);
else
{
@@ -2882,7 +2892,7 @@ proc_parent_pid (procinfo *pi)
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
if (!pi->status_valid)
@@ -3130,7 +3140,7 @@ proc_get_nthreads (procinfo *pi)
* because the LWP procinfos do not get prstatus filled in.
*/
#ifdef NEW_PROC_API
- if (pi->tid != 0) /* find the parent process procinfo */
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
#endif
return pi->prstatus.pr_nlwp;
@@ -3171,7 +3181,7 @@ proc_get_current_thread (procinfo *pi)
* find the parent process procinfo.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
if (!pi->status_valid)
@@ -3255,7 +3265,7 @@ proc_update_threads (procinfo *pi)
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
proc_iterate_over_threads (pi, proc_delete_dead_threads, NULL);
@@ -3310,7 +3320,7 @@ proc_update_threads (procinfo *pi)
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
proc_iterate_over_threads (pi, proc_delete_dead_threads, NULL);
@@ -3360,7 +3370,7 @@ proc_update_threads (procinfo *pi)
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
proc_iterate_over_threads (pi, proc_delete_dead_threads, NULL);
@@ -3434,7 +3444,7 @@ proc_iterate_over_threads (procinfo *pi,
* replace it with one that makes sure the ctl_fd is open.
*/
- if (pi->tid != 0)
+ if (!pi->main_proc)
pi = find_procinfo_or_die (pi->pid, 0);
for (thread = pi->thread_list; thread != NULL; thread = next)
@@ -3628,6 +3638,8 @@ procfs_attach (char *args, int from_tty)
fflush (stdout);
}
inferior_ptid = do_attach (pid_to_ptid (pid));
+ add_thread_silent (inferior_ptid);
+
push_target (&procfs_ops);
}
@@ -3784,14 +3796,7 @@ procfs_fetch_registers (struct regcache
int tid = TIDGET (inferior_ptid);
struct gdbarch *gdbarch = get_regcache_arch (regcache);
- /* 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_ptid), then look up procinfo for the requested
- thread. */
- if (tid != 0 && tid != proc_get_current_thread (pi))
- pi = find_procinfo_or_die (pid, tid);
+ pi = find_procinfo_or_die (pid, tid);
if (pi == NULL)
error (_("procfs: fetch_registers failed to find procinfo for %s"),
@@ -3850,14 +3855,7 @@ procfs_store_registers (struct regcache
int tid = TIDGET (inferior_ptid);
struct gdbarch *gdbarch = get_regcache_arch (regcache);
- /* First find procinfo for main process. */
- pi = find_procinfo_or_die (pid, 0);
-
- /* If the event thread is not the same as GDB's requested thread
- (ie. inferior_ptid), then look up procinfo for the requested
- thread. */
- if (tid != 0 && tid != proc_get_current_thread (pi))
- pi = find_procinfo_or_die (pid, tid);
+ pi = find_procinfo_or_die (pid, tid);
if (pi == NULL)
error (_("procfs: store_registers: failed to find procinfo for %s"),
@@ -4621,7 +4619,7 @@ procfs_resume (ptid_t ptid, int step, en
thread = find_procinfo (PIDGET (ptid), TIDGET (ptid));
if (thread != NULL)
{
- if (thread->tid != 0)
+ if (!thread->main_proc)
{
/* We're to resume a specific thread, and not the others.
* Set the child process's PR_ASYNC flag.
@@ -4951,9 +4949,11 @@ procfs_init_inferior (int pid)
if (!proc_set_run_on_last_close (pi))
proc_error (pi, "init_inferior, set_RLC", __LINE__);
- /* The 'process ID' we return to GDB is composed of
- the actual process ID plus the lwp ID. */
- inferior_ptid = MERGEPID (pi->pid, proc_get_current_thread (pi));
+ /* The 'process ID' we return to GDB is composed of the actual
+ process ID plus the lwp ID. */
+ pi->tid = proc_get_current_thread (pi);
+ thread_change_ptid (inferior_ptid,
+ MERGEPID (pi->pid, pi->tid));
/* Typically two, one trap to exec the shell, one to exec the
program being debugged. Defined by "inferior.h". */
@@ -5212,7 +5212,7 @@ procfs_notice_thread (procinfo *pi, proc
{
ptid_t gdb_threadid = MERGEPID (pi->pid, thread->tid);
- if (!in_thread_list (gdb_threadid))
+ if (!in_thread_list (gdb_threadid) || is_exited (gdb_threadid))
add_thread (gdb_threadid);
return 0;
@@ -6105,7 +6105,7 @@ procfs_corefile_thread_callback (procinf
{
struct procfs_corefile_thread_data *args = data;
- if (pi != NULL && thread->tid != 0)
+ if (pi != NULL && !thread->main_proc)
{
ptid_t saved_ptid = inferior_ptid;
inferior_ptid = MERGEPID (pi->pid, thread->tid);
Index: src/gdb/sol-thread.c
===================================================================
--- src.orig/gdb/sol-thread.c 2008-08-07 22:53:42.000000000 +0100
+++ src/gdb/sol-thread.c 2008-08-07 22:53:58.000000000 +0100
@@ -253,7 +253,7 @@ td_state_string (td_thr_state_e statecod
/* Convert a POSIX or Solaris thread ID into a LWP ID. If THREAD_ID
doesn't exist, that's an error. If it's an inactive thread, return
- DEFAULT_LPW.
+ DEFAULT_LWP.
NOTE: This function probably shouldn't call error(). */
@@ -350,6 +350,7 @@ sol_thread_open (char *arg, int from_tty
static void
sol_thread_attach (char *args, int from_tty)
{
+ sol_thread_active = 0;
procfs_ops.to_attach (args, from_tty);
/* Must get symbols from shared libraries before libthread_db can run! */
@@ -357,14 +358,13 @@ sol_thread_attach (char *args, int from_
if (sol_thread_active)
{
+ ptid_t ptid;
printf_filtered ("sol-thread active.\n");
main_ph.ptid = inferior_ptid; /* Save for xfer_memory. */
push_target (&sol_thread_ops);
- inferior_ptid = lwp_to_thread (inferior_ptid);
- if (PIDGET (inferior_ptid) == -1)
- inferior_ptid = main_ph.ptid;
- else
- add_thread (inferior_ptid);
+ ptid = lwp_to_thread (inferior_ptid);
+ if (PIDGET (ptid) != -1)
+ thread_change_ptid (inferior_ptid, ptid);
}
/* FIXME: Might want to iterate over all the threads and register
@@ -381,6 +381,7 @@ sol_thread_attach (char *args, int from_
static void
sol_thread_detach (char *args, int from_tty)
{
+ sol_thread_active = 0;
inferior_ptid = pid_to_ptid (PIDGET (main_ph.ptid));
unpush_target (&sol_thread_ops);
procfs_ops.to_detach (args, from_tty);
@@ -419,7 +420,7 @@ sol_thread_resume (ptid_t ptid, int step
do_cleanups (old_chain);
}
-/* Wait for any threads to stop. We may have to convert PIID from a
+/* Wait for any threads to stop. We may have to convert PTID from a
thread ID to an LWP ID, and vice versa on the way out. */
static ptid_t
@@ -460,7 +461,8 @@ sol_thread_wait (ptid_t ptid, struct tar
/* See if we have a new thread. */
if (is_thread (rtnval)
&& !ptid_equal (rtnval, save_ptid)
- && !in_thread_list (rtnval))
+ && (!in_thread_list (rtnval)
+ || is_exited (rtnval)))
add_thread (rtnval);
}
@@ -754,21 +756,21 @@ static void
sol_thread_create_inferior (char *exec_file, char *allargs, char **env,
int from_tty)
{
+ sol_thread_active = 0;
procfs_ops.to_create_inferior (exec_file, allargs, env, from_tty);
if (sol_thread_active && !ptid_equal (inferior_ptid, null_ptid))
{
+ ptid_t ptid;
+
/* Save for xfer_memory. */
main_ph.ptid = inferior_ptid;
push_target (&sol_thread_ops);
- inferior_ptid = lwp_to_thread (inferior_ptid);
- if (PIDGET (inferior_ptid) == -1)
- inferior_ptid = main_ph.ptid;
-
- if (!in_thread_list (inferior_ptid))
- add_thread (inferior_ptid);
+ ptid = lwp_to_thread (inferior_ptid);
+ if (PIDGET (ptid) != -1)
+ thread_change_ptid (inferior_ptid, ptid);
}
}
@@ -822,6 +824,7 @@ sol_thread_new_objfile (struct objfile *
static void
sol_thread_mourn_inferior (void)
{
+ sol_thread_active = 0;
unpush_target (&sol_thread_ops);
procfs_ops.to_mourn_inferior ();
}
@@ -1366,7 +1369,7 @@ sol_find_new_threads_callback (const td_
return -1;
ptid = BUILD_THREAD (ti.ti_tid, PIDGET (inferior_ptid));
- if (!in_thread_list (ptid))
+ if (!in_thread_list (ptid) || is_exited (ptid))
add_thread (ptid);
return 0;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [5/7] procfs (solaris, iris, osf, unixware, aix5)
2008-08-08 1:37 [5/7] procfs (solaris, iris, osf, unixware, aix5) Pedro Alves
@ 2008-08-15 17:38 ` Daniel Jacobowitz
2008-08-15 19:19 ` Pedro Alves
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Jacobowitz @ 2008-08-15 17:38 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
On Fri, Aug 08, 2008 at 02:37:57AM +0100, Pedro Alves wrote:
> This patch adjusts the procfs target, so that it registers the main thread in
> GDB's thread table.
This looks OK to me (took me a couple of tries to convince myself it
was right, but I'm convinced now).
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [5/7] procfs (solaris, iris, osf, unixware, aix5)
2008-08-15 17:38 ` Daniel Jacobowitz
@ 2008-08-15 19:19 ` Pedro Alves
2008-08-16 20:13 ` Daniel Jacobowitz
0 siblings, 1 reply; 4+ messages in thread
From: Pedro Alves @ 2008-08-15 19:19 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 2168 bytes --]
On Friday 15 August 2008 18:37:31, Daniel Jacobowitz wrote:
> On Fri, Aug 08, 2008 at 02:37:57AM +0100, Pedro Alves wrote:
> > This patch adjusts the procfs target, so that it registers the main
> > thread in GDB's thread table.
>
> This looks OK to me (took me a couple of tries to convince myself it
> was right, but I'm convinced now).
I'm sorry to had convinced you wrong. :-(
I noticed that before, when we went multi-threaded, we would keep
the main process listed with proc->tid == 0, and we would just
create a new procinfo for the main lwp, which is a little
redundant, but indeed simplifies things.
procfs_wait:
/* 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_ptid yet.
*/
if (TIDGET (inferior_ptid) != 0)
{
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));
}
If I instead do that right on target_create_inferior and target_attach,
we're done -- there's always a thread, and there's always a procinfo for
it too.
You asked me on IRC if the main lwp is also available in
the /proc tree, and although I somehow missed it, indeed it is there.
Here, 5642 is a single-threaded app:
pedro@opensolaris:~/orlando/gdb/baseline/build-solaris/gdb$ ls /proc/5642/lwp/
1
Here, 5613 is a multi-threaded app:
pedro@opensolaris:~/orlando/gdb/baseline/build-solaris/gdb$ ls /proc/5613/lwp/
1 2 3
We still have to use the main process procinfo entry, to get at
/proc/<pid>/map /proc/<pid>/as, because as expected, those are
not found under the lwp/1 directory:
pedro@opensolaris:~/orlando/gdb/baseline/build-solaris/gdb$ ls /proc/5613/lwp/1/
lwpctl lwpsinfo lwpstatus lwpusage templates xregs
My previous path had broken creating core dumps in multi-threaded apps,
as iterating over thread procinfo's would miss the main process.
Please find attached a new patch. This one's much simpler.
Only procfs.c changed.
--
Pedro Alves
[-- Attachment #2: 005-procfs_always_a_thread.diff --]
[-- Type: text/x-diff, Size: 10159 bytes --]
2008-08-15 Pedro Alves <pedro@codesourcery.com>
* procfs.c (to_attach): Create a procinfo for the current lwp.
Add it to gdb's thread list.
(procfs_fetch_registers, procfs_store_registers): Assume there's
always an lwp.
(procfs_wait): And add the main thread here.
(procfs_init_inferior): Create a procinfo for the main lwp here.
Change main thread's ptid with thread_change_ptid.
(procfs_notice_thread): Check for exited threads.
(procfs_corefile_thread_callback): Remote check for the main
process.
(procfs_make_note_section): Assume there is always a thread.
* sol-thread.c (sol_thread_attach): Clear sol_thread_active before
attaching. Change the main thread ptid with thread_change_ptid.
(sol_thread_detach): Clear sol_thread_active.
(sol_thread_wait): Check for exited threads.
(sol_thread_create_inferior): Clear sol_thread_active before
creating a new inferior. Change the main thread ptid with
thread_change_ptid.
(sol_thread_mourn_inferior): Clear sol_thread_active.
(sol_find_new_threads_callback): Check for exited threads.
---
gdb/procfs.c | 77 +++++++++++++++++++++----------------------------------
gdb/sol-thread.c | 33 ++++++++++++-----------
2 files changed, 48 insertions(+), 62 deletions(-)
Index: src/gdb/procfs.c
===================================================================
--- src.orig/gdb/procfs.c 2008-08-15 18:30:05.000000000 +0100
+++ src/gdb/procfs.c 2008-08-15 19:32:41.000000000 +0100
@@ -3664,6 +3664,7 @@ do_attach (ptid_t ptid)
{
procinfo *pi;
int fail;
+ int lwpid;
if ((pi = create_procinfo (PIDGET (ptid), 0)) == NULL)
perror (_("procfs: out of memory in 'attach'"));
@@ -3713,7 +3714,16 @@ do_attach (ptid_t ptid)
/* Let GDB know that the inferior was attached. */
attach_flag = 1;
- return MERGEPID (pi->pid, proc_get_current_thread (pi));
+
+ /* Create a procinfo for the current lwp. */
+ lwpid = proc_get_current_thread (pi);
+ create_procinfo (pi->pid, lwpid);
+
+ /* Add it to gdb's thread list. */
+ ptid = MERGEPID (pi->pid, lwpid);
+ add_thread (ptid);
+
+ return ptid;
}
static void
@@ -3784,14 +3794,7 @@ procfs_fetch_registers (struct regcache
int tid = TIDGET (inferior_ptid);
struct gdbarch *gdbarch = get_regcache_arch (regcache);
- /* 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_ptid), then look up procinfo for the requested
- thread. */
- if (tid != 0 && tid != proc_get_current_thread (pi))
- pi = find_procinfo_or_die (pid, tid);
+ pi = find_procinfo_or_die (pid, tid);
if (pi == NULL)
error (_("procfs: fetch_registers failed to find procinfo for %s"),
@@ -3850,14 +3853,7 @@ procfs_store_registers (struct regcache
int tid = TIDGET (inferior_ptid);
struct gdbarch *gdbarch = get_regcache_arch (regcache);
- /* First find procinfo for main process. */
- pi = find_procinfo_or_die (pid, 0);
-
- /* If the event thread is not the same as GDB's requested thread
- (ie. inferior_ptid), then look up procinfo for the requested
- thread. */
- if (tid != 0 && tid != proc_get_current_thread (pi))
- pi = find_procinfo_or_die (pid, tid);
+ pi = find_procinfo_or_die (pid, tid);
if (pi == NULL)
error (_("procfs: store_registers: failed to find procinfo for %s"),
@@ -4350,20 +4346,6 @@ wait_again:
add_thread (retval);
if (find_procinfo (PIDGET (retval), TIDGET (retval)) == NULL)
create_procinfo (PIDGET (retval), TIDGET (retval));
-
- /* 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_ptid yet.
- */
- if (TIDGET (inferior_ptid) != 0)
- {
- 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));
- }
}
}
else /* flags do not indicate STOPPED */
@@ -4891,6 +4873,7 @@ procfs_init_inferior (int pid)
procinfo *pi;
gdb_sigset_t signals;
int fail;
+ int lwpid;
/* This routine called on the parent side (GDB side)
after GDB forks the inferior. */
@@ -4951,9 +4934,17 @@ procfs_init_inferior (int pid)
if (!proc_set_run_on_last_close (pi))
proc_error (pi, "init_inferior, set_RLC", __LINE__);
- /* The 'process ID' we return to GDB is composed of
- the actual process ID plus the lwp ID. */
- inferior_ptid = MERGEPID (pi->pid, proc_get_current_thread (pi));
+ /* We now have have access to the lwpid of the main thread/lwp. */
+ lwpid = proc_get_current_thread (pi);
+
+ /* Create a procinfo for the main lwp. */
+ create_procinfo (pid, lwpid);
+
+ /* We already have a main thread registered in the thread table at
+ this point, but it didn't have any lwp info yet. Notify the core
+ about it. This changes inferior_ptid as well. */
+ thread_change_ptid (pid_to_ptid (pid),
+ MERGEPID (pid, lwpid));
/* Typically two, one trap to exec the shell, one to exec the
program being debugged. Defined by "inferior.h". */
@@ -5212,7 +5203,7 @@ procfs_notice_thread (procinfo *pi, proc
{
ptid_t gdb_threadid = MERGEPID (pi->pid, thread->tid);
- if (!in_thread_list (gdb_threadid))
+ if (!in_thread_list (gdb_threadid) || is_exited (gdb_threadid))
add_thread (gdb_threadid);
return 0;
@@ -6105,7 +6096,7 @@ procfs_corefile_thread_callback (procinf
{
struct procfs_corefile_thread_data *args = data;
- if (pi != NULL && thread->tid != 0)
+ if (pi != NULL)
{
ptid_t saved_ptid = inferior_ptid;
inferior_ptid = MERGEPID (pi->pid, thread->tid);
@@ -6167,17 +6158,9 @@ procfs_make_note_section (bfd *obfd, int
thread_args.note_size = note_size;
proc_iterate_over_threads (pi, procfs_corefile_thread_callback, &thread_args);
- if (thread_args.note_data == note_data)
- {
- /* iterate_over_threads didn't come up with any threads;
- just use inferior_ptid. */
- note_data = procfs_do_thread_registers (obfd, inferior_ptid,
- note_data, note_size);
- }
- else
- {
- note_data = thread_args.note_data;
- }
+ /* There should be always at least one thread. */
+ gdb_assert (thread_args.note_data != note_data);
+ note_data = thread_args.note_data;
auxv_len = target_read_alloc (¤t_target, TARGET_OBJECT_AUXV,
NULL, &auxv);
Index: src/gdb/sol-thread.c
===================================================================
--- src.orig/gdb/sol-thread.c 2008-08-15 18:30:05.000000000 +0100
+++ src/gdb/sol-thread.c 2008-08-15 19:53:22.000000000 +0100
@@ -253,7 +253,7 @@ td_state_string (td_thr_state_e statecod
/* Convert a POSIX or Solaris thread ID into a LWP ID. If THREAD_ID
doesn't exist, that's an error. If it's an inactive thread, return
- DEFAULT_LPW.
+ DEFAULT_LWP.
NOTE: This function probably shouldn't call error(). */
@@ -350,6 +350,7 @@ sol_thread_open (char *arg, int from_tty
static void
sol_thread_attach (char *args, int from_tty)
{
+ sol_thread_active = 0;
procfs_ops.to_attach (args, from_tty);
/* Must get symbols from shared libraries before libthread_db can run! */
@@ -357,14 +358,13 @@ sol_thread_attach (char *args, int from_
if (sol_thread_active)
{
+ ptid_t ptid;
printf_filtered ("sol-thread active.\n");
main_ph.ptid = inferior_ptid; /* Save for xfer_memory. */
push_target (&sol_thread_ops);
- inferior_ptid = lwp_to_thread (inferior_ptid);
- if (PIDGET (inferior_ptid) == -1)
- inferior_ptid = main_ph.ptid;
- else
- add_thread (inferior_ptid);
+ ptid = lwp_to_thread (inferior_ptid);
+ if (PIDGET (ptid) != -1)
+ thread_change_ptid (inferior_ptid, ptid);
}
/* FIXME: Might want to iterate over all the threads and register
@@ -381,6 +381,7 @@ sol_thread_attach (char *args, int from_
static void
sol_thread_detach (char *args, int from_tty)
{
+ sol_thread_active = 0;
inferior_ptid = pid_to_ptid (PIDGET (main_ph.ptid));
unpush_target (&sol_thread_ops);
procfs_ops.to_detach (args, from_tty);
@@ -419,7 +420,7 @@ sol_thread_resume (ptid_t ptid, int step
do_cleanups (old_chain);
}
-/* Wait for any threads to stop. We may have to convert PIID from a
+/* Wait for any threads to stop. We may have to convert PTID from a
thread ID to an LWP ID, and vice versa on the way out. */
static ptid_t
@@ -460,7 +461,8 @@ sol_thread_wait (ptid_t ptid, struct tar
/* See if we have a new thread. */
if (is_thread (rtnval)
&& !ptid_equal (rtnval, save_ptid)
- && !in_thread_list (rtnval))
+ && (!in_thread_list (rtnval)
+ || is_exited (rtnval)))
add_thread (rtnval);
}
@@ -754,21 +756,21 @@ static void
sol_thread_create_inferior (char *exec_file, char *allargs, char **env,
int from_tty)
{
+ sol_thread_active = 0;
procfs_ops.to_create_inferior (exec_file, allargs, env, from_tty);
if (sol_thread_active && !ptid_equal (inferior_ptid, null_ptid))
{
+ ptid_t ptid;
+
/* Save for xfer_memory. */
main_ph.ptid = inferior_ptid;
push_target (&sol_thread_ops);
- inferior_ptid = lwp_to_thread (inferior_ptid);
- if (PIDGET (inferior_ptid) == -1)
- inferior_ptid = main_ph.ptid;
-
- if (!in_thread_list (inferior_ptid))
- add_thread (inferior_ptid);
+ ptid = lwp_to_thread (inferior_ptid);
+ if (PIDGET (ptid) != -1)
+ thread_change_ptid (inferior_ptid, ptid);
}
}
@@ -822,6 +824,7 @@ sol_thread_new_objfile (struct objfile *
static void
sol_thread_mourn_inferior (void)
{
+ sol_thread_active = 0;
unpush_target (&sol_thread_ops);
procfs_ops.to_mourn_inferior ();
}
@@ -1366,7 +1369,7 @@ sol_find_new_threads_callback (const td_
return -1;
ptid = BUILD_THREAD (ti.ti_tid, PIDGET (inferior_ptid));
- if (!in_thread_list (ptid))
+ if (!in_thread_list (ptid) || is_exited (ptid))
add_thread (ptid);
return 0;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [5/7] procfs (solaris, iris, osf, unixware, aix5)
2008-08-15 19:19 ` Pedro Alves
@ 2008-08-16 20:13 ` Daniel Jacobowitz
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 2008-08-16 20:13 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
On Fri, Aug 15, 2008 at 08:19:15PM +0100, Pedro Alves wrote:
> Please find attached a new patch. This one's much simpler.
I like this one better, too. Thanks, this is OK.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-08-16 20:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-08 1:37 [5/7] procfs (solaris, iris, osf, unixware, aix5) Pedro Alves
2008-08-15 17:38 ` Daniel Jacobowitz
2008-08-15 19:19 ` Pedro Alves
2008-08-16 20:13 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox