public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 18/30] Wire in the new DWARF indexer
Date: Wed, 25 Aug 2021 20:19:25 -0600	[thread overview]
Message-ID: <20210826021937.1490292-19-tom@tromey.com> (raw)
In-Reply-To: <20210826021937.1490292-1-tom@tromey.com>

This wires the new DWARF indexer into the existing reader code.  That
is, this patch makes the modification necessary to enable the new
indexer.  It is not actually enabled by this patch -- that will be
done later.

I did a bit of performance testing for this patch and a few others.  I
copied my built gdb to /tmp, so that each test would be done on the
same executable.  Then, each time, I did:

    $ ./gdb -nx
    (gdb) maint time 1
    (gdb) file /tmp/gdb

This patch is the baseline and on one machine came in at 1.598869 wall
time.
---
 gdb/dwarf2/read.c | 199 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 142 insertions(+), 57 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 1bed6a32cdd..0e88d402890 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -794,7 +794,8 @@ class cutu_reader : public die_reader_specs
 	       dwarf2_per_objfile *per_objfile,
 	       struct abbrev_table *abbrev_table,
 	       dwarf2_cu *existing_cu,
-	       bool skip_partial);
+	       bool skip_partial,
+	       abbrev_cache *cache = nullptr);
 
   explicit cutu_reader (struct dwarf2_per_cu_data *this_cu,
 			dwarf2_per_objfile *per_objfile,
@@ -1102,7 +1103,9 @@ static dwarf2_psymtab *create_partial_symtab
   (dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile,
    const char *name);
 
-static void build_type_psymtabs_reader (cutu_reader *reader);
+class cooked_index_storage;
+static void build_type_psymtabs_reader (cutu_reader *reader,
+					cooked_index_storage *storage);
 
 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile);
 
@@ -5594,6 +5597,13 @@ dwarf2_initialize_objfile (struct objfile *objfile)
       return;
     }
 
+  if (per_bfd->cooked_index_table != nullptr)
+    {
+      dwarf_read_debug_printf ("re-using cooked index table");
+      objfile->qf.push_front (make_cooked_index_funcs ());
+      return;
+    }
+
   /* There might already be partial symtabs built for this BFD.  This happens
      when loading the same binary twice with the index-cache enabled.  If so,
      don't try to read an index.  The objfile / per_objfile initialization will
@@ -5606,13 +5616,6 @@ dwarf2_initialize_objfile (struct objfile *objfile)
       return;
     }
 
-  if (per_bfd->cooked_index_table != nullptr)
-    {
-      dwarf_read_debug_printf ("re-using cooked index table");
-      objfile->qf.push_front (make_cooked_index_funcs ());
-      return;
-    }
-
   if (dwarf2_read_debug_names (per_objfile))
     {
       dwarf_read_debug_printf ("found debug names");
@@ -6074,7 +6077,9 @@ fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile *per_objfile,
   else
       gdb_assert (sig_entry->v.psymtab == NULL);
   gdb_assert (sig_entry->signature == dwo_entry->signature);
-  gdb_assert (to_underlying (sig_entry->type_offset_in_section) == 0);
+  gdb_assert (to_underlying (sig_entry->type_offset_in_section) == 0
+	      || (to_underlying (sig_entry->type_offset_in_section)
+		  == to_underlying (dwo_entry->type_offset_in_tu)));
   gdb_assert (sig_entry->type_unit_group == NULL);
   gdb_assert (sig_entry->dwo_unit == NULL);
 
@@ -6558,7 +6563,8 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu,
 			  dwarf2_per_objfile *per_objfile,
 			  struct abbrev_table *abbrev_table,
 			  dwarf2_cu *existing_cu,
-			  bool skip_partial)
+			  bool skip_partial,
+			  abbrev_cache *cache)
   : die_reader_specs {},
     m_this_cu (this_cu)
 {
@@ -6682,10 +6688,16 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu,
     gdb_assert (cu->header.abbrev_sect_off == abbrev_table->sect_off);
   else
     {
-      abbrev_section->read (objfile);
-      m_abbrev_table_holder
-	= abbrev_table::read (abbrev_section, cu->header.abbrev_sect_off);
-      abbrev_table = m_abbrev_table_holder.get ();
+      if (cache != nullptr)
+	abbrev_table = cache->find (abbrev_section,
+				    cu->header.abbrev_sect_off);
+      if (abbrev_table == nullptr)
+	{
+	  abbrev_section->read (objfile);
+	  m_abbrev_table_holder
+	    = abbrev_table::read (abbrev_section, cu->header.abbrev_sect_off);
+	  abbrev_table = m_abbrev_table_holder.get ();
+	}
     }
 
   /* Read the top level CU/TU die.  */
