Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 1/6] Use scoped_restore for dwarf2_cu::list_in_scope
Date: Fri, 17 Apr 2026 12:24:03 -0600	[thread overview]
Message-ID: <20260417-list-in-scope-v1-1-0deb050fc03d@adacore.com> (raw)
In-Reply-To: <20260417-list-in-scope-v1-0-0deb050fc03d@adacore.com>

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.
---
 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 @@ struct dwarf2_cu
   /* 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 4035bba6e45..ebf7eeb673b 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7478,9 +7478,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
@@ -7629,8 +7628,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);
 }
@@ -7826,7 +7823,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 ())
     {
@@ -7912,11 +7911,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

-- 
2.53.0


  reply	other threads:[~2026-04-17 18:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-17 18:24 [PATCH 0/6] Some buildsym cleanups Tom Tromey
2026-04-17 18:24 ` Tom Tromey [this message]
2026-04-17 18:24 ` [PATCH 2/6] Remove some dead code from buildsym.c Tom Tromey
2026-04-17 20:10   ` Simon Marchi
2026-04-17 18:24 ` [PATCH 3/6] Remove context_stack::depth Tom Tromey
2026-04-17 18:24 ` [PATCH 4/6] Change pop_context to return a block Tom Tromey
2026-04-17 20:11   ` Simon Marchi
2026-04-17 18:24 ` [PATCH 5/6] Return void from buildsym_compunit::push_context Tom Tromey
2026-04-17 20:22   ` Simon Marchi
2026-04-17 18:24 ` [PATCH 6/6] Rename context_stack and make it private Tom Tromey
2026-04-17 20:24 ` [PATCH 0/6] Some buildsym cleanups Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260417-list-in-scope-v1-1-0deb050fc03d@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox