From: Tom Tromey Date: Wed, 15 Apr 2026 17:11:29 +0000 (-0600) Subject: Use scoped_restore for dwarf2_cu::list_in_scope X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=208b2e7a23c484b476b1abc532b78cb22913bf5f;p=thirdparty%2Fbinutils-gdb.git Use scoped_restore for dwarf2_cu::list_in_scope Some functions in the DWARF reader temporarily set dwarf2_cu::list_in_scope and then reset it when returning. This patch changes these spots to use scoped_restore. Approved-By: Simon Marchi --- diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h index 9b90415ed64..5157c6b8fa1 100644 --- a/gdb/dwarf2/cu.h +++ b/gdb/dwarf2/cu.h @@ -309,12 +309,7 @@ public: /* The generic symbol table building routines have separate lists for file scope symbols and all all other scopes (local scopes). So we need to select the right one to pass to add_symbol_to_list(). - We do it by keeping a pointer to the correct list in list_in_scope. - - FIXME: The original dwarf code just treated the file scope as the - first local scope, and all other local scopes as nested local - scopes, and worked fine. Check to see if we really need to - distinguish these in buildsym.c. */ + We do it by keeping a pointer to the correct list in list_in_scope. */ std::vector *list_in_scope = nullptr; /* Storage for things with the same lifetime as this read-in diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 48e89d10eac..beb1a440f1b 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -7480,9 +7480,8 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) /* We're inheriting ORIGIN's children into the scope we'd put DIE's symbols in. */ - std::vector *origin_previous_list_in_scope - = origin_cu->list_in_scope; - origin_cu->list_in_scope = cu->list_in_scope; + scoped_restore save_scope = make_scoped_restore (&origin_cu->list_in_scope, + cu->list_in_scope); if (die->tag != origin_die->tag && !(die->tag == DW_TAG_inlined_subroutine @@ -7631,8 +7630,6 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) } } - origin_cu->list_in_scope = origin_previous_list_in_scope; - if (cu != origin_cu) compute_delayed_physnames (origin_cu); } @@ -7828,7 +7825,9 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) attr_to_dynamic_prop (attr, die, cu, static_link, cu->addr_type ()); } - cu->list_in_scope = &cu->get_builder ()->get_local_symbols (); + scoped_restore save_scope + = make_scoped_restore (&cu->list_in_scope, + &cu->get_builder ()->get_local_symbols ()); for (die_info *child_die : die->children ()) { @@ -7914,11 +7913,6 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) back to building a containing block's symbol lists. */ cu->get_builder ()->get_local_symbols () = std::move (cstk.locals); cu->get_builder ()->set_local_using_directives (cstk.local_using_directives); - - /* If we've finished processing a top-level function, subsequent - symbols go in the file symbol list. */ - if (cu->get_builder ()->outermost_context_p ()) - cu->list_in_scope = &cu->get_builder ()->get_file_symbols (); } /* Process all the DIES contained within a lexical block scope. Start