@@ -7374,16 +7386,21 @@ static void
 process_psymtab_comp_unit (dwarf2_per_cu_data *this_cu,
 			   dwarf2_per_objfile *per_objfile,
 			   bool want_partial_unit,
-			   enum language pretend_language)
+			   enum language pretend_language,
+			   cooked_index_storage *storage)
 {
   /* If this compilation unit was already read in, free the
      cached copy in order to read it in again.	This is
      necessary because we skipped some symbols when we first
      read in the compilation unit (see load_partial_dies).
      This problem could be avoided, but the benefit is unclear.  */
-  per_objfile->remove_cu (this_cu);
+  if (!per_objfile->per_bfd->using_index)
+    per_objfile->remove_cu (this_cu);
 
-  cutu_reader reader (this_cu, per_objfile, nullptr, nullptr, false);
+  cutu_reader reader (this_cu, per_objfile, nullptr, nullptr, false,
+		      (storage == nullptr
+		       ? nullptr
+		       : storage->get_abbrev_cache ()));
 
   if (reader.comp_unit_die == nullptr)
     return;
@@ -7411,12 +7428,28 @@ process_psymtab_comp_unit (dwarf2_per_cu_data *this_cu,
       /* Nothing.  */
     }
   else if (this_cu->is_debug_types)
-    build_type_psymtabs_reader (&reader);
+    build_type_psymtabs_reader (&reader, storage);
   else if (want_partial_unit
 	   || reader.comp_unit_die->tag != DW_TAG_partial_unit)
-    process_psymtab_comp_unit_reader (&reader, reader.info_ptr,
-				      reader.comp_unit_die,
-				      pretend_language);
+    {
+      if (per_objfile->per_bfd->using_index)
+	{
+	  if (!this_cu->scanned && reader.comp_unit_die->has_children)
+	    {
+	      this_cu->scanned = true;
+	      prepare_one_comp_unit (reader.cu, reader.comp_unit_die,
+				     pretend_language);
+	      gdb_assert (storage != nullptr);
+	      cooked_indexer indexer (storage, this_cu,
+				      reader.cu->per_cu->lang);
+	      indexer.make_index (&reader);
+	    }
+	}
+      else
+	process_psymtab_comp_unit_reader (&reader, reader.info_ptr,
+					  reader.comp_unit_die,
+					  pretend_language);
+    }
 
   /* Age out any secondary CUs.  */
   per_objfile->age_comp_units ();
@@ -7425,7 +7458,8 @@ process_psymtab_comp_unit (dwarf2_per_cu_data *this_cu,
 /* Reader function for build_type_psymtabs.  */
 
 static void
-build_type_psymtabs_reader (cutu_reader *reader)
+build_type_psymtabs_reader (cutu_reader *reader,
+			    cooked_index_storage *storage)
 {
   dwarf2_per_objfile *per_objfile = reader->cu->per_objfile;
   struct dwarf2_cu *cu = reader->cu;
@@ -7453,16 +7487,26 @@ build_type_psymtabs_reader (cutu_reader *reader)
   tu_group->tus->push_back (sig_type);
 
   prepare_one_comp_unit (cu, type_unit_die, language_minimal);
-  pst = create_partial_symtab (per_cu, per_objfile, "");
-  pst->anonymous = true;
 
-  first_die = load_partial_dies (reader, info_ptr, 1);
+  if (per_objfile->per_bfd->using_index)
+    {
+      gdb_assert (storage != nullptr);
+      cooked_indexer indexer (storage, per_cu, cu->per_cu->lang);
+      indexer.make_index (reader);
+    }
+  else
+    {
+      pst = create_partial_symtab (per_cu, per_objfile, "");
+      pst->anonymous = true;
 
-  lowpc = (CORE_ADDR) -1;
-  highpc = (CORE_ADDR) 0;
-  scan_partial_symbols (first_die, &lowpc, &highpc, 0, cu);
+      first_die = load_partial_dies (reader, info_ptr, 1);
 
-  pst->end ();
+      lowpc = (CORE_ADDR) -1;
+      highpc = (CORE_ADDR) 0;
+      scan_partial_symbols (first_die, &lowpc, &highpc, 0, cu);
+
+      pst->end ();
+    }
 }
 
 /* Struct used to sort TUs by their abbreviation table offset.  */
@@ -7501,7 +7545,8 @@ struct tu_abbrev_offset
    dwarf2_per_objfile->per_bfd->type_unit_groups.  */
 
 static void
-build_type_psymtabs (dwarf2_per_objfile *per_objfile)
+build_type_psymtabs (dwarf2_per_objfile *per_objfile,
+		     cooked_index_storage *storage)
 {
   struct tu_stats *tu_stats = &per_objfile->per_bfd->tu_stats;
   abbrev_table_up abbrev_table;
@@ -7570,7 +7615,7 @@ build_type_psymtabs (dwarf2_per_objfile *per_objfile)
       cutu_reader reader (tu.sig_type, per_objfile,
 			  abbrev_table.get (), nullptr, false);
       if (!reader.dummy_p)
-	build_type_psymtabs_reader (&reader);
+	build_type_psymtabs_reader (&reader, storage);
     }
 }
 
@@ -7626,6 +7671,12 @@ build_type_psymtab_dependencies (void **slot, void *info)
   return 1;
 }
 
