[06/13,gdb/symtab] Add debug_handle_deferred_entries

Message ID 20231002125051.29911-7-tdevries@suse.de
State Superseded
Headers
Series Fix gdb.cp/breakpoint-locs.exp |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Testing failed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Tom de Vries Oct. 2, 2023, 12:50 p.m. UTC
  Add a const bool debug_handle_deferred_entries, defaulting to false, that
allows us to easily debug the handling of deferred entries.

Example output:
...
(gdb) file forward-spec^M
Reading symbols from forward-spec...^M
  0x00000000000000dd 0x7f0044002ed0 (0xdc)^M
  0x00000000000000e8 0x0^M
Resolve deferred: 0xca -> 0xe0: 0xdc^M
...

This tells us that to find the parent of DIE 0xca, we lookup the parent of DIE
0xe0 in the parent map, which is 0xdc.

Tested on x86_64-linux.
---
 gdb/dwarf2/read.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
  

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 54097dd4d21..23de6714268 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -4837,11 +4837,26 @@  class cooked_indexer
     m_deferred_entries.push_back (de);
   }
 
+  /* Set to true to debug handling of deferred entries.  */
+  const bool debug_handle_deferred_entries = false;
+
   /* Create a cooked_index_entry corresponding to deferred_entry DE with
      parent PARENT_ENTRY.  */
   const cooked_index_entry *resolve_deferred_entry
     (const deferred_entry &de, const cooked_index_entry *parent_entry)
   {
+    if (debug_handle_deferred_entries)
+      {
+	gdb_printf (gdb_stdlog,
+		    "Resolve deferred: 0x%" PRIx64 " -> 0x%lx: ",
+		    to_underlying (de.die_offset),
+		    de.spec_offset);
+	if (parent_entry == nullptr)
+	  gdb_printf (gdb_stdlog, "no parent\n");
+	else
+	  gdb_printf (gdb_stdlog, "0x%" PRIx64 "\n",
+		      to_underlying (parent_entry->die_offset));
+      }
     return m_index_storage->add (de.die_offset, de.tag, de.flags, de.name,
 				 parent_entry, m_per_cu);
   }
@@ -4849,6 +4864,9 @@  class cooked_indexer
   /* Create cooked_index_entries for the deferred entries.  */
   void handle_deferred_entries ()
   {
+    if (debug_handle_deferred_entries)
+      m_die_range_map.dump ();
+
     for (const auto &entry : m_deferred_entries)
       {
 	const cooked_index_entry *parent_entry