* [PATCH] gdb: Try searching for auto-load script using .gnu_debuglink
@ 2022-02-23 3:35 Aaron Merey
2022-03-04 15:56 ` Tom Tromey
0 siblings, 1 reply; 10+ messages in thread
From: Aaron Merey @ 2022-02-23 3:35 UTC (permalink / raw)
To: gdb-patches
If an auto-load script cannot be found and objfile is a separate
debuginfo whose filename does not match the name found in the parent
file's .gnu_debuglink section, then repeat the search using the
parent's filename where the last component is replaced with the
.gnu_debuglink name.
For example if the parent's filename is "/usr/lib/libxyz.so" and the
name in its .gnu_debuglink section is "libxyz.so.debug", then
if no auto-load script is otherwise found the search will be
repeated with the filename "/usr/lib/libxyz.so.debug".
This helps gdb locate auto-load scripts when debuginfo files do not have
the expected filename, such as when they are aquired from debuginfod.
---
gdb/auto-load.c | 62 +++++++++++++++++++++++++++++++++++++++----------
1 file changed, 50 insertions(+), 12 deletions(-)
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 680b87936b1..4ecec20d9cc 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -51,6 +51,9 @@
followed by the path of a python script to load. */
#define AUTO_SECTION_NAME ".debug_gdb_scripts"
+/* The section to look in for the name of a separate debug file. */
+#define DEBUGLINK_SECTION_NAME ".gnu_debuglink"
+
static void maybe_print_unsupported_script_warning
(struct auto_load_pspace_info *, struct objfile *objfile,
const struct extension_language_defn *language,
@@ -820,24 +823,59 @@ auto_load_objfile_script (struct objfile *objfile,
gdb::unique_xmalloc_ptr<char> realname
= gdb_realpath (objfile_name (objfile));
- if (!auto_load_objfile_script_1 (objfile, realname.get (), language))
+ if (auto_load_objfile_script_1 (objfile, realname.get (), language))
+ return;
+
+ /* For Windows/DOS .exe executables, strip the .exe suffix, so that
+ FOO-gdb.gdb could be used for FOO.exe, and try again. */
+
+ size_t len = strlen (realname.get ());
+ const size_t lexe = sizeof (".exe") - 1;
+
+ if (len > lexe && strcasecmp (realname.get () + len - lexe, ".exe") == 0)
{
- /* For Windows/DOS .exe executables, strip the .exe suffix, so that
- FOO-gdb.gdb could be used for FOO.exe, and try again. */
+ len -= lexe;
+ realname.get ()[len] = '\0';
+
+ auto_load_debug_printf
+ ("auto-load: Stripped .exe suffix, retrying with \"%s\".",
+ realname.get ());
+
+ auto_load_objfile_script_1 (objfile, realname.get (), language);
+ return;
+ }
- size_t len = strlen (realname.get ());
- const size_t lexe = sizeof (".exe") - 1;
+ /* If OBJFILE is a separate debug file and its name does not match
+ the name given in the parent's .gnu_debuglink section, try to
+ find the auto-load script using the parent's path and the
+ debuglink name. */
+
+ struct objfile *parent = objfile->separate_debug_objfile_backlink;
+ if (parent != nullptr)
+ {
+ unsigned long crc32;
+ char *debuglink = bfd_get_debug_link_info (parent->obfd, &crc32);
- if (len > lexe && strcasecmp (realname.get () + len - lexe, ".exe") == 0)
+ if (debuglink != nullptr
+ && strcmp (debuglink, basename (realname.get ())) != 0)
{
- len -= lexe;
- realname.get ()[len] = '\0';
+ /* Replace the last component of the parent's path with the
+ debuglink name. */
- auto_load_debug_printf
- ("auto-load: Stripped .exe suffix, retrying with \"%s\".",
- realname.get ());
+ std::string p_realname = gdb_realpath (objfile_name (parent)).get ();
+ size_t last = p_realname.find_last_of ('/');
- auto_load_objfile_script_1 (objfile, realname.get (), language);
+ if (last != std::string::npos)
+ {
+ p_realname.replace (last + 1, std::string::npos, debuglink);
+
+ auto_load_debug_printf
+ ("Debug filename mismatch, retrying with \"%s\".",
+ p_realname.c_str ());
+
+ auto_load_objfile_script_1 (objfile,
+ p_realname.c_str (), language);
+ }
}
}
}
--
2.35.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] gdb: Try searching for auto-load script using .gnu_debuglink
2022-02-23 3:35 [PATCH] gdb: Try searching for auto-load script using .gnu_debuglink Aaron Merey
@ 2022-03-04 15:56 ` Tom Tromey
2022-03-08 22:41 ` Aaron Merey
0 siblings, 1 reply; 10+ messages in thread
From: Tom Tromey @ 2022-03-04 15:56 UTC (permalink / raw)
To: Aaron Merey via Gdb-patches
>>>>> "Aaron" == Aaron Merey via Gdb-patches <gdb-patches@sourceware.org> writes:
Aaron> For example if the parent's filename is "/usr/lib/libxyz.so" and the
Aaron> name in its .gnu_debuglink section is "libxyz.so.debug", then
Aaron> if no auto-load script is otherwise found the search will be
Aaron> repeated with the filename "/usr/lib/libxyz.so.debug".
Seems reasonable.
Aaron> + char *debuglink = bfd_get_debug_link_info (parent->obfd, &crc32);
bfd_get_debug_link_info says it returns a malloc'd pointer, so I think
this is a memory leak. Using gdb::unique_xmalloc_ptr<char> would solve
this.
Tom
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] gdb: Try searching for auto-load script using .gnu_debuglink
2022-03-04 15:56 ` Tom Tromey
@ 2022-03-08 22:41 ` Aaron Merey
2022-03-09 0:26 ` Tom Tromey
2022-03-10 17:57 ` Pedro Alves
0 siblings, 2 replies; 10+ messages in thread
From: Aaron Merey @ 2022-03-08 22:41 UTC (permalink / raw)
To: tom; +Cc: gdb-patches, Aaron Merey
Hi Tom,
On Fri, Mar 4, 2022 at 10:56 AM Tom Tromey <tom@tromey.com> wrote:
> Aaron> + char *debuglink = bfd_get_debug_link_info (parent->obfd, &crc32);
>
> bfd_get_debug_link_info says it returns a malloc'd pointer, so I think
> this is a memory leak. Using gdb::unique_xmalloc_ptr<char> would solve
> this.
Fixed, thanks.
Aaron
---
gdb/auto-load.c | 64 +++++++++++++++++++++++++++++++++++++++----------
1 file changed, 52 insertions(+), 12 deletions(-)
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 9a1ccec87ce..0acf2cee777 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -51,6 +51,9 @@
followed by the path of a python script to load. */
#define AUTO_SECTION_NAME ".debug_gdb_scripts"
+/* The section to look in for the name of a separate debug file. */
+#define DEBUGLINK_SECTION_NAME ".gnu_debuglink"
+
static void maybe_print_unsupported_script_warning
(struct auto_load_pspace_info *, struct objfile *objfile,
const struct extension_language_defn *language,
@@ -823,24 +826,61 @@ auto_load_objfile_script (struct objfile *objfile,
gdb::unique_xmalloc_ptr<char> realname
= gdb_realpath (objfile_name (objfile));
- if (!auto_load_objfile_script_1 (objfile, realname.get (), language))
+ if (auto_load_objfile_script_1 (objfile, realname.get (), language))
+ return;
+
+ /* For Windows/DOS .exe executables, strip the .exe suffix, so that
+ FOO-gdb.gdb could be used for FOO.exe, and try again. */
+
+ size_t len = strlen (realname.get ());
+ const size_t lexe = sizeof (".exe") - 1;
+
+ if (len > lexe && strcasecmp (realname.get () + len - lexe, ".exe") == 0)
{
- /* For Windows/DOS .exe executables, strip the .exe suffix, so that
- FOO-gdb.gdb could be used for FOO.exe, and try again. */
+ len -= lexe;
+ realname.get ()[len] = '\0';
+
+ auto_load_debug_printf
+ ("auto-load: Stripped .exe suffix, retrying with \"%s\".",
+ realname.get ());
+
+ auto_load_objfile_script_1 (objfile, realname.get (), language);
+ return;
+ }
- size_t len = strlen (realname.get ());
- const size_t lexe = sizeof (".exe") - 1;
+ /* If OBJFILE is a separate debug file and its name does not match
+ the name given in the parent's .gnu_debuglink section, try to
+ find the auto-load script using the parent's path and the
+ debuglink name. */
+
+ struct objfile *parent = objfile->separate_debug_objfile_backlink;
+ if (parent != nullptr)
+ {
+ unsigned long crc32;
+ gdb::unique_xmalloc_ptr<char> debuglink
+ (bfd_get_debug_link_info (parent->obfd, &crc32));
- if (len > lexe && strcasecmp (realname.get () + len - lexe, ".exe") == 0)
+ if (debuglink.get () != nullptr
+ && strcmp (debuglink.get (), basename (realname.get ())) != 0)
{
- len -= lexe;
- realname.get ()[len] = '\0';
+ /* Replace the last component of the parent's path with the
+ debuglink name. */
- auto_load_debug_printf
- ("auto-load: Stripped .exe suffix, retrying with \"%s\".",
- realname.get ());
+ std::string p_realname = gdb_realpath (objfile_name (parent)).get ();
+ size_t last = p_realname.find_last_of ('/');
- auto_load_objfile_script_1 (objfile, realname.get (), language);
+ if (last != std::string::npos)
+ {
+ p_realname.replace (last + 1, std::string::npos,
+ debuglink.get ());
+
+ auto_load_debug_printf
+ ("Debug filename mismatch, retrying with \"%s\".",
+ p_realname.c_str ());
+
+ auto_load_objfile_script_1 (objfile,
+ p_realname.c_str (), language);
+ }
}
}
}
--
2.35.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] gdb: Try searching for auto-load script using .gnu_debuglink
2022-03-08 22:41 ` Aaron Merey
@ 2022-03-09 0:26 ` Tom Tromey
2022-03-09 1:42 ` Aaron Merey
2022-03-10 17:57 ` Pedro Alves
1 sibling, 1 reply; 10+ messages in thread
From: Tom Tromey @ 2022-03-09 0:26 UTC (permalink / raw)
To: Aaron Merey; +Cc: tom, gdb-patches
>>>>> "Aaron" == Aaron Merey <amerey@redhat.com> writes:
Aaron> + && strcmp (debuglink.get (), basename (realname.get ())) != 0)
gdb normally uses lbasename and not plain basename.
This is ok with this fixed.
Tom
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] gdb: Try searching for auto-load script using .gnu_debuglink
2022-03-09 0:26 ` Tom Tromey
@ 2022-03-09 1:42 ` Aaron Merey
0 siblings, 0 replies; 10+ messages in thread
From: Aaron Merey @ 2022-03-09 1:42 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On Tue, Mar 8, 2022 at 7:26 PM Tom Tromey <tom@tromey.com> wrote:
>
> >>>>> "Aaron" == Aaron Merey <amerey@redhat.com> writes:
>
> Aaron> + && strcmp (debuglink.get (), basename (realname.get ())) != 0)
>
> gdb normally uses lbasename and not plain basename.
>
> This is ok with this fixed.
Fixed. Pushed as commit 2e79bbf1e2.
Aaron
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] gdb: Try searching for auto-load script using .gnu_debuglink
2022-03-08 22:41 ` Aaron Merey
2022-03-09 0:26 ` Tom Tromey
@ 2022-03-10 17:57 ` Pedro Alves
2022-03-10 20:16 ` Aaron Merey
1 sibling, 1 reply; 10+ messages in thread
From: Pedro Alves @ 2022-03-10 17:57 UTC (permalink / raw)
To: Aaron Merey, tom; +Cc: gdb-patches
On 2022-03-08 22:41, Aaron Merey via Gdb-patches wrote:
> + auto_load_debug_printf
> + ("auto-load: Stripped .exe suffix, retrying with \"%s\".",
> + realname.get ());
> +
With "auto-load:" in the fmt, doesn't gdb print "auto-load" twice?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] gdb: Try searching for auto-load script using .gnu_debuglink
2022-03-10 17:57 ` Pedro Alves
@ 2022-03-10 20:16 ` Aaron Merey
2022-03-10 20:22 ` Aaron Merey
0 siblings, 1 reply; 10+ messages in thread
From: Aaron Merey @ 2022-03-10 20:16 UTC (permalink / raw)
To: Pedro Alves; +Cc: Tom Tromey, gdb-patches
Hi Pedro,
On Thu, Mar 10, 2022 at 1:26 PM Pedro Alves <pedro@palves.net> wrote:
>
> On 2022-03-08 22:41, Aaron Merey via Gdb-patches wrote:
> > + auto_load_debug_printf
> > + ("auto-load: Stripped .exe suffix, retrying with \"%s\".",
> > + realname.get ());
> > +
>
> With "auto-load:" in the fmt, doesn't gdb print "auto-load" twice?
This was fixed in the second version of the patch I posted:
On Tue, Mar 8, 2022 at 5:41 PM Aaron Merey <amerey@redhat.com> wrote:
> + auto_load_debug_printf
> + ("Debug filename mismatch, retrying with \"%s\".",
> + p_realname.c_str ());
The first version repeated "auto-load" because I based the message
on a pre-existing call to auto_load_debug_printf in auto_load_objfile_script
which contains a repeated "auto-load". That should be fixed and I will post
a patch for this.
Aaron
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] gdb: Try searching for auto-load script using .gnu_debuglink
2022-03-10 20:16 ` Aaron Merey
@ 2022-03-10 20:22 ` Aaron Merey
2022-03-10 20:43 ` Tom Tromey
2022-03-11 9:32 ` Pedro Alves
0 siblings, 2 replies; 10+ messages in thread
From: Aaron Merey @ 2022-03-10 20:22 UTC (permalink / raw)
To: Pedro Alves; +Cc: Tom Tromey, gdb-patches
On Thu, Mar 10, 2022 at 3:16 PM Aaron Merey <amerey@redhat.com> wrote:
>
> Hi Pedro,
>
> On Thu, Mar 10, 2022 at 1:26 PM Pedro Alves <pedro@palves.net> wrote:
> >
> > On 2022-03-08 22:41, Aaron Merey via Gdb-patches wrote:
> > > + auto_load_debug_printf
> > > + ("auto-load: Stripped .exe suffix, retrying with \"%s\".",
> > > + realname.get ());
> > > +
> >
> > With "auto-load:" in the fmt, doesn't gdb print "auto-load" twice?
>
> This was fixed in the second version of the patch I posted:
>
> On Tue, Mar 8, 2022 at 5:41 PM Aaron Merey <amerey@redhat.com> wrote:
> > + auto_load_debug_printf
> > + ("Debug filename mismatch, retrying with \"%s\".",
> > + p_realname.c_str ());
>
> The first version repeated "auto-load" because I based the message
> on a pre-existing call to auto_load_debug_printf in auto_load_objfile_script
> which contains a repeated "auto-load". That should be fixed and I will post
> a patch for this.
Sorry Pedro, I mistook the function call you quoted for the call I added and
later fixed. The repeated auto-load you quoted was copied verbatim from a
pre-existing call to auto_load_debug_printf and was not fixed in the patch
that was merged. But like I said I will post a fix for this.
Aaron
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] gdb: Try searching for auto-load script using .gnu_debuglink
2022-03-10 20:22 ` Aaron Merey
@ 2022-03-10 20:43 ` Tom Tromey
2022-03-11 9:32 ` Pedro Alves
1 sibling, 0 replies; 10+ messages in thread
From: Tom Tromey @ 2022-03-10 20:43 UTC (permalink / raw)
To: Aaron Merey via Gdb-patches; +Cc: Pedro Alves, Aaron Merey, Tom Tromey
Aaron> Sorry Pedro, I mistook the function call you quoted for the call I added and
Aaron> later fixed. The repeated auto-load you quoted was copied verbatim from a
Aaron> pre-existing call to auto_load_debug_printf and was not fixed in the patch
Aaron> that was merged. But like I said I will post a fix for this.
If it's just removing the prefix from the printf format, I think it
qualifies as obvious, just FYI.
Tom
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] gdb: Try searching for auto-load script using .gnu_debuglink
2022-03-10 20:22 ` Aaron Merey
2022-03-10 20:43 ` Tom Tromey
@ 2022-03-11 9:32 ` Pedro Alves
1 sibling, 0 replies; 10+ messages in thread
From: Pedro Alves @ 2022-03-11 9:32 UTC (permalink / raw)
To: Aaron Merey; +Cc: Tom Tromey, gdb-patches
On 2022-03-10 20:22, Aaron Merey wrote:
> On Thu, Mar 10, 2022 at 3:16 PM Aaron Merey <amerey@redhat.com> wrote:
>>
>> Hi Pedro,
>>
>> On Thu, Mar 10, 2022 at 1:26 PM Pedro Alves <pedro@palves.net> wrote:
>>>
>>> On 2022-03-08 22:41, Aaron Merey via Gdb-patches wrote:
>>>> + auto_load_debug_printf
>>>> + ("auto-load: Stripped .exe suffix, retrying with \"%s\".",
>>>> + realname.get ());
>>>> +
>>>
>>> With "auto-load:" in the fmt, doesn't gdb print "auto-load" twice?
>>
>> This was fixed in the second version of the patch I posted:
>>
>> On Tue, Mar 8, 2022 at 5:41 PM Aaron Merey <amerey@redhat.com> wrote:
>>> + auto_load_debug_printf
>>> + ("Debug filename mismatch, retrying with \"%s\".",
>>> + p_realname.c_str ());
>>
>> The first version repeated "auto-load" because I based the message
>> on a pre-existing call to auto_load_debug_printf in auto_load_objfile_script
>> which contains a repeated "auto-load". That should be fixed and I will post
>> a patch for this.
>
> Sorry Pedro, I mistook the function call you quoted for the call I added and
> later fixed. The repeated auto-load you quoted was copied verbatim from a
> pre-existing call to auto_load_debug_printf and was not fixed in the patch
> that was merged. But like I said I will post a fix for this.
Thanks Aaron.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-03-11 9:32 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-23 3:35 [PATCH] gdb: Try searching for auto-load script using .gnu_debuglink Aaron Merey
2022-03-04 15:56 ` Tom Tromey
2022-03-08 22:41 ` Aaron Merey
2022-03-09 0:26 ` Tom Tromey
2022-03-09 1:42 ` Aaron Merey
2022-03-10 17:57 ` Pedro Alves
2022-03-10 20:16 ` Aaron Merey
2022-03-10 20:22 ` Aaron Merey
2022-03-10 20:43 ` Tom Tromey
2022-03-11 9:32 ` Pedro Alves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).