+struct skeleton_data
+{
+  dwarf2_per_objfile *per_objfile;
+  cooked_index_storage *storage;
+};
+
 /* Traversal function for process_skeletonless_type_unit.
    Read a TU in a DWO file and build partial symbols for it.  */
 
@@ -7633,15 +7684,16 @@ static int
 process_skeletonless_type_unit (void **slot, void *info)
 {
   struct dwo_unit *dwo_unit = (struct dwo_unit *) *slot;
-  dwarf2_per_objfile *per_objfile = (dwarf2_per_objfile *) info;
+  skeleton_data *data = (skeleton_data *) info;
 
   /* If this TU doesn't exist in the global table, add it and read it in.  */
 
-  if (per_objfile->per_bfd->signatured_types == NULL)
-    per_objfile->per_bfd->signatured_types = allocate_signatured_type_table ();
+  if (data->per_objfile->per_bfd->signatured_types == NULL)
+    data->per_objfile->per_bfd->signatured_types
+      = allocate_signatured_type_table ();
 
   signatured_type find_entry (dwo_unit->signature);
-  slot = htab_find_slot (per_objfile->per_bfd->signatured_types.get (),
+  slot = htab_find_slot (data->per_objfile->per_bfd->signatured_types.get (),
 			 &find_entry, INSERT);
   /* If we've already seen this type there's nothing to do.  What's happening
      is we're doing our own version of comdat-folding here.  */
@@ -7651,14 +7703,14 @@ process_skeletonless_type_unit (void **slot, void *info)
   /* This does the job that create_all_comp_units would have done for
      this TU.  */
   signatured_type *entry
-    = add_type_unit (per_objfile, dwo_unit->signature, slot);
-  fill_in_sig_entry_from_dwo_entry (per_objfile, entry, dwo_unit);
+    = add_type_unit (data->per_objfile, dwo_unit->signature, slot);
+  fill_in_sig_entry_from_dwo_entry (data->per_objfile, entry, dwo_unit);
   *slot = entry;
 
   /* This does the job that build_type_psymtabs would have done.  */
-  cutu_reader reader (entry, per_objfile, nullptr, nullptr, false);
+  cutu_reader reader (entry, data->per_objfile, nullptr, nullptr, false);
   if (!reader.dummy_p)
-    build_type_psymtabs_reader (&reader);
+    build_type_psymtabs_reader (&reader, data->storage);
 
   return 1;
 }
@@ -7682,15 +7734,18 @@ process_dwo_file_for_skeletonless_type_units (void **slot, void *info)
    Note: This can't be done until we know what all the DWO files are.  */
 
 static void
-process_skeletonless_type_units (dwarf2_per_objfile *per_objfile)
+process_skeletonless_type_units (dwarf2_per_objfile *per_objfile,
+				 cooked_index_storage *storage)
 {
+  skeleton_data data { per_objfile, storage };
+
   /* Skeletonless TUs in DWP files without .gdb_index is not supported yet.  */
   if (get_dwp_file (per_objfile) == NULL
       && per_objfile->per_bfd->dwo_files != NULL)
     {
       htab_traverse_noresize (per_objfile->per_bfd->dwo_files.get (),
 			      process_dwo_file_for_skeletonless_type_units,
-			      per_objfile);
+			      &data);
     }
 }
 
@@ -7736,9 +7791,6 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
      read_in_chain.  Make sure to free them when we're done.  */
   free_cached_comp_units freer (per_objfile);
 
-  create_all_comp_units (per_objfile);
-  build_type_psymtabs (per_objfile);
-
   /* Create a temporary address map on a temporary obstack.  We later
      copy this to the final obstack.  */
   auto_obstack temp_obstack;
