From: Andrew Burgess <aburgess@redhat.com>
To: Simon Marchi <simark@simark.ca>, Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCHv3] gdb: resolve class name via DW_AT_signature in cooked index
Date: Wed, 16 Sep 2026 12:45:53 +0100 [thread overview]
Message-ID: <87wlslbery.fsf@redhat.com> (raw)
In-Reply-To: <8ff7fcd2-f79c-48fc-9730-fbaf4dc17ec3@simark.ca>
Simon Marchi <simark@simark.ca> writes:
> On 2026-09-15 11:01, Tom Tromey wrote:
>>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
>>
>>>> We would have to delete the name-less entries, and any child
>>>> entry that refers to them, not sure how to do that efficiently though.
>>
>> Andrew> This is the problem I'm currently trying to solve.
>>
>> Andrew> The problem with this approach is that the parent might be from another
>> Andrew> shard, potentially resolved due to the IS_PARENT_DEFERRED flag from the
>> Andrew> parent map. The race is on the read of the parent's name field, the
>> Andrew> parent might appear nameless, but it might in fact be the case that the
>> Andrew> name hasn't been assigned yet.
>>
>> Andrew> The other possibility is that, because this is an error case, we could
>> Andrew> have a serial action that cleans up the mess, deleting child entries
>> Andrew> with nameless parents. This would be done in
>> Andrew> cooked_index::set_contents, as part of this code:
>>
>> Right now your patch is fixing up these entries in parallel, in each
>> shard. But if this is uncommon enough, it could be done in
>> cooked_index::set_contents instead, say when setting up the finalizer
>> tasks:
>>
>> for (auto &shard : m_shards)
>> {
>> auto this_shard = shard.get ();
>> const parent_map_map *parent_maps = m_state->get_parent_map_map ();
>> ... signature->entry lookup here
>>
>> Then entries could be filtered out in cooked_index_shard::finalize if
>> they have a "bad" parent somewhere in their "parent" chain.
>
> Having a bad parent is rare, that would only happen when some
> (nameless) type has a DW_AT_signature and the matching type unit can't
> be found. That would be a buggy producer that "forgets" to add the
> necessary type units.
>
> But the basic case where the name fixup is needed isn't an error case,
> it's just what happens when using clang with -fdebug-types-section,
> since structures/classes are nameless:
>
> 0x0000099e: DW_TAG_structure_type
> DW_AT_declaration [DW_FORM_flag_present] (true)
> DW_AT_signature [DW_FORM_ref_sig8] (0xdf1329ababfff8ca)
>
> So I suppose you'll get one fixup to do per structure/class type.
>
> Doing the fixups in parallel is easy, since it's just looking up the
> signature -> maps, and the "finalize" step already exists, so why not.
>
>>
>> I'm not sure if this would work or not. TBH I find all this stuff in
>> DWARF pretty maddening and also difficult to reason about. Like, even
>> constructing the case you are talking about seems very tricky, seeing
>> that it has to involve type signatures and somehow also cross-CU parent
>> references.
>>
>> A different option might be to ignore such entries at lookup time. That
>> is, let the child entries stay in the vector and just skip them in the
>> relevant lookup loops. My intuition generally is that DWARF reading is
>> slow and user-visible, as is CU expansion -- but the lookups themselves
>> are not.
>
>>
>> This would probably just mean touching the index writers and
>> cooked_index_functions::search. Perhaps the bad entries themselves (an
>> entry with a signature that couldn't be found) could simply not appear
>> in the shard vector, to avoid problems with their anonymity.
>>
>> In cooked_index_functions::search you could just stick a check here:
>>
>> if (!entry->matches (search_flags)
>> || !entry->matches (domain))
>> continue;
>>
>> Like "entry->valid () || ..."
>
> This was our earlier suggestion. Leave the name nullptr (or set a flag,
> whatever), marking them as invalid. When you need to compute the full
> name of an entry, you walk up the parent chain. If one of those parents
> is invalid, bail out. You can't correctly an entry's full name if the
> name of a parent is missing, as simple as that. And then you have to
> handle invalid entries in a few other locations (like
> cooked_index_functions::search and the index writers, as you said), but
> it shouldn't be too bad. That sounds simpler than trying to remove the
> entries.
I've just posted v4. The approach taken there is to orphan entries that
have an invalid parent during finalization. After that I just let
things play out as they will. This means that something that should be
'the_type::method' will be added to the index as just 'method' IFF the
DWARF for 'the_type' is broken such that the signature based lookup for
'the_type' fails.
I think this is the same result as you've get by leaving the bad entries
around (i.e. linked via the parent pointer) and just bailing out when
trying to build the full name.
At the end of the day, if the DWARF is bad then anything we come up with
is not ideal. I guess the gold standard would be to remove the bad
entry and all its (grand-)*children, but that's super expensive, and
doesn't seem worth the hassle for something that should never happen.
Anyway, you'll need to check out v4 and let me know what you think.
Thanks,
Andrew
next prev parent reply other threads:[~2026-09-16 11:46 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 10:03 [PATCH] [GDB 18] " Andrew Burgess
2026-08-21 17:07 ` Tom Tromey
2026-08-28 21:30 ` [PATCHv2] " Andrew Burgess
2026-09-01 13:31 ` [PATCHv3] " Andrew Burgess
2026-09-10 16:11 ` Simon Marchi
2026-09-11 19:18 ` Tom Tromey
2026-09-12 2:06 ` Simon Marchi
2026-09-14 13:23 ` Andrew Burgess
2026-09-14 14:57 ` Simon Marchi
2026-09-14 15:38 ` Tom Tromey
2026-09-15 10:25 ` Andrew Burgess
2026-09-15 15:01 ` Tom Tromey
2026-09-15 15:55 ` Simon Marchi
2026-09-15 17:21 ` Simon Marchi
2026-09-16 11:40 ` Andrew Burgess
2026-09-16 11:45 ` Andrew Burgess [this message]
2026-09-16 11:48 ` Andrew Burgess
2026-09-14 15:36 ` Tom Tromey
2026-09-10 16:18 ` Simon Marchi
2026-09-16 11:38 ` [PATCHv4] " Andrew Burgess
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=87wlslbery.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
--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