yann@96: Status: submitted similar patch 2004-12-08 yann@96: yann@96: This patch cleans up the initialization of thread_db. It works for static yann@96: binaries now. The vsyscall patches hide this problem, since new static yann@96: binaries will load the vsyscall DSO and then trigger thread_db; but yann@96: this is still a good cleanup. yann@96: yann@96: Index: gdb-6.3/gdb/thread-db.c yann@96: =================================================================== yann@96: --- gdb-6.3.orig/gdb/thread-db.c 2004-10-08 16:29:56.000000000 -0400 yann@96: +++ gdb-6.3/gdb/thread-db.c 2004-11-10 00:19:30.626530413 -0500 yann@96: @@ -34,6 +34,7 @@ yann@96: #include "target.h" yann@96: #include "regcache.h" yann@96: #include "solib-svr4.h" yann@96: +#include "observer.h" yann@96: yann@96: #ifdef HAVE_GNU_LIBC_VERSION_H yann@96: #include yann@96: @@ -627,59 +628,49 @@ check_thread_signals (void) yann@96: #endif yann@96: } yann@96: yann@96: +/* Check whether thread_db is usable. This function is called when yann@96: + an inferior is created (or otherwise acquired, e.g. attached to) yann@96: + and when new shared libraries are loaded into a running process. */ yann@96: + yann@96: static void yann@96: -thread_db_new_objfile (struct objfile *objfile) yann@96: +check_for_thread_db (void) yann@96: { yann@96: td_err_e err; yann@96: + static int already_loaded; yann@96: yann@96: /* First time through, report that libthread_db was successfuly yann@96: loaded. Can't print this in in thread_db_load as, at that stage, yann@96: - the interpreter and it's console haven't started. The real yann@96: - problem here is that libthread_db is loaded too early - it should yann@96: - only be loaded when there is a program to debug. */ yann@96: - { yann@96: - static int dejavu; yann@96: - if (!dejavu) yann@96: - { yann@96: - Dl_info info; yann@96: - const char *library = NULL; yann@96: - /* Try dladdr. */ yann@96: - if (dladdr ((*td_ta_new_p), &info) != 0) yann@96: - library = info.dli_fname; yann@96: - /* Try dlinfo? */ yann@96: - if (library == NULL) yann@96: - /* Paranoid - don't let a NULL path slip through. */ yann@96: - library = LIBTHREAD_DB_SO; yann@96: - printf_unfiltered ("Using host libthread_db library \"%s\".\n", yann@96: - library); yann@96: - dejavu = 1; yann@96: - } yann@96: - } yann@96: + the interpreter and it's console haven't started. */ yann@96: yann@96: - /* Don't attempt to use thread_db on targets which can not run yann@96: - (core files). */ yann@96: - if (objfile == NULL || !target_has_execution) yann@96: + if (!already_loaded) yann@96: { yann@96: - /* All symbols have been discarded. If the thread_db target is yann@96: - active, deactivate it now. */ yann@96: - if (using_thread_db) yann@96: - { yann@96: - gdb_assert (proc_handle.pid == 0); yann@96: - unpush_target (&thread_db_ops); yann@96: - using_thread_db = 0; yann@96: - } yann@96: + Dl_info info; yann@96: + const char *library = NULL; yann@96: + if (dladdr ((*td_ta_new_p), &info) != 0) yann@96: + library = info.dli_fname; yann@96: + yann@96: + /* Try dlinfo? */ yann@96: yann@96: - goto quit; yann@96: + if (library == NULL) yann@96: + /* Paranoid - don't let a NULL path slip through. */ yann@96: + library = LIBTHREAD_DB_SO; yann@96: + yann@96: + printf_unfiltered ("Using host libthread_db library \"%s\".\n", yann@96: + library); yann@96: + already_loaded = 1; yann@96: } yann@96: yann@96: if (using_thread_db) yann@96: /* Nothing to do. The thread library was already detected and the yann@96: target vector was already activated. */ yann@96: - goto quit; yann@96: + return; yann@96: + yann@96: + /* Don't attempt to use thread_db on targets which can not run yann@96: + (executables not running yet, core files) for now. */ yann@96: + if (!target_has_execution) yann@96: + return; yann@96: yann@96: - /* Initialize the structure that identifies the child process. Note yann@96: - that at this point there is no guarantee that we actually have a yann@96: - child process. */ yann@96: + /* Initialize the structure that identifies the child process. */ yann@96: proc_handle.pid = GET_PID (inferior_ptid); yann@96: yann@96: /* Now attempt to open a connection to the thread library. */ yann@96: @@ -706,12 +697,24 @@ thread_db_new_objfile (struct objfile *o yann@96: thread_db_err_str (err)); yann@96: break; yann@96: } yann@96: +} yann@96: + yann@96: +static void yann@96: +thread_db_new_objfile (struct objfile *objfile) yann@96: +{ yann@96: + if (objfile != NULL) yann@96: + check_for_thread_db (); yann@96: yann@96: -quit: yann@96: if (target_new_objfile_chain) yann@96: target_new_objfile_chain (objfile); yann@96: } yann@96: yann@96: +static void yann@96: +check_for_thread_db_observer (struct target_ops *target, int from_tty) yann@96: +{ yann@96: + check_for_thread_db (); yann@96: +} yann@96: + yann@96: /* Attach to a new thread. This function is called when we receive a yann@96: TD_CREATE event or when we iterate over all threads and find one yann@96: that wasn't already in our list. */ yann@96: @@ -1366,5 +1369,8 @@ _initialize_thread_db (void) yann@96: /* Add ourselves to objfile event chain. */ yann@96: target_new_objfile_chain = deprecated_target_new_objfile_hook; yann@96: deprecated_target_new_objfile_hook = thread_db_new_objfile; yann@96: + yann@96: + /* Register ourselves for the new inferior observer. */ yann@96: + observer_attach_inferior_created (check_for_thread_db_observer); yann@96: } yann@96: } yann@96: Index: gdb-6.3/gdb/Makefile.in yann@96: =================================================================== yann@96: --- gdb-6.3.orig/gdb/Makefile.in 2004-11-09 23:04:57.000000000 -0500 yann@96: +++ gdb-6.3/gdb/Makefile.in 2004-11-10 00:19:26.440347022 -0500 yann@96: @@ -2626,7 +2626,8 @@ thread.o: thread.c $(defs_h) $(symtab_h) yann@96: $(gdbcmd_h) $(regcache_h) $(gdb_h) $(gdb_string_h) $(ui_out_h) yann@96: thread-db.o: thread-db.c $(defs_h) $(gdb_assert_h) $(gdb_proc_service_h) \ yann@96: $(gdb_thread_db_h) $(bfd_h) $(gdbthread_h) $(inferior_h) \ yann@96: - $(symfile_h) $(objfiles_h) $(target_h) $(regcache_h) $(solib_svr4_h) yann@96: + $(symfile_h) $(objfiles_h) $(target_h) $(regcache_h) $(solib_svr4_h) \ yann@96: + $(observer_h) yann@96: top.o: top.c $(defs_h) $(gdbcmd_h) $(call_cmds_h) $(cli_cmds_h) \ yann@96: $(cli_script_h) $(cli_setshow_h) $(cli_decode_h) $(symtab_h) \ yann@96: $(inferior_h) $(target_h) $(breakpoint_h) $(gdbtypes_h) \