@@ -7747,20 +7799,35 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
     = make_scoped_restore (&per_bfd->partial_symtabs->psymtabs_addrmap,
 			   addrmap_create_mutable (&temp_obstack));
 
+  cooked_index_storage index_storage;
+  cooked_index_storage *index_storage_ptr
+    = per_bfd->using_index ? &index_storage : nullptr;
+  create_all_comp_units (per_objfile);
+  build_type_psymtabs (per_objfile, index_storage_ptr);
+  if (per_bfd->using_index)
+    {
+      per_bfd->quick_file_names_table
+	= create_quick_file_names_table (per_bfd->all_comp_units.size ());
+
+      if (!per_bfd->debug_aranges.empty ())
+	read_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges,
+				   index_storage.get_addrmap ());
+    }
+
   for (const auto &per_cu : per_bfd->all_comp_units)
     {
-      if (per_cu->v.psymtab != NULL)
+      if (!per_bfd->using_index && per_cu->v.psymtab != NULL)
 	/* In case a forward DW_TAG_imported_unit has read the CU already.  */
 	continue;
       process_psymtab_comp_unit (per_cu.get (), per_objfile, false,
-				 language_minimal);
+				 language_minimal, index_storage_ptr);
     }
 
   /* This has to wait until we read the CUs, we need the list of DWOs.  */
-  process_skeletonless_type_units (per_objfile);
+  process_skeletonless_type_units (per_objfile, &index_storage);
 
   /* Now that all TUs have been processed we can fill in the dependencies.  */
-  if (per_bfd->type_unit_groups != NULL)
+  if (!per_bfd->using_index && per_bfd->type_unit_groups != NULL)
     {
       htab_traverse_noresize (per_bfd->type_unit_groups.get (),
 			      build_type_psymtab_dependencies, per_objfile);
@@ -7769,14 +7836,27 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
   if (dwarf_read_debug > 0)
     print_tu_stats (per_objfile);
 
-  set_partial_user (per_objfile);
+  if (per_bfd->using_index)
+    {
+      per_bfd->cooked_index_table = index_storage.release ();
+      per_bfd->cooked_index_table->finalize ();
 
-  per_bfd->partial_symtabs->psymtabs_addrmap
-    = addrmap_create_fixed (per_bfd->partial_symtabs->psymtabs_addrmap,
-			    per_bfd->partial_symtabs->obstack ());
-  /* At this point we want to keep the address map.  */
-  save_psymtabs_addrmap.release ();
+      const cooked_index_entry *main_entry
+	= per_bfd->cooked_index_table->get_main ();
+      if (main_entry != nullptr)
+	set_objfile_main_name (objfile, main_entry->name,
+			       main_entry->per_cu->lang);
+    }
+  else
+    {
+      set_partial_user (per_objfile);
 
+      per_bfd->partial_symtabs->psymtabs_addrmap
+	= addrmap_create_fixed (per_bfd->partial_symtabs->psymtabs_addrmap,
+				per_bfd->partial_symtabs->obstack ());
+      /* At this point we want to keep the address map.  */
+      save_psymtabs_addrmap.release ();
+    }
   dwarf_read_debug_printf ("Done building psymtabs of %s",
 			   objfile_name (objfile));
 }
@@ -7865,6 +7945,10 @@ read_comp_units_from_section (dwarf2_per_objfile *per_objfile,
       this_cu->is_dwz = is_dwz;
       this_cu->section = section;
 
+      if (per_objfile->per_bfd->using_index)
+	this_cu->v.quick = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack,
+					   struct dwarf2_per_cu_quick_data);
+
       info_ptr = info_ptr + this_cu->length;
       per_objfile->per_bfd->all_comp_units.push_back (std::move (this_cu));
     }
