From: Tom Tromey Date: Wed, 15 Apr 2026 19:11:31 +0000 (-0600) Subject: Return void from buildsym_compunit::push_context X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=844e25c38fd038ce40ddaf4fd33b5e75ea23539e;p=thirdparty%2Fbinutils-gdb.git 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 --- 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)