]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Return void from buildsym_compunit::push_context
authorTom Tromey <tromey@adacore.com>
Wed, 15 Apr 2026 19:11:31 +0000 (13:11 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 20 Apr 2026 14:23:16 +0000 (08:23 -0600)
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 <simon.marchi@efficios.com>
gdb/buildsym.c
gdb/buildsym.h
gdb/dwarf2/read.c

index 733d6c7f0dd1ade7dfa055238879468a9d0e5a6d..0ef1ea1cc2e3d645099a6af2fc4366e42598aeca 100644 (file)
@@ -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.  */
index d1199735abbe7c9bfa2195d0776dc082d35d5d37..02c411b053d325bd88c449ffbca5eee919872060 100644 (file)
@@ -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,
index 1c4173eb44d64833f865cb37174ccfeb00dcfd6c..0c95a582e7ffc9b95a04375740b8a81aebb2348c 100644 (file)
@@ -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)