]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use scoped_restore for dwarf2_cu::list_in_scope
authorTom Tromey <tromey@adacore.com>
Wed, 15 Apr 2026 17:11:29 +0000 (11:11 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 20 Apr 2026 14:23:15 +0000 (08:23 -0600)
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 <simon.marchi@efficios.com>
gdb/dwarf2/cu.h
gdb/dwarf2/read.c

index 9b90415ed64d03adefb6d986f26c25bc68f03497..5157c6b8fa1b6ebf1ae0f4f43894395505ac796b 100644 (file)
@@ -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
index 48e89d10eac781ed5dd217ea60d182fc2bd77fad..beb1a440f1b3b9adab5cca40789c22741e262b8c 100644 (file)
@@ -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