From: Doug Evans <dje@google.com>
To: Pedro Alves <pedro@codesourcery.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA] Only try to load libthread_db when we load libpthread.
Date: Tue, 11 Oct 2011 03:38:00 -0000 [thread overview]
Message-ID: <CADPb22SEaVRSwfqiT6y_Mk9zxUmwwSfCLxzE-jPHKui35KTtEA@mail.gmail.com> (raw)
In-Reply-To: <201110101922.54265.pedro@codesourcery.com>
[-- Attachment #1: Type: text/plain, Size: 1089 bytes --]
On Mon, Oct 10, 2011 at 11:22 AM, Pedro Alves <pedro@codesourcery.com> wrote:
> This version goes back to breaking the "file right_executable" core
> or attach cases (with static binaries) that the previous patch
> fixed. :-)
> [...]
> (gdb -c core; file exec).
That scenario I hadn't thought of.
Thanks, at least the code will be there for a documented reason.
Note that the non-static case of that sequence was and still is broken.
I checked this in.
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.
[-- Attachment #2: gdb-111010-libthread-db-5.patch.txt --]
[-- Type: text/plain, Size: 5416 bytes --]
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.
Index: linux-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/linux-nat.c,v
retrieving revision 1.216
diff -u -p -r1.216 linux-nat.c
--- linux-nat.c 7 Oct 2011 12:06:46 -0000 1.216
+++ linux-nat.c 11 Oct 2011 02:44:46 -0000
@@ -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: 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 11 Oct 2011 02:44:46 -0000
@@ -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 core 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
/* 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: 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 11 Oct 2011 02:44:46 -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 11 Oct 2011 02:44:46 -0000
@@ -1081,6 +1081,7 @@ symbol_file_add_with_addrs_or_offsets (b
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 (b
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)
prev parent reply other threads:[~2011-10-11 3:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-05 18:27 Doug Evans
2011-10-06 11:22 ` Pedro Alves
2011-10-06 19:56 ` Pedro Alves
2011-10-06 20:08 ` Doug Evans
2011-10-06 20:26 ` Pedro Alves
2011-10-06 21:56 ` Doug Evans
2011-10-06 22:06 ` Doug Evans
2011-10-07 11:09 ` Pedro Alves
2011-10-10 5:01 ` Doug Evans
2011-10-10 18:23 ` Pedro Alves
2011-10-11 3:38 ` Doug Evans [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CADPb22SEaVRSwfqiT6y_Mk9zxUmwwSfCLxzE-jPHKui35KTtEA@mail.gmail.com \
--to=dje@google.com \
--cc=gdb-patches@sourceware.org \
--cc=pedro@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox