* linux-thread-db.c (thread_db_new_objfile): Only try to load
authorDoug Evans <dje@google.com>
Tue, 11 Oct 2011 03:31:59 +0000 (03:31 +0000)
committerDoug Evans <dje@google.com>
Tue, 11 Oct 2011 03:31:59 +0000 (03:31 +0000)
libthread_db when we load libpthread or the main symbol file.
(thread_db_inferior_created): New function.
(_initialize_thread_db): Attach inferior_created observer.
* linux-nat.c (linux_child_post_attach): Remove call to
check_for_thread_db.
(linux_child_post_startup_inferior): Ditto.
* objfiles.h (OBJF_MAINLINE): Define.
* symfile.c (symbol_file_add_with_addrs_or_offsets): Pass it to
allocate_objfile when appropriate.

gdb/ChangeLog
gdb/linux-nat.c
gdb/linux-thread-db.c
gdb/objfiles.h
gdb/symfile.c

index a13421591b6fc6ecd116494faefcd16bf8bec24d..db214d2d2d76df40b4bc8109a2f7fa8de94c433a 100644 (file)
@@ -1,3 +1,16 @@
+2011-10-10  Doug Evans  <dje@google.com>
+
+       * linux-thread-db.c (thread_db_new_objfile): Only try to load
+       libthread_db when we load libpthread or the main symbol file.
+       (thread_db_inferior_created): New function.
+       (_initialize_thread_db): Attach inferior_created observer.
+       * linux-nat.c (linux_child_post_attach): Remove call to
+       check_for_thread_db.
+       (linux_child_post_startup_inferior): Ditto.
+       * objfiles.h (OBJF_MAINLINE): Define.
+       * symfile.c (symbol_file_add_with_addrs_or_offsets): Pass it to
+       allocate_objfile when appropriate.
+
 2011-10-10  Ulrich Weigand  <ulrich.weigand@linaro.org>
 
        PR gdb/13218
index 0cb40962d7d22e46e648ae98f657ed13d9691ad3..411afdc66bb1bfa2e2e982370a11d31abb5cf257 100644 (file)
@@ -571,7 +571,6 @@ static void
 linux_child_post_attach (int pid)
 {
   linux_enable_event_reporting (pid_to_ptid (pid));
-  check_for_thread_db ();
   linux_enable_tracesysgood (pid_to_ptid (pid));
 }
 
@@ -579,7 +578,6 @@ static void
 linux_child_post_startup_inferior (ptid_t ptid)
 {
   linux_enable_event_reporting (ptid);
-  check_for_thread_db ();
   linux_enable_tracesysgood (ptid);
 }
 
index 8dd766b2512915d166394b9b4ce93faaa5dac5ce..d9380fd80a0ca3bc854aa1d409d1907fb2c6c73c 100644 (file)
@@ -1077,16 +1077,37 @@ 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,
+        or if this is the main symbol file.
+        We need to check OBJF_MAINLINE to handle the case of debugging
+        a statically linked executable AND the symbol file is specified AFTER
+        the exec file is loaded (e.g., gdb -c core ; file foo).
+        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 ();
 }
 
+/* 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 +1866,9 @@ When non-zero, libthread-db debugging is enabled."),
 
   /* 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);
 }
index bb28dc1d658e9ac33df545bb76975013d465ae08..1d24fb90b81cade725a121deaafc7dafa4b6dc04 100644 (file)
@@ -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 1540cb717ae3f0ae7bb05fbd8ba976af73f92652..5c4906fad21ba2fa4ea6b65bc024a0d6f69c0058 100644 (file)
@@ -1081,6 +1081,7 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
   struct cleanup *my_cleanups;
   const char *name = bfd_get_filename (abfd);
   const int from_tty = add_flags & SYMFILE_VERBOSE;
+  const int mainline = add_flags & SYMFILE_MAINLINE;
   const int should_print = ((from_tty || info_verbose)
                            && (readnow_symbol_files
                                || (add_flags & SYMFILE_NO_READ) == 0));
@@ -1097,12 +1098,12 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
      interactively wiping out any existing symbols.  */
 
   if ((have_full_symbols () || have_partial_symbols ())
-      && (add_flags & SYMFILE_MAINLINE)
+      && mainline
       && from_tty
       && !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)
This page took 0.035957 seconds and 4 git commands to generate.