[binutils-gdb] Return void from buildsym_compunit::push_context

Tom Tromey via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=844e25c38fd038ce40ddaf4fd33b5e75ea23539e

commit 844e25c38fd038ce40ddaf4fd33b5e75ea23539e
Author: Tom Tromey <[email protected]>
Date:   Wed Apr 15 13:11:31 2026 -0600

    Return void from buildsym_compunit::push_context
    
    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.
    
    Approved-By: Simon Marchi <[email protected]>

Diff:
---
 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 733d6c7f0dd..0ef1ea1cc2e 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -927,17 +927,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 1c4173eb44d..0c95a582e7f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7801,10 +7801,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 (),
@@ -7827,7 +7828,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 ())
     {
@@ -7866,7 +7867,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
@@ -15791,9 +15792,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)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.