/* Non-zero if we're using this module's target vector. */
static int using_thread_db;
-/* Non-zero if we musn't deactivate this module's target vector. */
+/* Non-zero if we have to keep this module's target vector active
+ across re-runs. */
static int keep_thread_db;
/* Non-zero if we have determined the signals used by the threads
#endif
}
-static void
-deactivate_target (void)
-{
- /* Forget about the child's process ID. We shouldn't need it
- anymore. */
- proc_handle.pid = 0;
-
- if (! keep_thread_db)
- {
- using_thread_db = 0;
- unpush_target (&thread_db_ops);
- }
-}
-
static void
thread_db_new_objfile (struct objfile *objfile)
{
if (objfile == NULL)
{
/* All symbols have been discarded. If the thread_db target is
- active, deactivate it now, even if the application was linked
- statically against the thread library. */
- keep_thread_db = 0;
+ active, deactivate it now. */
if (using_thread_db)
- deactivate_target ();
+ {
+ gdb_assert (proc_handle.pid == 0);
+ unpush_target (&thread_db_ops);
+ using_thread_db = 0;
+ }
+
+ keep_thread_db = 0;
goto quit;
}
/* Under Linux, we have to attach to each and every thread. */
#ifdef ATTACH_LWP
- if (ti_p->ti_lid != GET_PID (ptid))
- ATTACH_LWP (BUILD_LWP (ti_p->ti_lid, GET_PID (ptid)), 0);
+ ATTACH_LWP (BUILD_LWP (ti_p->ti_lid, GET_PID (ptid)), 0);
#endif
/* Enable thread event reporting for this thread. */
target_pid_to_str (ptid), thread_db_err_str (err));
}
+static void
+thread_db_attach (char *args, int from_tty)
+{
+ target_beneath->to_attach (args, from_tty);
+
+ /* Destroy thread info; it's no longer valid. */
+ init_thread_list ();
+
+ /* The child process is now the actual multi-threaded
+ program. Snatch its process ID... */
+ proc_handle.pid = GET_PID (inferior_ptid);
+
+ /* ...and perform the remaining initialization steps. */
+ enable_thread_event_reporting ();
+ thread_db_find_new_threads();
+}
+
static void
detach_thread (ptid_t ptid, int verbose)
{
thread_db_detach (char *args, int from_tty)
{
disable_thread_event_reporting ();
- deactivate_target ();
+
+ /* There's no need to save & restore inferior_ptid here, since the
+ inferior is supposed to be survive this function call. */
+ inferior_ptid = lwp_from_thread (inferior_ptid);
+
+ /* Forget about the child's process ID. We shouldn't need it
+ anymore. */
+ proc_handle.pid = 0;
target_beneath->to_detach (args, from_tty);
}
static void
thread_db_kill (void)
{
+ /* There's no need to save & restore inferior_ptid here, since the
+ inferior isn't supposed to survive this function call. */
+ inferior_ptid = lwp_from_thread (inferior_ptid);
target_beneath->to_kill ();
}
static void
thread_db_create_inferior (char *exec_file, char *allargs, char **env)
{
+ if (! keep_thread_db)
+ {
+ unpush_target (&thread_db_ops);
+ using_thread_db = 0;
+ }
+
target_beneath->to_create_inferior (exec_file, allargs, env);
}
thread_db_mourn_inferior (void)
{
remove_thread_event_breakpoints ();
- deactivate_target ();
+
+ /* Forget about the child's process ID. We shouldn't need it
+ anymore. */
+ proc_handle.pid = 0;
target_beneath->to_mourn_inferior ();
}
thread_db_ops.to_shortname = "multi-thread";
thread_db_ops.to_longname = "multi-threaded child process.";
thread_db_ops.to_doc = "Threads and pthreads support.";
+ thread_db_ops.to_attach = thread_db_attach;
thread_db_ops.to_detach = thread_db_detach;
thread_db_ops.to_resume = thread_db_resume;
thread_db_ops.to_wait = thread_db_wait;