From: Andrew Burgess Date: Thu, 27 Nov 2025 17:08:56 +0000 (+0000) Subject: gdb/dwarf: remove line_header parameter from dwarf2_decode_lines X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4d4bb9f71d714f3c2fc1c0ddfa7d1897843e675;p=thirdparty%2Fbinutils-gdb.git gdb/dwarf: remove line_header parameter from dwarf2_decode_lines The function declaration for dwarf2_decode_lines is: void dwarf_decode_lines (struct line_header *lh, struct dwarf2_cu *cu, unrelocated_addr lowpc, bool decode_mapping) However, it is always the case that: lh == cu->line_header I propose that we simplify the dwarf_decode_lines signature by removing the line_header parameter. The same is true for dwarf_decode_lines_1, which is only called from dwarf_decode_lines. I'm proposing this change because I was looking through the DWARF code, trying to understand how symtabs are created, and this extra complexity just makes things harder to understand: what is the relationship between the line_header (LH) and dwarf2_cu (CU) parameters? When would we ever want to process a line_header other than the one attached to CU? (answer: never, and we don't). This simplification makes things easier to understand (IMHO). There should be no user visible changes after this commit. Approved-By: Tom Tromey --- diff --git a/gdb/dwarf2/line-program.c b/gdb/dwarf2/line-program.c index 6670026799a..094f0dec806 100644 --- a/gdb/dwarf2/line-program.c +++ b/gdb/dwarf2/line-program.c @@ -481,12 +481,12 @@ lnp_state_machine::check_line_address (struct dwarf2_cu *cu, } /* Subroutine of dwarf_decode_lines to simplify it. - Process the line number information in LH. */ + Process the line number information in CU::line_header. */ static void -dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu, - unrelocated_addr lowpc) +dwarf_decode_lines_1 (struct dwarf2_cu *cu, unrelocated_addr lowpc) { + struct line_header *lh = cu->line_header; const gdb_byte *line_ptr, *extended_end; const gdb_byte *line_end; unsigned int bytes_read, extended_len; @@ -694,11 +694,11 @@ dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu, /* See dwarf2/line-program.h. */ void -dwarf_decode_lines (struct line_header *lh, struct dwarf2_cu *cu, - unrelocated_addr lowpc, bool decode_mapping) +dwarf_decode_lines (struct dwarf2_cu *cu, unrelocated_addr lowpc, + bool decode_mapping) { if (decode_mapping) - dwarf_decode_lines_1 (lh, cu, lowpc); + dwarf_decode_lines_1 (cu, lowpc); /* Make sure a symtab is created for every file, even files which contain only variables (i.e. no code with associated @@ -706,7 +706,8 @@ dwarf_decode_lines (struct line_header *lh, struct dwarf2_cu *cu, buildsym_compunit *builder = cu->get_builder (); struct compunit_symtab *cust = builder->get_compunit_symtab (); - for (auto &fe : lh->file_names ()) + struct line_header *lh = cu->line_header; + for (file_entry &fe : lh->file_names ()) { dwarf2_start_subfile (cu, fe, *lh); subfile *sf = builder->get_current_subfile (); diff --git a/gdb/dwarf2/line-program.h b/gdb/dwarf2/line-program.h index 9b4e91c12ec..060b1ffbfbf 100644 --- a/gdb/dwarf2/line-program.h +++ b/gdb/dwarf2/line-program.h @@ -20,12 +20,7 @@ #ifndef GDB_DWARF2_LINE_PROGRAM_H #define GDB_DWARF2_LINE_PROGRAM_H -/* Decode the Line Number Program (LNP) for the given line_header - structure and CU. The actual information extracted and the type - of structures created from the LNP depends on the value of PST. - - FND holds the CU file name and directory, if known. - It is used for relative paths in the line table. +/* Decode the Line Number Program (LNP) for CU::line_header. NOTE: It is important that psymtabs have the same file name (via strcmp) as the corresponding symtab. Since the directory is not @@ -40,8 +35,7 @@ for its PC<->lines mapping information. Otherwise only the filename table is read in. */ -extern void dwarf_decode_lines (struct line_header *lh, - struct dwarf2_cu *cu, +extern void dwarf_decode_lines (struct dwarf2_cu *cu, unrelocated_addr lowpc, bool decode_mapping); #endif /* GDB_DWARF2_LINE_PROGRAM_H */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 4b706f654e0..5311016b257 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -6089,7 +6089,7 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, then there won't be any interesting code in the CU, but a check later on (in lnp_state_machine::check_line_address) will fail to properly exclude an entry that was removed via --gc-sections. */ - dwarf_decode_lines (cu->line_header, cu, lowpc, decode_mapping && have_code); + dwarf_decode_lines (cu, lowpc, decode_mapping && have_code); } /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */