]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/symtab] Dump m_all_parents_map for verbose debug dwarf-read
authorTom de Vries <tdevries@suse.de>
Sat, 28 Sep 2024 06:35:02 +0000 (08:35 +0200)
committerTom de Vries <tdevries@suse.de>
Sat, 28 Sep 2024 06:35:02 +0000 (08:35 +0200)
[ This is based on "[gdb/symtab] Add parent_map::dump" [1]. ]

When building the cooked index, gdb builds up a parent map.

This map is currently only visible at user level through the effect of using
it, but it's useful to be able to inspect it as well.

Add dumping of this parent map for "set debug dwarf-read 2".

As example, take test-case gdb.dwarf2/enum-type-c++.exp with target board
debug-types.

The parent map looks like:
...
$ gdb -q -batch \
    -iex "maint set worker-threads 0" \
    -iex "set debug dwarf-read 2" \
    outputs/gdb.dwarf2/enum-type-c++/enum-type-c++
  ...
[dwarf-read] print_stats: Final m_all_parents_map:
map start:
  0x0000000000000000 0x0
  0x0000000000000037 0x20f27d30 (0x36: ec)
  0x0000000000000051 0x0
  0x000000000000008b 0x20f27dc0 (0x8a: A)
  0x00000000000000a6 0x0
...

There's no parent entry at address 0xd6, which is part of what causes this:
...
(gdb) FAIL: gdb.dwarf2/enum-type-c++.exp: val1 has a parent
...

With the series containing the proposed fix applied [2], we get instead:
...
[dwarf-read] print_stats: Final m_all_parents_map:
map start:
  0x0000000000000000 0x0
  0x0000000000000026 0x7e0bdc0 (0x25: ns)
  0x0000000000000036 0x0
  0x0000000000000037 0x7e0bdf0 (0x36: ns::ec)
  0x0000000000000051 0x0
  0x000000000000007f 0x7e0be80 (0x7e: ns)
  0x000000000000008a 0x0
  0x000000000000008b 0x7e0beb0 (0x8a: ns::A)
  0x00000000000000a6 0x0
  0x00000000000000cc 0x7e0bf10 (0xcb: ns)
  0x00000000000000d4 0x7e0bf40 (0xd3: ns::A)
  0x00000000000000dc 0x7e0bf10 (0xcb: ns)
  0x00000000000000dd 0x7e0bf40 (0xd3: ns::A)
  0x00000000000000f6 0x0
...
and find at 0xd6 parent ns::A.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
[1] https://sourceware.org/pipermail/gdb-patches/2023-October/202883.html
[2] https://sourceware.org/pipermail/gdb-patches/2024-September/211958.html

gdb/addrmap.c
gdb/addrmap.h
gdb/dwarf2/parent-map.h
gdb/dwarf2/read.c

index b9a0f77d5d0b8f5a791e36598e1f3236bbf89b2c..696a7dc1b2af13cd4d23205936a76d1bb3daf126 100644 (file)
@@ -354,7 +354,9 @@ addrmap_mutable::~addrmap_mutable ()
 /* See addrmap.h.  */
 
 void
