[PATCHv3,1/4] gdb/dwarf: remove line_header parameter from dwarf2_decode_lines
Commit Message
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.
---
gdb/dwarf2/line-program.c | 15 ++++++++-------
gdb/dwarf2/line-program.h | 10 ++--------
gdb/dwarf2/read.c | 2 +-
3 files changed, 11 insertions(+), 16 deletions(-)
Comments
On 2025-12-22 09:41, Andrew Burgess wrote:
> 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.
Could you do the same for dwarf2_start_subfile and lnp_state_machine?
Simon
@@ -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 ();
@@ -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 */
@@ -6099,7 +6099,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. */