public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 2/7] Change handling of DW_TAG_enumeration_type in DWARF scanner
Date: Mon, 08 Apr 2024 15:11:38 -0600	[thread overview]
Message-ID: <20240408-die-map-madness-v2-2-6741626d544d@tromey.com> (raw)
In-Reply-To: <20240408-die-map-madness-v2-0-6741626d544d@tromey.com>

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.
---
 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 7b306d8594c..b54b381aef3 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16469,6 +16469,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
@@ -16531,15 +16537,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:

-- 
2.43.0


  parent reply	other threads:[~2024-04-08 21:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08 21:11 [PATCH gdb/symtab v2 0/7] Compute DWARF entry parents across CUs Tom Tromey
2024-04-08 21:11 ` [PATCH gdb/symtab v2 1/7] Refactor condition in scan_attributes Tom Tromey
2024-04-08 21:11 ` Tom Tromey [this message]
2024-04-08 21:11 ` [PATCH v2 3/7] Add move operators for addrmap Tom Tromey
2024-04-08 21:11 ` [PATCH v2 4/7] Introduce class parent_map for DIE range map Tom Tromey
2024-04-08 21:11 ` [PATCH v2 5/7] Correctly handle DIE parent computations Tom Tromey
2024-04-08 21:11 ` [PATCH gdb/testsuite v2 6/7] Add gdb.dwarf2/forward-spec-inter-cu.exp Tom Tromey
2024-04-08 21:11 ` [PATCH gdb/testsuite v2 7/7] Add gdb.dwarf2/backward-spec-inter-cu.exp Tom Tromey
2024-04-16 17:54 ` [PATCH gdb/symtab v2 0/7] Compute DWARF entry parents across CUs Tom Tromey

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=20240408-die-map-madness-v2-2-6741626d544d@tromey.com \
    --to=tom@tromey.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).