-addrmap_dump (struct addrmap *map, struct ui_file *outfile, void *payload)
+addrmap_dump (struct addrmap *map, struct ui_file *outfile, void *payload,
+             gdb::function_view<void (struct ui_file *outfile,
+                                      const void *value)> annotate_value)
 {
   /* True if the previously printed addrmap entry was for PAYLOAD.
      If so, we want to print the next one as well (since the next
@@ -373,10 +375,16 @@ addrmap_dump (struct addrmap *map, struct ui_file *outfile, void *payload)
       addr_str = "<ends here>";
 
     if (matches || previous_matched)
-      gdb_printf (outfile, "  %s%s %s\n",
-                 payload != nullptr ? "  " : "",
-                 core_addr_to_string (start_addr),
-                 addr_str);
+      {
+       gdb_printf (outfile, "  %s%s %s",
+                   payload != nullptr ? "  " : "",
+                   core_addr_to_string (start_addr),
+                   addr_str);
+       if (annotate_value != nullptr)
+         annotate_value (outfile, obj);
+
+       gdb_printf (outfile, "\n");
+      }
 
     previous_matched = matches;
 
index abd1ee3d95f64f9290dc5f8b0ae371aa58d23c49..85d46452c2a06be36e746e336d5ed5b63f577abd 100644 (file)
@@ -219,8 +219,13 @@ private:
 
 /* Dump the addrmap to OUTFILE.  If PAYLOAD is non-NULL, only dump any
    components that map to PAYLOAD.  (If PAYLOAD is NULL, the entire
-   map is dumped.)  */
+   map is dumped.)  If ANNOTATE_VALUE is non-nullptr, call it for each
+   value.  */
+
 void addrmap_dump (struct addrmap *map, struct ui_file *outfile,
-                  void *payload);
+                  void *payload,
+                  gdb::function_view<void (struct ui_file *outfile,
+                                           const void *value)>
+                    annotate_value = nullptr);
 
 #endif /* ADDRMAP_H */
index 5307d4df45b74c93f51eb2e4d9a4de1d291152ff..6cff548a2a71f251332795a3e99262df4bb8c12d 100644 (file)
@@ -104,6 +104,9 @@ public:
     return new (obstack) addrmap_fixed (obstack, &m_map);
   }
 
+  /* Dump a human-readable form of this map.  */
+  void dump () const;
+
 private:
 
   /* An addrmap that maps from section offsets to cooked_index_entry *.  */
@@ -141,6 +144,9 @@ public:
     return nullptr;
   }
 
+  /* Dump a human-readable form of this collection of parent_maps.  */
+  void dump () const;
+
 private:
 
   /* Storage for the convert maps.  */
index 193a52ef6e07d54b061058f9d0733f6a19f9905d..749e39df1756bf03a468f5a24489e8ba14afec42 100644 (file)
@@ -4449,6 +4449,50 @@ cooked_index_storage::eq_cutu_reader (const void *a, const void *b)
   return ra->cu->per_cu->index == *rb;
 }
 
+/* Dump MAP as parent_map.  */
+
+static void
+dump_parent_map (const struct addrmap *map)
+{
+  auto_obstack temp_storage;
+
+  auto annotate_cooked_index_entry
+    = [&] (struct ui_file *outfile, const void *value)
+       {
+         const cooked_index_entry *parent_entry
+           = (const cooked_index_entry *)value;
+         if (parent_entry == nullptr)
+           return;
+
+         gdb_printf (outfile, " (0x%" PRIx64 ": %s)",
+                     to_underlying (parent_entry->die_offset),
+                     parent_entry->full_name (&temp_storage, false));
+       };
+
+  addrmap_dump (const_cast<addrmap *> (map), gdb_stdlog, nullptr,
+               annotate_cooked_index_entry);
+}
+
+/* See parent-map.h.  */
+
+void
+parent_map::dump () const
+{
+  dump_parent_map (&m_map);
+}
+
+/* See parent-map.h.  */
+
+void
+parent_map_map::dump () const
+{
+  for (const auto &iter : m_maps)
+    {
+      gdb_printf (gdb_stdlog, "map start:\n");
+      dump_parent_map (iter);
+    }
+}
+
 /* An instance of this is created to index a CU.  */
 
 class cooked_indexer
@@ -4841,6 +4885,11 @@ private:
   {
     if (dwarf_read_debug > 0)
       print_tu_stats (m_per_objfile);
+    if (dwarf_read_debug > 1)
+      {
+       dwarf_read_debug_printf_v ("Final m_all_parents_map:");
+       m_all_parents_map.dump ();
+      }
   }
 
   /* After the last DWARF-reading task has finished, this function