From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 4/6] Change pop_context to return a block
Date: Fri, 17 Apr 2026 16:11:21 -0400 [thread overview]
Message-ID: <b5e8ecc3-5ea5-46fa-9424-4c9230ff0945@simark.ca> (raw)
In-Reply-To: <20260417-list-in-scope-v1-4-0deb050fc03d@adacore.com>
On 4/17/26 2:24 PM, Tom Tromey wrote:
> This changes buildsym_compunit::pop_context to create and return the
> block, if needed. It also arranges to reset some fields in the
> buildsym_compunit object to their saved values.
>
> This also enables the removal of the set_local_using_directives
> method.
> ---
> gdb/buildsym.c | 29 +++++++++++++++++------------
> gdb/buildsym.h | 15 +++++++++------
> gdb/dwarf2/read.c | 55 ++++++++++++++++++-------------------------------------
> 3 files changed, 44 insertions(+), 55 deletions(-)
>
> diff --git a/gdb/buildsym.c b/gdb/buildsym.c
> index 6d719cb25a0..592bcf8bcf0 100644
> --- a/gdb/buildsym.c
> +++ b/gdb/buildsym.c
> @@ -629,13 +629,7 @@ buildsym_compunit::end_compunit_symtab_get_static_block (CORE_ADDR end_addr,
> the context stack. */
>
> if (!m_context_stack.empty ())
> - {
> - struct context_stack cstk = pop_context ();
> -
> - /* Make a block for the local symbols within. */
> - finish_block (cstk.name, cstk.old_blocks, NULL,
> - cstk.start_addr, end_addr);
> - }
> + pop_context (end_addr);
> gdb_assert (m_context_stack.empty ());
>
> /* Executables may have out of order pending blocks; sort the
> @@ -949,14 +943,25 @@ buildsym_compunit::push_context (CORE_ADDR valu)
> return ctx;
> }
>
> -/* Pop a context block. Returns the address of the context block just
> - popped. */
> +/* See buildsym.h. */
>
> -context_stack
> -buildsym_compunit::pop_context ()
> +block *
> +buildsym_compunit::pop_context (CORE_ADDR end_addr,
> + const struct dynamic_prop *static_link,
> + bool required)
> {
> gdb_assert (!m_context_stack.empty ());
> - context_stack result = m_context_stack.back ();
> + context_stack cstk = m_context_stack.back ();
> m_context_stack.pop_back ();
A nit about pre-existing code, but I think that we could std::move the
result of `.back ()`:
context_stack cstk = std::move (m_context_stack.back ());
> + block *result = nullptr;
> + if (required || !m_local_symbols.empty ()
> + || m_local_using_directives != nullptr)
> + result = finish_block (cstk.name, cstk.old_blocks, static_link,
> + cstk.start_addr, end_addr);
> +
> + m_local_symbols = std::move (cstk.locals);
> + m_local_using_directives = cstk.local_using_directives;
My understanding is that the "current" locals and local_using_directives
vectors are not held in m_context_stack, they are held in these
m_local_symbols and m_local_using_directives fields. An entry in
m_context_stack is a saved context, to be restored later. I wonder if
it would simplify the code if we removed m_local_symbols and
m_local_using_directives, and said that the topmost m_context_stack
entry holds the current locals and local_using_directives. That would
mean pushing an initial context_stack entry for the global scope, I
guess?
We wouldn't need moving in and out of m_local_symbols and
m_local_using_directives anymore. I don't think it would simplify that
much in terms of number of lines, but it might make the code a bit
easier to follow. Just something to explore, I think this patch is
good.
Simon
next prev parent reply other threads:[~2026-04-17 20:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-17 18:24 [PATCH 0/6] Some buildsym cleanups Tom Tromey
2026-04-17 18:24 ` [PATCH 1/6] Use scoped_restore for dwarf2_cu::list_in_scope Tom Tromey
2026-04-17 18:24 ` [PATCH 2/6] Remove some dead code from buildsym.c Tom Tromey
2026-04-17 20:10 ` Simon Marchi
2026-04-17 18:24 ` [PATCH 3/6] Remove context_stack::depth Tom Tromey
2026-04-17 18:24 ` [PATCH 4/6] Change pop_context to return a block Tom Tromey
2026-04-17 20:11 ` Simon Marchi [this message]
2026-04-17 18:24 ` [PATCH 5/6] Return void from buildsym_compunit::push_context Tom Tromey
2026-04-17 20:22 ` Simon Marchi
2026-04-17 18:24 ` [PATCH 6/6] Rename context_stack and make it private Tom Tromey
2026-04-17 20:24 ` [PATCH 0/6] Some buildsym cleanups 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=b5e8ecc3-5ea5-46fa-9424-4c9230ff0945@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=tromey@adacore.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