Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Lancelot SIX <lancelot.six@amd.com>
To: Tom Tromey <tom@tromey.com>
Cc: <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Avoid race when reading dwz file
Date: Thu, 28 Mar 2024 10:37:04 +0000	[thread overview]
Message-ID: <20240328103632.7iljwbcnjm55rkgd@khazad-dum> (raw)
In-Reply-To: <877ciczufp.fsf@tromey.com>

On Fri, Mar 08, 2024 at 07:09:46AM -0700, Tom Tromey wrote:
> >>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:
> 
> Tom> PR gdb/31260 points out a race introduced by the background reading
> Tom> changes.  If a given objfile is re-opened when it is already being
> Tom> read, dwarf2_initialize_objfile will call dwarf2_read_dwz_file again,
> Tom> causing the 'dwz_file' to be reset.
> 
> Tom> This patch fixes the problem by arranging to open the dwz just once:
> Tom> when the dwarf2_per_bfd object is created.
> 
> Tom> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31260
> 
> I'm checking this in.
> 
> Tom

Hi Tom,

It looks like this patch introduces a slight behavior change, and I am
not sure if this is intentional (or desired).

Before this patch we had:

    bool
    dwarf2_initialize_objfile (...)
    {
      if (!dwarf2_has_info (...))
        return false;
      ...
         dwarf2_read_dwz_file (...);
    }

This meas that dwarf2_read_dwz_file is only called if dwarf2_has_info
returns true.

Since this patch, the call to dwarf2_read_dwz_file has been moved inside
dwarf2_has_info.  As a consequence, dwarf2_read_dwz_file can be called
in cases where dwarf2_has_info returns false.

I can observe this on ubuntu-22.06 when loading
/lib/x86_64-linux-gnu/libtinfo.so.6 (provided by libtinfo6).  That file
has no .debug_info section, but has a .gnu_debugaltlink section.  The
old logic would skip dwarf2_read_dwz_file because of the absence of
.debug_info, but the new behavior tries (and might fail) to load the
debug information referenced in .gnu_debugaltlink:

    $ ./gdb/gdb -data-directory ./gdb/data-directory -q /lib/x86_64-linux-gnu/libtinfo.so.6
    Reading symbols from /lib/x86_64-linux-gnu/libtinfo.so.6...
    
    warning: could not find '.gnu_debugaltlink' file for /usr/lib/x86_64-linux-gnu/libtinfo.so.6.3
    (No debugging symbols found in /lib/x86_64-linux-gnu/libtinfo.so.6)
    (gdb)

I am not too sure if it makes sense to try to load the debug info
referenced in .gnu_debugaltlink if the "main" debug info section is
missing.  It can be better than nothing as it can provide some types
information, but it is definitely not sufficient for a "full" debug
session.

Should the call to dwarf2_read_dwz_file be guarded only if "main" debug
info sections are present?  I can prepare a patch doing this.

[Arguably, .gnu_debugaltlink should also be removed when stripping the
debug information, but it is not.]

Best,
Lancelot.

  reply	other threads:[~2024-03-28 10:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-25 13:51 Tom Tromey
2024-03-08 14:09 ` Tom Tromey
2024-03-28 10:37   ` Lancelot SIX [this message]
2024-03-28 23:03     ` Tom Tromey
2024-03-30 16:47       ` Six, Lancelot

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=20240328103632.7iljwbcnjm55rkgd@khazad-dum \
    --to=lancelot.six@amd.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.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