]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Entries from anon-struct.exp not in cooked index
authorTom Tromey <tom@tromey.com>
Sun, 19 Jan 2025 01:15:21 +0000 (18:15 -0700)
committerTom Tromey <tom@tromey.com>
Wed, 10 Sep 2025 22:05:27 +0000 (16:05 -0600)
g++ will sometimes use a typedef to give a name to an otherwise
anonymous type for linkage purposes.  gdb tries to handle this odd
scenario, which is enforced by anon-struct.exp.

It's difficult to detect this problem in the current tree, but the
cooked index does not include an entry for these DIEs.

This patch changes gdb to add these to the index.  This is needed by
subsequent changes in this series.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32519
Acked-By: Simon Marchi <simon.marchi@efficios.com>
gdb/dwarf2/cooked-index-shard.h
gdb/dwarf2/cooked-index-worker.h
gdb/dwarf2/cooked-indexer.c

index 925960b7ece276f24ce672dc341605b0985a4c28..3a8e34d437fab36d1c03c6b3b4e336c053120bc8 100644 (file)
@@ -48,6 +48,13 @@ public:
                           cooked_index_entry_ref parent_entry,
                           dwarf2_per_cu *per_cu);
 
+  /* Add a copy of NAME to the index.  Return a pointer to the
+     copy.  */
+  const char *add (std::string_view name)
+  {
+    return m_names.insert (name);
+  }
+
   /* Install a new fixed addrmap from the given mutable addrmap.  */
   void install_addrmap (addrmap_mutable *map)
   {
index 8b9766cddcbf1c58361d61ffebc9ca15de8deb84..bdbb5d92421fb8fce0d55fcd99ef06018ee1a9eb 100644 (file)
@@ -87,6 +87,13 @@ public:
                         name, parent_entry, per_cu);
   }
 
+  /* Add a copy of NAME to the index.  Return a pointer to the
+     copy.  */
+  const char *add (std::string_view name)
+  {
+    return m_shard->add (name);
+  }
+
   /* Install the current addrmap into the shard being constructed,
      then transfer ownership of the index to the caller.  */
   cooked_index_shard_up release_shard ()
index 31344d7fdaa373c1d976d8ab27540fa35765bac0..913ff77f8900f6baabc9a4678a3127d3b8bc377d 100644 (file)
@@ -21,6 +21,8 @@
 #include "dwarf2/cooked-index-worker.h"
 #include "dwarf2/error.h"
 #include "dwarf2/read.h"
+#include "cp-support.h"
+#include "demangle.h"
 
 /* See cooked-indexer.h.  */
 
@@ -561,6 +563,30 @@ cooked_indexer::index_dies (cutu_reader *reader,
          name = nullptr;
        }
 
+      /* An otherwise anonymous type might be given a name (via
+        typedef) for linkage purposes, and gdb tries to handle this
+        case.  See anon-struct.exp.  In this case, GCC will emit a
+        funny thing: a linkage name for the type, but in "type" form.
+        That is, it will not start with _Z.  */
+      if ((abbrev->tag == DW_TAG_class_type
+          || abbrev->tag == DW_TAG_structure_type
+          || abbrev->tag == DW_TAG_union_type)
+         && m_language == language_cplus
+         && name == nullptr
+         && linkage_name != nullptr)
+       {
+         gdb::unique_xmalloc_ptr<char> dem
+           = gdb_demangle (linkage_name, DMGL_GNU_V3 | DMGL_TYPES);
+         if (dem != nullptr)
+           {
+             /* We're only interested in the last component.  */
+             std::vector<std::string_view> split
+               = split_name (dem.get (), split_style::CXX);
+             name = m_index_storage->add (split.back ());
+             linkage_name = nullptr;
+           }
+       }
+
       cooked_index_entry *this_entry = nullptr;
       if (name != nullptr)
        {