2011-10-06 Doug Evans * linux-thread-db.c (thread_db_new_objfile): Only try to load libthread_db when we load libpthread or the main symbol file. * objfiles.h (OBJF_MAINLINE): Define. * symfile.c (symbol_file_add_with_addrs_or_offsets): Pass it to allocate_objfile when appropriate. 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 6 Oct 2011 21:39:32 -0000 @@ -1083,7 +1083,16 @@ thread_db_new_objfile (struct objfile *o /* 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, + or if this is the main symbol file. + We need to check OBJF_MAINLINE in case this is a statically + linked executable. + 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. */ + && ((objfile->flags & OBJF_MAINLINE) != 0 + || libpthread_name_p (objfile->name))) check_for_thread_db (); } Index: objfiles.h =================================================================== RCS file: /cvs/src/src/gdb/objfiles.h,v retrieving revision 1.85 diff -u -p -r1.85 objfiles.h --- objfiles.h 14 Jun 2011 16:49:41 -0000 1.85 +++ objfiles.h 6 Oct 2011 21:39:32 -0000 @@ -196,7 +196,8 @@ struct objfile CORE_ADDR addr_low; - /* Some flag bits for this objfile. */ + /* Some flag bits for this objfile. + The values are defined by OBJF_*. */ unsigned short flags; @@ -434,6 +435,11 @@ struct objfile #define OBJF_PSYMTABS_READ (1 << 4) +/* Set if this is the main symbol file + (as opposed to symbol file for dynamically loaded code). */ + +#define OBJF_MAINLINE (1 << 5) + /* The object file that contains the runtime common minimal symbols for SunOS4. Note that this objfile has no associated BFD. */ Index: symfile.c =================================================================== RCS file: /cvs/src/src/gdb/symfile.c,v retrieving revision 1.316 diff -u -p -r1.316 symfile.c --- symfile.c 29 Sep 2011 02:04:25 -0000 1.316 +++ symfile.c 6 Oct 2011 21:39:34 -0000 @@ -1084,6 +1084,7 @@ symbol_file_add_with_addrs_or_offsets (b const int should_print = ((from_tty || info_verbose) && (readnow_symbol_files || (add_flags & SYMFILE_NO_READ) == 0)); + const int mainline = add_flags & SYMFILE_MAINLINE; if (readnow_symbol_files) { @@ -1102,7 +1103,7 @@ symbol_file_add_with_addrs_or_offsets (b && !query (_("Load new symbol table from \"%s\"? "), name)) error (_("Not confirmed.")); - objfile = allocate_objfile (abfd, flags); + objfile = allocate_objfile (abfd, flags | (mainline ? OBJF_MAINLINE : 0)); discard_cleanups (my_cleanups); if (parent)