aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbserver/thread-db.c
diff options
context:
space:
mode:
authorDaniel Jacobowitz <drow@false.org>2007-10-23 20:05:03 +0000
committerDaniel Jacobowitz <drow@false.org>2007-10-23 20:05:03 +0000
commit24a09b5f373c09e5cb56523e6fcb76e81bcd4784 (patch)
tree4fa03e2bad677d365b5a0641e2c8eb6b5e63e8ac /gdb/gdbserver/thread-db.c
parent3d5f6d122ed686b9a568cafddc3d298c10180248 (diff)
downloadgdb-24a09b5f373c09e5cb56523e6fcb76e81bcd4784.zip
gdb-24a09b5f373c09e5cb56523e6fcb76e81bcd4784.tar.gz
gdb-24a09b5f373c09e5cb56523e6fcb76e81bcd4784.tar.bz2
* inferiors.c (change_inferior_id): Delete.
(add_pid_to_list, pull_pid_from_list): New. * linux-low.c (PTRACE_SETOPTIONS, PTRACE_GETEVENTMSG) (PTRACE_O_TRACESYSGOOD, PTRACE_O_TRACEFORK, PTRACE_O_TRACEVFORK) (PTRACE_O_TRACECLONE, PTRACE_O_TRACEEXEC, PTRACE_O_TRACEVFORKDONE) (PTRACE_O_TRACEEXIT, PTRACE_EVENT_FORK, PTRACE_EVENT_VFORK) (PTRACE_EVENT_CLONE, PTRACE_EVENT_EXEC, PTRACE_EVENT_VFORK_DONE) (PTRACE_EVENT_EXIT, __WALL): Provide default definitions. (stopped_pids, thread_db_active, must_set_ptrace_flags): New variables. (using_threads): Always set to 1. (handle_extended_wait): New. (add_process): Do not set TID. (linux_create_inferior): Set must_set_ptrace_flags. (linux_attach_lwp): Remove TID argument. Do not check using_threads. Use PTRACE_SETOPTIONS. Call new_thread_notify. Update all callers. (linux_thread_alive): Rename TID argument to LWPID. (linux_wait_for_process): Handle unknown processes. Do not use TID. (linux_wait_for_event): Do not use TID or check using_threads. Update call to dead_thread_notify. Call handle_extended_wait. (linux_create_inferior): Use PTRACE_SETOPTIONS. (send_sigstop): Delete sigstop_sent. (wait_for_sigstop): Avoid TID. (linux_supports_tracefork_flag, linux_tracefork_child, my_waitpid) (linux_test_for_tracefork): New. (linux_lookup_signals): Use thread_db_active and linux_supports_tracefork_flag. (initialize_low): Use thread_db_active and linux_test_for_tracefork. * linux-low.h (get_process_thread): Avoid TID. (struct process_ifo): Move thread_known and tid to the end. Remove sigstop_sent. (linux_attach_lwp, thread_db_init): Update prototypes. * server.h (change_inferior_id): Delete prototype. (add_pid_to_list, pull_pid_from_list): New prototypes. * thread-db.c (thread_db_use_events): New. (find_first_thread): Rename to... (find_one_thread): ...this. Update callers and messages. Do not call fatal. Check thread_db_use_events. Do not call change_inferior_id or new_thread_notify. (maybe_attach_thread): Update. Do not call new_thread_notify. (thread_db_init): Set thread_db_use_events. Check use_events. * utils.c (fatal, warning): Correct message prefix.
Diffstat (limited to 'gdb/gdbserver/thread-db.c')
-rw-r--r--gdb/gdbserver/thread-db.c80
1 files changed, 40 insertions, 40 deletions
diff --git a/gdb/gdbserver/thread-db.c b/gdb/gdbserver/thread-db.c
index adcb946..1869dbd 100644
--- a/gdb/gdbserver/thread-db.c
+++ b/gdb/gdbserver/thread-db.c
@@ -24,6 +24,8 @@
extern int debug_threads;
+static int thread_db_use_events;
+
#ifdef HAVE_THREAD_DB_H
#include <thread_db.h>
#endif
@@ -39,7 +41,7 @@ static struct ps_prochandle proc_handle;
/* Connection to the libthread_db library. */
static td_thragent_t *thread_agent;
-static int find_first_thread (void);
+static int find_one_thread (int);
static int find_new_threads_callback (const td_thrhandle_t *th_p, void *data);
static char *
@@ -152,7 +154,7 @@ thread_db_create_event (CORE_ADDR where)
created threads. */
process = get_thread_process (current_inferior);
if (process->thread_known == 0)
- find_first_thread ();
+ find_one_thread (process->lwpid);
/* msg.event == TD_EVENT_CREATE */
@@ -224,7 +226,7 @@ thread_db_enable_reporting ()
}
static int
-find_first_thread (void)
+find_one_thread (int lwpid)
{
td_thrhandle_t th;
td_thrinfo_t ti;
@@ -232,54 +234,50 @@ find_first_thread (void)
struct thread_info *inferior;
struct process_info *process;
- inferior = (struct thread_info *) all_threads.head;
+ inferior = (struct thread_info *) find_inferior_id (&all_threads, lwpid);
process = get_thread_process (inferior);
if (process->thread_known)
return 1;
- /* Get information about the one thread we know we have. */
+ /* Get information about this thread. */
err = td_ta_map_lwp2thr (thread_agent, process->lwpid, &th);
if (err != TD_OK)
- error ("Cannot get first thread handle: %s", thread_db_err_str (err));
+ error ("Cannot get thread handle for LWP %d: %s",
+ lwpid, thread_db_err_str (err));
err = td_thr_get_info (&th, &ti);
if (err != TD_OK)
- error ("Cannot get first thread info: %s", thread_db_err_str (err));
+ error ("Cannot get thread info for LWP %d: %s",
+ lwpid, thread_db_err_str (err));
if (debug_threads)
- fprintf (stderr, "Found first thread %ld (LWP %d)\n",
+ fprintf (stderr, "Found thread %ld (LWP %d)\n",
ti.ti_tid, ti.ti_lid);
if (process->lwpid != ti.ti_lid)
- fatal ("PID mismatch! Expected %ld, got %ld",
- (long) process->lwpid, (long) ti.ti_lid);
+ {
+ warning ("PID mismatch! Expected %ld, got %ld",
+ (long) process->lwpid, (long) ti.ti_lid);
+ return 0;
+ }
- /* If the new thread ID is zero, a final thread ID will be available
- later. Do not enable thread debugging yet. */
- if (ti.ti_tid == 0)
+ if (thread_db_use_events)
{
err = td_thr_event_enable (&th, 1);
if (err != TD_OK)
error ("Cannot enable thread event reporting for %d: %s",
ti.ti_lid, thread_db_err_str (err));
- return 0;
}
- /* Switch to indexing the threads list by TID. */
- change_inferior_id (&all_threads, ti.ti_tid);
-
- new_thread_notify (ti.ti_tid);
+ /* If the new thread ID is zero, a final thread ID will be available
+ later. Do not enable thread debugging yet. */
+ if (ti.ti_tid == 0)
+ return 0;
- process->tid = ti.ti_tid;
- process->lwpid = ti.ti_lid;
process->thread_known = 1;
+ process->tid = ti.ti_tid;
process->th = th;
- err = td_thr_event_enable (&th, 1);
- if (err != TD_OK)
- error ("Cannot enable thread event reporting for %d: %s",
- ti.ti_lid, thread_db_err_str (err));
-
return 1;
}
@@ -291,16 +289,16 @@ maybe_attach_thread (const td_thrhandle_t *th_p, td_thrinfo_t *ti_p)
struct process_info *process;
inferior = (struct thread_info *) find_inferior_id (&all_threads,
- ti_p->ti_tid);
+ ti_p->ti_lid);
if (inferior != NULL)
return;
if (debug_threads)
fprintf (stderr, "Attaching to thread %ld (LWP %d)\n",
ti_p->ti_tid, ti_p->ti_lid);
- linux_attach_lwp (ti_p->ti_lid, ti_p->ti_tid);
+ linux_attach_lwp (ti_p->ti_lid);
inferior = (struct thread_info *) find_inferior_id (&all_threads,
- ti_p->ti_tid);
+ ti_p->ti_lid);
if (inferior == NULL)
{
warning ("Could not attach to thread %ld (LWP %d)\n",
@@ -310,17 +308,17 @@ maybe_attach_thread (const td_thrhandle_t *th_p, td_thrinfo_t *ti_p)
process = inferior_target_data (inferior);
- new_thread_notify (ti_p->ti_tid);
-
process->tid = ti_p->ti_tid;
- process->lwpid = ti_p->ti_lid;
-
process->thread_known = 1;
process->th = *th_p;
- err = td_thr_event_enable (th_p, 1);
- if (err != TD_OK)
- error ("Cannot enable thread event reporting for %d: %s",
- ti_p->ti_lid, thread_db_err_str (err));
+
+ if (thread_db_use_events)
+ {
+ err = td_thr_event_enable (th_p, 1);
+ if (err != TD_OK)
+ error ("Cannot enable thread event reporting for %d: %s",
+ ti_p->ti_lid, thread_db_err_str (err));
+ }
}
static int
@@ -350,7 +348,7 @@ thread_db_find_new_threads (void)
/* This function is only called when we first initialize thread_db.
First locate the initial thread. If it is not ready for
debugging yet, then stop. */
- if (find_first_thread () == 0)
+ if (find_one_thread (all_threads.head->id) == 0)
return;
/* Iterate over all user-space threads to discover new threads. */
@@ -387,7 +385,7 @@ thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
process = get_thread_process (thread);
if (!process->thread_known)
- find_first_thread ();
+ find_one_thread (process->lwpid);
if (!process->thread_known)
return TD_NOTHR;
@@ -409,7 +407,7 @@ thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
}
int
-thread_db_init ()
+thread_db_init (int use_events)
{
int err;
@@ -428,6 +426,8 @@ thread_db_init ()
/* Allow new symbol lookups. */
all_symbols_looked_up = 0;
+ thread_db_use_events = use_events;
+
err = td_ta_new (&proc_handle, &thread_agent);
switch (err)
{
@@ -438,7 +438,7 @@ thread_db_init ()
case TD_OK:
/* The thread library was detected. */
- if (thread_db_enable_reporting () == 0)
+ if (use_events && thread_db_enable_reporting () == 0)
return 0;
thread_db_find_new_threads ();
thread_db_look_up_symbols ();