[4/8] gdb/dwarf: remove unnecessary parameters to create_{cus, debug_type}_hash_table

Message ID 20250305050834.2223161-4-simon.marchi@polymtl.ca
State New
Headers
Series [1/8] gdb/dwarf: remove unnecessary local variable in dw2_get_file_names_reader |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Simon Marchi March 5, 2025, 5:06 a.m. UTC
  From: Simon Marchi <simon.marchi@polymtl.ca>

In create_cus_hash_table, we can get the section and hash table from the
dwo_file directly.

In create_debug_type_hash_table, we can get the hash table from the
dwo_file directly - the section varies.

Change-Id: I1d5ef49df98fe2620e12b83484b28cd7398f24ae
---
 gdb/dwarf2/read.c | 51 +++++++++++++++++++----------------------------
 1 file changed, 21 insertions(+), 30 deletions(-)
  

Comments

Tom Tromey March 5, 2025, 4:02 p.m. UTC | #1
>>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes:

Simon> From: Simon Marchi <simon.marchi@polymtl.ca>
Simon> In create_cus_hash_table, we can get the section and hash table from the
Simon> dwo_file directly.

Simon> In create_debug_type_hash_table, we can get the hash table from the
Simon> dwo_file directly - the section varies.

Seems reasonable.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 11798f3bdb6a..946d99fd4c15 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2539,13 +2539,12 @@  read_abbrev_offset (dwarf2_per_objfile *per_objfile,
 }
 
 /* A helper for create_debug_types_hash_table.  Read types from SECTION
-   and fill them into TYPES_HTAB.  It will process only type units,
-   therefore DW_UT_type.  */
+   and fill them into DWO_FILE's type unit hash table.  It will process only
+   type units, therefore DW_UT_type.  */
 
 static void
 create_debug_type_hash_table (dwarf2_per_objfile *per_objfile,
-			      struct dwo_file *dwo_file,
-			      dwarf2_section_info *section, htab_up &types_htab,
+			      dwo_file *dwo_file, dwarf2_section_info *section,
 			      rcuh_kind section_kind)
 {
   struct objfile *objfile = per_objfile->objfile;
@@ -2606,8 +2605,8 @@  create_debug_type_hash_table (dwarf2_per_objfile *per_objfile,
 	  continue;
 	}
 
-      if (types_htab == NULL)
-	types_htab = allocate_dwo_unit_table ();
+      if (dwo_file->tus == nullptr)
+	dwo_file->tus = allocate_dwo_unit_table ();
 
       dwo_tu = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, dwo_unit);
       dwo_tu->dwo_file = dwo_file;
@@ -2617,7 +2616,7 @@  create_debug_type_hash_table (dwarf2_per_objfile *per_objfile,
       dwo_tu->sect_off = sect_off;
       dwo_tu->length = length;
 
-      slot = htab_find_slot (types_htab.get (), dwo_tu, INSERT);
+      slot = htab_find_slot (dwo_file->tus.get (), dwo_tu, INSERT);
       gdb_assert (slot != NULL);
       if (*slot != NULL)
 	complaint (_("debug type entry at offset %s is duplicate to"
@@ -2639,18 +2638,15 @@  create_debug_type_hash_table (dwarf2_per_objfile *per_objfile,
    (or .debug_types.dwo) section(s).
    DWO_FILE is a pointer to the DWO file object.
 
-   The result is a pointer to the hash table or NULL if there are no types.
-
    Note: This function processes DWO files only, not DWP files.  */
 
 static void
-create_debug_types_hash_table (dwarf2_per_objfile *per_objfile,
-			       struct dwo_file *dwo_file,
-			       gdb::array_view<dwarf2_section_info> type_sections,
-			       htab_up &types_htab)
+create_debug_types_hash_table
+  (dwarf2_per_objfile *per_objfile, dwo_file *dwo_file,
+   gdb::array_view<dwarf2_section_info> type_sections)
 {
   for (dwarf2_section_info &section : type_sections)
-    create_debug_type_hash_table (per_objfile, dwo_file, &section, types_htab,
+    create_debug_type_hash_table (per_objfile, dwo_file, &section,
 				  rcuh_kind::TYPE);
 }
 
@@ -6997,13 +6993,13 @@  create_dwo_cu_reader (const cutu_reader *reader, const gdb_byte *info_ptr,
    Note: This function processes DWO files only, not DWP files.  */
 
 static void
-create_cus_hash_table (dwarf2_cu *cu, struct dwo_file &dwo_file,
-		       dwarf2_section_info &section, htab_up &cus_htab)
+create_cus_hash_table (dwarf2_cu *cu, dwo_file &dwo_file)
 {
   dwarf2_per_objfile *per_objfile = cu->per_objfile;
   struct objfile *objfile = per_objfile->objfile;
   dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
   const gdb_byte *info_ptr, *end_ptr;
+  auto &section = dwo_file.sections.info;
 
   section.read (objfile);
   info_ptr = section.buffer;
@@ -7034,17 +7030,17 @@  create_cus_hash_table (dwarf2_cu *cu, struct dwo_file &dwo_file,
 			      &dwo_file, &read_unit);
       info_ptr += per_cu.length ();
 
-      // If the unit could not be parsed, skip it.
+      /* If the unit could not be parsed, skip it.  */
       if (read_unit.dwo_file == NULL)
 	continue;
 
-      if (cus_htab == NULL)
-	cus_htab = allocate_dwo_unit_table ();
+      if (dwo_file.cus == nullptr)
+	dwo_file.cus = allocate_dwo_unit_table ();
 
       dwo_unit = OBSTACK_ZALLOC (&per_bfd->obstack,
 				 struct dwo_unit);
       *dwo_unit = read_unit;
-      slot = htab_find_slot (cus_htab.get (), dwo_unit, INSERT);
+      slot = htab_find_slot (dwo_file.cus.get (), dwo_unit, INSERT);
       gdb_assert (slot != NULL);
       if (*slot != NULL)
 	{
@@ -8329,19 +8325,14 @@  open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
     dwarf2_locate_dwo_sections (per_objfile->objfile, dwo_file->dbfd.get (),
 				sec, &dwo_file->sections);
 
-  create_cus_hash_table (cu, *dwo_file, dwo_file->sections.info, dwo_file->cus);
+  create_cus_hash_table (cu, *dwo_file);
 
   if (cu->per_cu->version () < 5)
-    {
-      create_debug_types_hash_table (per_objfile, dwo_file.get (),
-				     dwo_file->sections.types, dwo_file->tus);
-    }
+    create_debug_types_hash_table (per_objfile, dwo_file.get (),
+				   dwo_file->sections.types);
   else
-    {
-      create_debug_type_hash_table (per_objfile, dwo_file.get (),
-				    &dwo_file->sections.info, dwo_file->tus,
-				    rcuh_kind::COMPILE);
-    }
+    create_debug_type_hash_table (per_objfile, dwo_file.get (),
+				  &dwo_file->sections.info, rcuh_kind::COMPILE);
 
   dwarf_read_debug_printf ("DWO file found: %s", dwo_name);