[2/8] gdb/dwarf: remove unnecessary parameter of create_cus_hash_table

Message ID 20250305050834.2223161-2-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@efficios.com>

We can use `cu->per_objfile` instead of passing down a
dwarf2_per_objfile explicitly.

Change-Id: Ie1fd93d9e7a74d09b857f1f0909d7441b79ed893
---
 gdb/dwarf2/read.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
  

Comments

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

Simon> From: Simon Marchi <simon.marchi@efficios.com>
Simon> We can use `cu->per_objfile` instead of passing down a
Simon> dwarf2_per_objfile explicitly.

This seems fine but I don't really understand this function.  Like, it
takes a CU argument but it loops over some contents and seems to read
multiple CUs?  Weird stuff.

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

Tom
  
Simon Marchi March 5, 2025, 3:50 p.m. UTC | #2
On 3/5/25 10:33 AM, Tom Tromey wrote:
>>>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes:
> 
> Simon> From: Simon Marchi <simon.marchi@efficios.com>
> Simon> We can use `cu->per_objfile` instead of passing down a
> Simon> dwarf2_per_objfile explicitly.
> 
> This seems fine but I don't really understand this function.  Like, it
> takes a CU argument but it loops over some contents and seems to read
> multiple CUs?  Weird stuff.

My understanding is that the passed-in CU is a DWO stub from the main
file, therefore pointing to an external DWO file.  This function reads
all the CUs present in the DWO file (hence the loop) to fill the
dwo_file::cus hash table.  Typically, there will just be one CU in the
DWO file, but note the comment on dwo_file::cus:

     Multiple CUs per DWO are supported as an extension to handle LLVM's Link
     Time Optimization output (where multiple source files may be compiled into
     a single object/dwo pair).

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

Thanks,

Simon
  

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 926d377488a7..a3ae88c76203 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7021,10 +7021,10 @@  create_dwo_cu_reader (const struct die_reader_specs *reader,
    Note: This function processes DWO files only, not DWP files.  */
 
 static void
-create_cus_hash_table (dwarf2_per_objfile *per_objfile,
-		       dwarf2_cu *cu, struct dwo_file &dwo_file,
+create_cus_hash_table (dwarf2_cu *cu, struct dwo_file &dwo_file,
 		       dwarf2_section_info &section, htab_up &cus_htab)
 {
+  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;
@@ -8353,8 +8353,7 @@  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 (per_objfile, cu, *dwo_file, dwo_file->sections.info,
-			 dwo_file->cus);
+  create_cus_hash_table (cu, *dwo_file, dwo_file->sections.info, dwo_file->cus);
 
   if (cu->per_cu->version () < 5)
     {