From: Andrew Burgess <aburgess@redhat.com>
To: Simon Marchi <simon.marchi@efficios.com>, gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: Re: [PATCH 1/2] gdb: split cooked index finalization into separate steps
Date: Thu, 24 Sep 2026 11:16:20 +0100 [thread overview]
Message-ID: <877bkb2buz.fsf@redhat.com> (raw)
In-Reply-To: <20260924050002.1539783-2-simon.marchi@efficios.com>
Simon Marchi <simon.marchi@efficios.com> writes:
> This patch refactors the existing cooked index "finalize" step into
> multiple steps. This is a preparatory patch for the following patch,
> which will add some more steps. I believe that using this pattern will
> help keep the code readable and easy to understand, despite the
> increasing amount of work done.
>
> The following patch introduces a step that needs to run after the
> deferred parents have been resolved, but before the name
> canonicalization happens, so factor out the deferred parents code into a
> step of its own.
>
> The code that remains in cooked_index_shard::finalize is all about name
> canonicalization (if we consider the Ada stuff to be a special case of
> that), so rename that step to cooked_index_shard::canonicalize_names().
>
> For clarity, move the "write to cache" code out of the "done" callback
> to make it clear that it is logically a separate step.
>
> So as of this patch, we have the steps:
>
> - resolve deferred parents
> - canonicalize names
> - write to cache
>
> The term "finalization" now refers to all these steps. Or, depending on
> your definition, it could refer to all but "write to cache", since the
> index reaches the FINALIZED state (i.e. becomes fully usable) just
> before that one.
>
> Here are the implementation details:
>
> - The first step is called by cooked_index::set_contents(), then each
> step is responsible for calling the next one (thus forming a chain),
> until we are done.
>
> - Steps that involve per-shard parallel processing use gdb::task_group,
> the "done" callback of the task_group starts the next task.
>
> A special case of that is: if some steps are able to detect ahead of
> time that it's unnecessary to run the step for a given shard, they
> can omit adding a task for that shard.
>
> An even more special case of that is: if no tasks are added to a task
> group, the "done" callback for that task group is invoked
> immediately when the group is started. This allows easily and
> cheaply skipping entire steps when they are not needed.
>
> This is used in this patch for the new "resolve deferred parents"
> step. Each shard records whether it has at least one deferred parent
> during the initial scan. If a shard has none (which is a common
> case), then cooked_index_shard::resolve_deferred_parents would
> iterate the index entries for nothing. The step therefore omits
> adding a task for that shard in that case. If no shards have any
> deferred parents that require resolving, we go directly to the next
> step with very little cost.
>
> During review, Claude pointed out that my change actually fixes a
> potential problem. The current code resolves the deferred parent of an
> entry in the same loop where it potentially calls "full_name" for that
> entry (to create the special Ada entries). "full_name" walks up the
> parent chain, and thus requires all grand-parents to be resolved.
> Depending on the order of DIEs in the file, it might not be true.
> Having the "resolve deferred parents" step run completely before the
> name canonicalization step avoids this.
>
> I built a gdb.dwarf2 test case around the DWARF structure it proposed to
> hit the bug. It is perhaps not something we expect from real-world
> producers, but it's also not completely unthinkable. It hits this
> assert when the patch is not applied:
>
> gdb/dwarf2/cooked-index-entry.h:217: internal-error: get_parent: Assertion `(flags & IS_PARENT_DEFERRED) == 0' failed.
>
> ... and passes with it.
Simon,
Thanks for doing this. My reworked series (unposted) had a patch just
like this, but your addition of the new test is a bonus I didn't have,
so I think yours is better. I only had one minor suggestion from my
take on this change, see below...
> +
> +void
> +cooked_index_shard::canonicalize_names ()
> {
> gdb::unordered_set<const cooked_index_entry *,
> cooked_index_entry_name_ptr_hash,
> @@ -216,13 +236,6 @@ cooked_index_shard::finalize (const parent_map_map *parent_maps)
>
> for (cooked_index_entry *entry : m_entries)
> {
> - if ((entry->flags & IS_PARENT_DEFERRED) != 0)
> - {
> - const cooked_index_entry *new_parent
> - = parent_maps->find (entry->get_deferred_parent ());
> - entry->resolve_parent (new_parent);
> - }
> -
I replaced this block with:
/* Deferred parents should not reach this point. */
gdb_assert ((entry->flags & IS_PARENT_DEFERRED) == 0);
I think the assert is worth keeping. With that:
Approved-By: Andrew Burgess <aburgess@redhat.com>
Thanks,
Andrew
next prev parent reply other threads:[~2026-09-24 10:16 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 10:03 [PATCH] [GDB 18] gdb: resolve class name via DW_AT_signature in cooked index 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
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
2026-09-22 4:26 ` Simon Marchi
2026-09-23 13:47 ` Simon Marchi
2026-09-24 4:59 ` [PATCH 0/2] " Simon Marchi
2026-09-24 5:05 ` Simon Marchi
2026-09-24 15:09 ` [PATCH v6 0/3] gdb/dwarf: " Simon Marchi
2026-09-24 15:09 ` [PATCH v6 1/3] gdb/dwarf: split cooked index finalization into separate steps Simon Marchi
2026-09-24 15:09 ` [PATCH v6 2/3] gdb/dwarf: resolve class name via DW_AT_signature in cooked index Simon Marchi
2026-09-24 15:09 ` [PATCH v6 3/3] gdb/dwarf: add cooked_index_entry::parent_is_deferred Simon Marchi
2026-09-24 20:53 ` Andrew Burgess
2026-09-25 2:34 ` Simon Marchi
2026-09-24 4:59 ` [PATCH 1/2] gdb: split cooked index finalization into separate steps Simon Marchi
2026-09-24 10:16 ` Andrew Burgess [this message]
2026-09-24 14:24 ` Simon Marchi
2026-09-24 4:59 ` [PATCH 2/2] gdb: resolve class name via DW_AT_signature in cooked index Simon Marchi
2026-09-24 10:39 ` Andrew Burgess
2026-09-24 15:07 ` Simon Marchi
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=877bkb2buz.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.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