Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 5/6] Return void from buildsym_compunit::push_context
Date: Fri, 17 Apr 2026 12:24:07 -0600	[thread overview]
Message-ID: <20260417-list-in-scope-v1-5-0deb050fc03d@adacore.com> (raw)
In-Reply-To: <20260417-list-in-scope-v1-0-0deb050fc03d@adacore.com>

There is one caller that uses the result of
buildsym_compunit::push_context.  This patch changes this method to
return void and changes that spot to instead call a new methods on
buildsym_compunit.

This patch also removes the get_current_context_stack method in favor
of a new method that checks the exact condition needed by the one
caller.

This patch enables a subsequent cleanup; in particular now the
'context_stack' type isn't used outside of buildsym.
---
 gdb/buildsym.c    | 12 ++++--------
 gdb/buildsym.h    | 21 ++++++++++++++++-----
 gdb/dwarf2/read.c | 15 +++++++--------
 3 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 592bcf8bcf0..f5cc7de324d 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -930,17 +930,13 @@ buildsym_compunit::augment_type_symtab ()
 /* Push a context block.  VALU is the starting PC address of this
    context.  */
 
-context_stack &
+void
 buildsym_compunit::push_context (CORE_ADDR valu)
 {
-  context_stack &ctx
-    = m_context_stack.emplace_back (std::move (m_local_symbols),
-				    m_local_using_directives,
-				    m_pending_blocks, valu);
-
+  m_context_stack.emplace_back (std::move (m_local_symbols),
+				m_local_using_directives,
+				m_pending_blocks, valu);
   m_local_using_directives = nullptr;
-
-  return ctx;
 }
 
 /* See buildsym.h.  */
diff --git a/gdb/buildsym.h b/gdb/buildsym.h
index d1199735abb..02c411b053d 100644
--- a/gdb/buildsym.h
+++ b/gdb/buildsym.h
@@ -199,11 +199,22 @@ struct buildsym_compunit
     return m_context_stack.empty ();
   }
 
-  struct context_stack *get_current_context_stack ()
+  /* Return true if the lexical context currently being constructed
+     has a symbol, false otherwise.  */
+  bool current_context_has_function () const
   {
-    if (m_context_stack.empty ())
-      return nullptr;
-    return &m_context_stack.back ();
+    return (!m_context_stack.empty ()
+	    && m_context_stack.back ().name != nullptr);
+  }
+
+  /* Set the symbol on the lexical context currently being
+     constructed.  */
+  void set_current_context_function (symbol *fun)
+  {
+    gdb_assert (!m_context_stack.empty ());
+    gdb_assert (m_context_stack.back ().name == nullptr);
+    gdb_assert (fun != nullptr);
+    m_context_stack.back ().name = fun;
   }
 
   struct subfile *get_current_subfile ()
@@ -236,7 +247,7 @@ struct buildsym_compunit
     m_producer = producer;
   }
 
-  context_stack &push_context (CORE_ADDR valu);
+  void push_context (CORE_ADDR valu);
 
   /* Pop a context and create the corresponding block.  Returns the
      block.  END_ADDR is the final address of the block.  STATIC_LINK,
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 4447923ae3e..2a330655c48 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7799,10 +7799,11 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
 	}
     }
 
-  gdb_assert (cu->get_builder () != nullptr);
-  context_stack &ctx = cu->get_builder ()->push_context (lowpc);
+  buildsym_compunit *builder = cu->get_builder ();
+  gdb_assert (builder != nullptr);
+  builder->push_context (lowpc);
   symbol *func_sym = new_symbol (die, read_type_die (die, cu), cu, templ_func);
-  ctx.name = func_sym;
+  builder->set_current_context_function (func_sym);
 
   if (dwarf2_func_is_main_p (die, cu))
     set_objfile_main_name (objfile, func_sym->linkage_name (),
@@ -7825,7 +7826,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
 
   scoped_restore save_scope
     = make_scoped_restore (&cu->list_in_scope,
-			   &cu->get_builder ()->get_local_symbols ());
+			   &builder->get_local_symbols ());
 
   for (die_info *child_die : die->children ())
     {
@@ -7864,7 +7865,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
 	}
     }
 
-  block *block = cu->get_builder ()->pop_context (highpc, static_link);
+  block *block = builder->pop_context (highpc, static_link);
 
   /* For C++, set the block's scope.  */
   if ((cu->lang () == language_cplus
@@ -15785,9 +15786,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 	       pretend it's a local variable in that case so that the user can
 	       still see it.  */
 	    sym->set_domain (VAR_DOMAIN);
-	    struct context_stack *curr
-	      = cu->get_builder ()->get_current_context_stack ();
-	    if (curr != nullptr && curr->name != nullptr)
+	    if (cu->get_builder ()->current_context_has_function ())
 	      sym->set_is_argument (true);
 	    attr = dwarf2_attr (die, DW_AT_location, cu);
 	    if (attr != nullptr)

-- 
2.53.0


  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 ` Tom Tromey [this message]
2026-04-17 20:22   ` [PATCH 5/6] Return void from buildsym_compunit::push_context 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=20260417-list-in-scope-v1-5-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