@@ -7993,7 +8077,7 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
 		/* Go read the partial unit, if needed.  */
 		if (per_cu->v.psymtab == NULL)
 		  process_psymtab_comp_unit (per_cu, cu->per_objfile, true,
-					     cu->per_cu->lang);
+					     cu->per_cu->lang, nullptr);
 
 		if (pdi->die_parent == nullptr
 		    && per_cu->unit_type == DW_UT_compile
@@ -19277,7 +19361,8 @@ cooked_indexer::ensure_cu_exists (cutu_reader *reader,
   cutu_reader *result = m_index_storage->get_reader (per_cu);
   if (result == nullptr)
     {
-      cutu_reader new_reader (per_cu, per_objfile, nullptr, nullptr, false);
+      cutu_reader new_reader (per_cu, per_objfile, nullptr, nullptr, false,
+			      m_index_storage->get_abbrev_cache ());
 
       prepare_one_comp_unit (new_reader.cu, new_reader.comp_unit_die,
 			     language_minimal);
-- 
2.31.1


  parent reply	other threads:[~2021-08-26  2:19 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26  2:19 [PATCH 00/30] Rewrite the DWARF "partial" reader Tom Tromey
2021-08-26  2:19 ` [PATCH 01/30] Introduce make_unique_xstrndup Tom Tromey
2021-08-26  2:19 ` [PATCH 02/30] Split create_addrmap_from_aranges Tom Tromey
2021-08-26  2:19 ` [PATCH 03/30] Add dwarf2_per_cu_data::addresses_seen Tom Tromey
2021-08-26  2:19 ` [PATCH 04/30] Refactor dwarf2_get_pc_bounds Tom Tromey
2021-08-26  2:19 ` [PATCH 05/30] Allow ada_decode not to decode operators Tom Tromey
2021-08-26  2:19 ` [PATCH 06/30] Let skip_one_die not skip children Tom Tromey
2021-08-26  2:19 ` [PATCH 07/30] Add name splitting Tom Tromey
2021-08-26  2:19 ` [PATCH 08/30] Add new overload of dwarf5_djb_hash Tom Tromey
2021-08-26  2:19 ` [PATCH 09/30] Refactor build_type_psymtabs_reader Tom Tromey
2021-08-26  2:19 ` [PATCH 10/30] Add batching parameter to parallel_for_each Tom Tromey
2021-08-26  2:19 ` [PATCH 11/30] Return vector of results from parallel_for_each Tom Tromey
2021-08-27  6:20   ` Tom de Vries
2021-08-28 19:20     ` Tom Tromey
2021-08-26  2:19 ` [PATCH 12/30] Introduce DWARF abbrev cache Tom Tromey
2021-08-26  2:19 ` [PATCH 13/30] Statically examine abbrev properties Tom Tromey
2021-09-06 22:31   ` Lancelot SIX
2021-11-04 18:00     ` Tom Tromey
2021-08-26  2:19 ` [PATCH 14/30] Update skip_one_die for new " Tom Tromey
2021-08-26  2:19 ` [PATCH 15/30] Introduce the new DWARF index class Tom Tromey
2021-09-09 23:32   ` Lancelot SIX
2021-11-04 18:03     ` Tom Tromey
2021-08-26  2:19 ` [PATCH 16/30] The new DWARF indexer Tom Tromey
2021-08-26  2:19 ` [PATCH 17/30] Implement quick_symbol_functions for cooked DWARF index Tom Tromey
2021-08-26  2:19 ` Tom Tromey [this message]
2021-08-26  2:19 ` [PATCH 19/30] Pre-read DWARF section data Tom Tromey
2021-08-26  2:19 ` [PATCH 20/30] Parallelize DWARF indexing Tom Tromey
2021-08-26  2:19 ` [PATCH 21/30] "Finalize" the DWARF index in the background Tom Tromey
2021-08-26  2:19 ` [PATCH 22/30] Rename write_psymtabs_to_index Tom Tromey
2021-08-26  2:19 ` [PATCH 23/30] Change the key type in psym_index_map Tom Tromey
2021-08-26  2:19 ` [PATCH 24/30] Change parameters to write_address_map Tom Tromey
2021-08-26  2:19 ` [PATCH 25/30] Genericize addrmap handling in the DWARF index writer Tom Tromey
2021-08-26  2:19 ` [PATCH 26/30] Adapt .gdb_index writer to new DWARF scanner Tom Tromey
2021-08-26  2:19 ` [PATCH 27/30] Adapt .debug_names " Tom Tromey
2021-08-26  2:19 ` [PATCH 28/30] Enable the new DWARF indexer Tom Tromey
2021-08-26  2:19 ` [PATCH 29/30] Delete DWARF psymtab code Tom Tromey
2021-08-26  2:19 ` [PATCH 30/30] Remove dwarf2_per_cu_data::v Tom Tromey
2021-08-26 20:32 ` [PATCH 00/30] Rewrite the DWARF "partial" reader Tom de Vries
2021-08-26 21:29   ` Tom Tromey
2021-08-27  7:31     ` Tom de Vries
2021-08-30 15:04       ` Tom Tromey
2021-09-06 19:46         ` Tom Tromey
2021-09-07 10:58           ` Tom de Vries
2021-09-07 12:16             ` Tom de Vries
2021-10-29 23:06               ` Tom Tromey
2021-09-09 19:00 ` Wei-min Pan
2021-09-11 21:08   ` Tom Tromey
2021-09-13 16:50     ` Weimin Pan

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=20210826021937.1490292-19-tom@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).