Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Sergio Durigan Junior via Gdb-patches <gdb-patches@sourceware.org>
To: Simon Marchi <simark@simark.ca>
Cc: Mark Wielaard <mark@klomp.org>, gdb-patches@sourceware.org
Subject: Re: [PATCH v3] Search for DWZ files in debug-file-directories as well
Date: Tue, 01 Dec 2020 22:08:15 -0500	[thread overview]
Message-ID: <87a6uwewgw.fsf@paluero> (raw)
In-Reply-To: <6ca067dc-6f81-3573-a3cf-712ac7371c5b@simark.ca> (Simon Marchi's message of "Tue, 1 Dec 2020 09:45:49 -0500")

On Tuesday, December 01 2020, Simon Marchi wrote:

> On 2020-11-28 8:08 p.m., Sergio Durigan Junior via Gdb-patches wrote:
>> Changes from v2:
>>
>> - Put the new code into a new function.
>>
>> - The code now makes sure that the debug-file-directory being
>>   processed ends with a directory separator, which makes things more
>>   robust.
>>
>> - Minimized indentation level; fixed typos and improved code
>>   readability by adding more comments.
>>
>>
>> When Debian (and Ubuntu) builds its binaries, it (still) doesn't use
>> dwz's "--relative" option.  This causes their debuginfo files to
>> carry a .gnu_debugaltlink section containing a full pathname to the
>> DWZ alt debug file, like this:
>>
>>   $ readelf -wk /usr/bin/cat
>>   Contents of the .gnu_debugaltlink section:
>>
>>     Separate debug info file: /usr/lib/debug/.dwz/x86_64-linux-gnu/coreutils.debug
>>     Build-ID (0x14 bytes):
>>    ee 76 5d 71 97 37 ce 46 99 44 32 bb e8 a9 1a ef 99 96 88 db
>>
>>   Contents of the .gnu_debuglink section:
>>
>>     Separate debug info file: 06d3bee37b8c7e67b31cb2689cb351102ae73b.debug
>>     CRC value: 0x53267655
>>
>> This usually works OK, because most of the debuginfo files installed
>> via apt will be present in /usr/lib/debug anyway.  However, imagine
>> the following scenario:
>>
>> - You are using /usr/bin/cat, it crashes on you and generates a
>>   corefile.
>>
>> - You don't want/need to "apt install" the debuginfo file for
>>   coreutils from the repositories.  Instead, you already have the
>>   debuginfo files in a separate directory (e.g., $HOME/dbgsym).
>>
>> - You start GDB and "set debug-file-directory $HOME/dbgsym/usr/lib/debug".
>>   You then get the following message:
>>
>>   $ gdb -ex 'set debug-file-directory ./dbgsym/usr/lib/debug' -ex 'file /bin/cat' -ex 'core-file ./cat.core'
>>   GNU gdb (Ubuntu 10.1-0ubuntu1) 10.1
>>   ...
>>   Reading symbols from /bin/cat...
>>   Reading symbols from /home/sergio/gdb/dbgsym/usr/lib/debug/.build-id/bc/06d3bee37b8c7e67b31cb2689cb351102ae73b.debug...
>>   could not find '.gnu_debugaltlink' file for /home/sergio/gdb/dbgsym/usr/lib/debug/.build-id/bc/06d3bee37b8c7e67b31cb2689cb351102ae73b.debug
>>
>> This error happens because GDB is trying to locate the build-id
>> link (inside /home/sergio/gdb/dbgsym/usr/lib/debug/.build-id) for the
>> DWZ alt debug file, which doesn't exist.  Arguably, this is a problem
>> with how dh_dwz works in Debian, and it's something I'm also planning
>> to tackle.  But, back at the problem at hand.
>>
>> Besides not being able to find the build-id link in the directory
>> mentioned above, GDB also tried to open the DWZ alt file using its
>> filename.  The problem here is that, since we don't have the distro's
>> debuginfo installed, it can't find anything under /usr/lib/debug that
>> satisfies it.
>>
>> It occurred to me that a good way to workaround this problem is to
>> actually try to locate the DWZ alt debug file inside the
>> debug-file-directories (that were likely provided by the user).  So
>> this is what the proposed patch does.
>>
>> The idea here is simple: get the filename extracted from the
>> .gnu_debugaltlink section, and manipulate it in order to replace the
>> initial part of the path (everything before "/.dwz/") by whatever
>> debug-file-directories the user might have provided.
>>
>> I talked with Mark Wielaard and he agrees this is a sensible approach.
>> In fact, apparently this is something that eu-readelf also does.
>>
>> I regtested this code, and no regressions were found.
>>
>> 2020-11-28  Sergio Durigan Junior  <sergiodj@sergiodj.net>
>>
>> 	* dwarf2/read.c (dwz_search_other_debugdirs): New function.
>> 	(dwarf2_get_dwz_file): Convert 'filename' to a
>> 	std::string.  Use dwz_search_other_debugdirs to search for DWZ
>> 	files in the debug-file-directories provided by the user as well.
>
> Thanks this is OK.

Thanks, I've just pushed the patch.

> I forgot to mention that before, but a test would be nice to make sure
> this feature doesn't break when doing changes to the DWARF reader.

Totally agreed.  I'll see if I can come up with a testcase for this, and
will submit it later.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
https://sergiodj.net/

      reply	other threads:[~2020-12-02  3:08 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-14 23:48 [PATCH] " Sergio Durigan Junior via Gdb-patches
2020-11-15 13:19 ` Mark Wielaard
2020-11-16  1:25 ` Simon Marchi
2020-11-16  9:32   ` Mark Wielaard
2020-11-16 17:57   ` Sergio Durigan Junior via Gdb-patches
2020-11-19  2:27 ` [PATCH v2] " Sergio Durigan Junior via Gdb-patches
2020-11-25 15:09   ` Sergio Durigan Junior via Gdb-patches
2020-11-25 16:58   ` Luis Machado via Gdb-patches
2020-11-28 20:51     ` Sergio Durigan Junior via Gdb-patches
2020-11-26 16:53   ` Simon Marchi
2020-11-28 20:58     ` Sergio Durigan Junior via Gdb-patches
2020-11-28 21:35       ` Sergio Durigan Junior via Gdb-patches
2020-11-28 22:13         ` Simon Marchi
2020-11-28 22:12       ` Simon Marchi
2020-11-29  0:57         ` Sergio Durigan Junior via Gdb-patches
2020-11-29  1:29           ` Simon Marchi
2020-11-29  1:08 ` [PATCH v3] " Sergio Durigan Junior via Gdb-patches
2020-12-01 14:45   ` Simon Marchi
2020-12-02  3:08     ` Sergio Durigan Junior via Gdb-patches [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=87a6uwewgw.fsf@paluero \
    --to=gdb-patches@sourceware.org \
    --cc=mark@klomp.org \
    --cc=sergiodj@sergiodj.net \
    --cc=simark@simark.ca \
    /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