]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: print DWARF CUs/TUs in "maint print objfiles"
authorSimon Marchi <simon.marchi@polymtl.ca>
Tue, 18 Feb 2025 19:31:28 +0000 (14:31 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 10 Mar 2025 20:09:02 +0000 (16:09 -0400)
This was useful to me, to debug some problems.

Before printing cooked index entries, print a list of CUs and TUs.  The
information printed for each is a bit arbitrary, I took a look at the
types and printed what seemed relevant.

An example of output for a CU:

    [0] ((dwarf2_per_cu_data *) 0x50f000007840)
    type:       DW_UT_compile
    offset:     0x0
    size:       0x1bff
    artificial: false
    GDB lang:   c++
    DWARF lang: DW_LANG_C_plus_plus

And for a TU:

    [2] ((signatured_type *) 0x511000040000)
    type:      DW_UT_type
    offset:    0x0
    size:      0x94
    signature: 0x2e966c0dc94b065b

I moved the call to cooked_index_functions::wait before printing the
CU/TU list, otherwise trying to call "maint print objfiles" quickly,
like this, would lead to an internal error:

  $ ./gdb  -nx -q --data-directory=data-directory testsuite/outputs/gdb.dwarf2/struct-with-sig/struct-with-sig -ex "maint print objfiles"

This is because dwarf2_per_cu_data::m_unit_type was not yet set, when
trying to read it.  Waiting for the index to be built ensures that it is
set, since setting the unit type is done as a side-effect somewhere.

Change-Id: Ic810ec3bb4d3f5abb481cf1cee9b2954ff4f0874

gdb/dwarf2/cooked-index.h
gdb/dwarf2/read.c

index 4c35d5b65ddf290775d7c808516f3bafae5f5238..d9c8ae2d3d01acfc99df912cb5d693c44aecaba6 100644 (file)
@@ -696,13 +696,7 @@ struct cooked_index_functions : public dwarf2_base_index_functions
     dwarf2_base_index_functions::print_stats (objfile, print_bcache);
   }
 
-  void dump (struct objfile *objfile) override
-  {
-    cooked_index *index = wait (objfile, true);
-    gdb_printf ("Cooked index in use:\n");
-    gdb_printf ("\n");
-    index->dump (objfile->arch ());
-  }
+  void dump (struct objfile *objfile) override;
 
   void expand_all_symtabs (struct objfile *objfile) override
   {
index 469c2900ce4ed1e98bbec57615c311e2b485bdc5..5c26f87562d18886e1cc43c2b7d5977854ea503a 100644 (file)
@@ -14733,6 +14733,60 @@ cutu_reader::read_toplevel_die (die_info **diep, const gdb_byte *info_ptr,
   return result;
 }
 
+void
+cooked_index_functions::dump (struct objfile *objfile)
+{
+  /* Building the index fills some information in dwarf2_per_cu (e.g. the
+     unit type), which we print in the CU/TU list.  We also need to wait for the
+     index to be built before calling `cooked_index::dump` below.  */
+  cooked_index *index = this->wait (objfile, true);
+
+  const auto per_bfd = get_dwarf2_per_objfile (objfile)->per_bfd;
+
+  gdb_printf ("  Number of compilation units: %u\n", per_bfd->num_comp_units);
+  gdb_printf ("  Number of type units: %u\n", per_bfd->num_type_units);
+  gdb_printf ("\n");
+
+  gdb_printf ("  Compilation/type units:\n");
+  gdb_printf ("\n");
+
+  for (std::size_t i = 0; i < per_bfd->all_units.size (); ++i)
+    {
+      const auto &unit = *per_bfd->all_units[i];
+      const char *gdb_type_name
+       = unit.is_debug_types ? "signatured_type" : "dwarf2_per_cu";
+      const auto bool_str
+       = [] (const bool val) { return val ? "true" : "false"; };
+
+      gdb_printf ("    [%zu] ((%s *) %p)\n", i, gdb_type_name, &unit);
+      gdb_printf ("    type:       %s\n",
+                 dwarf_unit_type_name (unit.unit_type (false)));
+      gdb_printf ("    offset:     0x%" PRIx64 "\n",
+                 to_underlying (unit.sect_off));
+      gdb_printf ("    size:       0x%x\n", unit.length ());
+
+      if (unit.is_debug_types)
+       {
+         const auto &tu = static_cast<const signatured_type &> (unit);
+
+         gdb_printf ("    signature:  0x%s\n", phex (tu.signature, 8));
+       }
+      else
+       {
+         gdb_printf ("    artificial: %s\n", bool_str (unit.lto_artificial));
+         gdb_printf ("    GDB lang:   %s\n", language_str (unit.lang (false)));
+         gdb_printf ("    DWARF lang: %s\n",
+                     dwarf_source_language_name (unit.dw_lang ()));
+       }
+
+      gdb_printf ("\n");
+    }
+
+  gdb_printf ("Cooked index in use:\n");
+  gdb_printf ("\n");
+  index->dump (objfile->arch ());
+}
+
 struct compunit_symtab *
 cooked_index_functions::find_compunit_symtab_by_address
      (struct objfile *objfile, CORE_ADDR address)