2011-10-09 Doug Evans * linux-thread-db.c (thread_db_new_objfile): Only try to load libthread_db when we load libpthread. (thread_db_inferior_created): New function. (_initialize_thread_db): Attach inferior_created observer. Index: linux-thread-db.c =================================================================== RCS file: /cvs/src/src/gdb/linux-thread-db.c,v retrieving revision 1.91 diff -u -p -r1.91 linux-thread-db.c --- linux-thread-db.c 13 Sep 2011 19:27:01 -0000 1.91 +++ linux-thread-db.c 10 Oct 2011 03:52:27 -0000 @@ -1077,16 +1077,32 @@ check_for_thread_db (void) return; } +/* This function is called via the new_objfile observer. */ + static void thread_db_new_objfile (struct objfile *objfile) { /* This observer must always be called with inferior_ptid set correctly. */ - if (objfile != NULL) + if (objfile != NULL + /* Only check for thread_db if we loaded libpthread. + For dynamically linked executables, libpthread can be near the end + of the list of shared libraries to load, and in an app of several + thousand shared libraries, this can otherwise be painful. */ + && libpthread_name_p (objfile->name)) check_for_thread_db (); } +/* This function is called via the inferior_created observer. + This handles the case of debugging statically linked executables. */ + +static void +thread_db_inferior_created (struct target_ops *target, int from_tty) +{ + check_for_thread_db (); +} + /* Attach to a new thread. This function is called when we receive a TD_CREATE event or when we iterate over all threads and find one that wasn't already in our list. Returns true on success. */ @@ -1845,4 +1861,9 @@ When non-zero, libthread-db debugging is /* Add ourselves to objfile event chain. */ observer_attach_new_objfile (thread_db_new_objfile); + + /* Add ourselves to inferior_created event chain. + This is needed to handle debugging statically linked programs where + the new_objfile observer won't get called for libpthread. */ + observer_attach_inferior_created (thread_db_inferior_created); }