public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Change handling of DW_TAG_enumeration_type in DWARF scanner
@ 2024-04-16 17:55 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2024-04-16 17:55 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4e417d7bb1c7d8b8a73b73b0b7c051f0a6e1b6b6

commit 4e417d7bb1c7d8b8a73b73b0b7c051f0a6e1b6b6
Author: Tom Tromey <tom@tromey.com>
Date:   Fri Jan 12 18:01:00 2024 -0700

    Change handling of DW_TAG_enumeration_type in DWARF scanner
    
    Currently the DWARF scanner will enter enumeration constants into the
    same namespace as the DW_TAG_enumeration_type itself.  This is the
    right thing to do, but the implementation may result in strange
    entries being added to the addrmap that maps DIE ranges to entries.
    
    This came up when debugging an earlier version of this series; and
    while I don't think this should impact the current series, it seems
    better to clean this up anyway.
    
    In the new code, rather than pass the "wrong" scope down through
    recursive calls to the scanner, the correct scope is always passed,
    and then the parent handling is done when creating the enumerator
    entry.

Diff:
---
 gdb/dwarf2/read.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 4c97fe12307..b7e04a1ebf3 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16468,6 +16468,12 @@ cooked_indexer::index_dies (cutu_reader *reader,
 	  flags &= ~IS_STATIC;
 	  flags |= parent_entry->flags & IS_STATIC;
 	}
+      /* If the parent is an enum, but not an enum class, then use the
+	 grandparent instead.  */
+      if (this_parent_entry != nullptr
+	  && this_parent_entry->tag == DW_TAG_enumeration_type
+	  && !is_enum_class)
+	this_parent_entry = this_parent_entry->get_parent ();
 
       if (abbrev->tag == DW_TAG_namespace
 	  && m_language == language_cplus
@@ -16530,15 +16536,7 @@ cooked_indexer::index_dies (cutu_reader *reader,
 	      break;
 
 	    case DW_TAG_enumeration_type:
-	      /* We need to recurse even for an anonymous enumeration.
-		 Which scope we record as the parent scope depends on
-		 whether we're reading an "enum class".  If so, we use
-		 the enum itself as the parent, yielding names like
-		 "enum_class::enumerator"; otherwise we inject the
-		 names into our own parent scope.  */
-	      info_ptr = recurse (reader, info_ptr,
-				  is_enum_class ? this_entry : parent_entry,
-				  fully);
+	      info_ptr = recurse (reader, info_ptr, this_entry, fully);
 	      continue;
 
 	    case DW_TAG_module:

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-16 17:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-16 17:55 [binutils-gdb] Change handling of DW_TAG_enumeration_type in DWARF scanner Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).