From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 6/6] Rename context_stack and make it private
Date: Fri, 17 Apr 2026 12:24:08 -0600 [thread overview]
Message-ID: <20260417-list-in-scope-v1-6-0deb050fc03d@adacore.com> (raw)
In-Reply-To: <20260417-list-in-scope-v1-0-0deb050fc03d@adacore.com>
"context_stack" has been misnamed at least since the storage was
changed to a std::vector, and arguably even since the very beginning.
This patch renames it to "lexical_context", which is a bit closer to
what is is for.
This type is also no longer used outside of buildsym itself -- callers
can now push and pop contexts, but they don't act on the context
object itself. So, the type is made private.
One benefit of this approach is that callers no longer need to be
quite as careful -- previously there was at least a possibility that a
context object pointer would be invalidated when pushing and popping
the stack.
---
gdb/buildsym.c | 2 +-
gdb/buildsym.h | 60 +++++++++++++++++++++++++++++-----------------------------
2 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index f5cc7de324d..44621a4c776 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -947,7 +947,7 @@ buildsym_compunit::pop_context (CORE_ADDR end_addr,
bool required)
{
gdb_assert (!m_context_stack.empty ());
- context_stack cstk = m_context_stack.back ();
+ lexical_context cstk = m_context_stack.back ();
m_context_stack.pop_back ();
block *result = nullptr;
diff --git a/gdb/buildsym.h b/gdb/buildsym.h
index 02c411b053d..c9010665bce 100644
--- a/gdb/buildsym.h
+++ b/gdb/buildsym.h
@@ -68,35 +68,6 @@ struct subfile
using subfile_up = std::unique_ptr<subfile>;
-/* Stack representing unclosed lexical contexts (that will become
- blocks, eventually). */
-
-struct context_stack
-{
- context_stack (std::vector<symbol *> locals, using_direct *local_using_directives,
- pending_block *old_blocks, CORE_ADDR start_addr)
- : locals (std::move (locals)),
- local_using_directives (local_using_directives),
- old_blocks (old_blocks),
- start_addr (start_addr)
- {}
-
- /* Outer locals at the time we entered. */
- std::vector<symbol *> locals;
-
- /* Pending using directives at the time we entered. */
- using_direct *local_using_directives;
-
- /* Pointer into blocklist as of entry. */
- pending_block *old_blocks;
-
- /* Name of function, if any, defining context. */
- symbol *name = nullptr;
-
- /* PC where this context starts. */
- CORE_ADDR start_addr;
-};
-
/* Flags associated with a linetable entry. */
enum linetable_entry_flag : unsigned
@@ -340,9 +311,38 @@ struct buildsym_compunit
/* Global "using" directives. */
struct using_direct *m_global_using_directives = nullptr;
+ /* Unclosed lexical contexts (that will become blocks,
+ eventually). */
+ struct lexical_context
+ {
+ lexical_context (std::vector<symbol *> locals,
+ using_direct *local_using_directives,
+ pending_block *old_blocks, CORE_ADDR start_addr)
+ : locals (std::move (locals)),
+ local_using_directives (local_using_directives),
+ old_blocks (old_blocks),
+ start_addr (start_addr)
+ {}
+
+ /* Outer locals at the time we entered. */
+ std::vector<symbol *> locals;
+
+ /* Pending using directives at the time we entered. */
+ using_direct *local_using_directives;
+
+ /* Pointer into blocklist as of entry. */
+ pending_block *old_blocks;
+
+ /* Name of function, if any, defining context. */
+ symbol *name = nullptr;
+
+ /* PC where this context starts. */
+ CORE_ADDR start_addr;
+ };
+
/* The stack of contexts that are pushed by push_context and popped
by pop_context. */
- std::vector<struct context_stack> m_context_stack;
+ std::vector<lexical_context> m_context_stack;
struct subfile *m_current_subfile = nullptr;
--
2.53.0
next prev parent reply other threads:[~2026-04-17 18:25 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
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 ` Tom Tromey [this message]
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=20260417-list-in-scope-v1-6-0deb050fc03d@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/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