[binutils-gdb] Use scoped_restore for dwarf2_cu::list_in_scope
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=208b2e7a23c484b476b1abc532b78cb22913bf5f commit 208b2e7a23c484b476b1abc532b78cb22913bf5f Author: Tom Tromey <[email protected]> Date: Wed Apr 15 11:11:29 2026 -0600 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 <[email protected]> Diff: --- gdb/dwarf2/cu.h | 7 +------ gdb/dwarf2/read.c | 16 +++++----------- 2 files changed, 6 insertions(+), 17 deletions(-) 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<symbol *> *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<symbol *> *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