From: Andrew Burgess Date: Thu, 25 Dec 2025 11:15:09 +0000 (+0000) Subject: gdb/dwarf: rename dwarf2_start_subfile to dwarf2_cu::start_subfile X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3507c2881efe4eeff251a473c691eaeb423e771e;p=thirdparty%2Fbinutils-gdb.git gdb/dwarf: rename dwarf2_start_subfile to dwarf2_cu::start_subfile Rename dwarf2_start_subfile to dwarf2_cu::start_subfile. This refactor continues the work started in the previous commit. There should be no user visible changes after this commit. Approved-By: Tom Tromey --- diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c index 0abf25bf8a1..1cf320267fb 100644 --- a/gdb/dwarf2/cu.c +++ b/gdb/dwarf2/cu.c @@ -250,7 +250,7 @@ dwarf2_cu::create_subfiles_and_symtabs () for (file_entry &fe : this->line_header->file_names ()) { - dwarf2_start_subfile (*this, fe); + this->start_subfile (fe); subfile *sf = builder->get_current_subfile (); if (sf->symtab == nullptr) @@ -260,3 +260,30 @@ dwarf2_cu::create_subfiles_and_symtabs () fe.symtab = sf->symtab; } } + +/* See dwarf2/cu.h. */ + +void +dwarf2_cu::start_subfile (const file_entry &fe) +{ + std::string filename_holder; + const char *filename = fe.name; + const char *dirname = this->line_header->include_dir_at (fe.d_index); + + /* In order not to lose the line information directory, + we concatenate it to the filename when it makes sense. + Note that the Dwarf3 standard says (speaking of filenames in line + information): ``The directory index is ignored for file names + that represent full path names''. Thus ignoring dirname in the + `else' branch below isn't an issue. */ + + if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) + { + filename_holder = path_join (dirname, filename); + filename = filename_holder.c_str (); + } + + std::string filename_for_id = this->line_header->file_file_name (fe); + this->get_builder ()->start_subfile (filename, filename_for_id.c_str ()); +} + diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h index c0596c35876..97c0b87121b 100644 --- a/gdb/dwarf2/cu.h +++ b/gdb/dwarf2/cu.h @@ -26,6 +26,7 @@ #include "language.h" #include "gdbsupport/unordered_set.h" #include "dwarf2/die.h" +#include "line-header.h" /* Type used for delaying computation of method physnames. See comments for compute_delayed_physnames. */ @@ -75,6 +76,9 @@ struct dwarf2_cu /* Create a subfile and symtab for every entry in the line_header. */ void create_subfiles_and_symtabs (); + /* Start a subfile for FE within this CU. */ + void start_subfile (const file_entry &fe); + /* Reset the builder. */ void reset_builder () { m_builder.reset (); } diff --git a/gdb/dwarf2/line-program.c b/gdb/dwarf2/line-program.c index 0b8af07d47a..18f010919c2 100644 --- a/gdb/dwarf2/line-program.c +++ b/gdb/dwarf2/line-program.c @@ -244,7 +244,7 @@ lnp_state_machine::handle_set_file (file_name_index file) else { m_line_has_non_zero_discriminator = m_discriminator != 0; - dwarf2_start_subfile (*m_cu, *fe); + m_cu->start_subfile (*fe); } } @@ -507,7 +507,7 @@ dwarf_decode_lines_1 (struct dwarf2_cu *cu, unrelocated_addr lowpc) const file_entry *fe = state_machine.current_file (); if (fe != NULL) - dwarf2_start_subfile (*cu, *fe); + cu->start_subfile (*fe); /* Decode the table. */ while (line_ptr < line_end && !end_sequence) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index a99a2760af5..4edd9cf2591 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -15966,32 +15966,6 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu, comp_dir); } -/* See dwarf2/read.h. */ - -void -dwarf2_start_subfile (dwarf2_cu &cu, const file_entry &fe) -{ - std::string filename_holder; - const char *filename = fe.name; - const char *dirname = cu.line_header->include_dir_at (fe.d_index); - - /* In order not to lose the line information directory, - we concatenate it to the filename when it makes sense. - Note that the Dwarf3 standard says (speaking of filenames in line - information): ``The directory index is ignored for file names - that represent full path names''. Thus ignoring dirname in the - `else' branch below isn't an issue. */ - - if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) - { - filename_holder = path_join (dirname, filename); - filename = filename_holder.c_str (); - } - - std::string filename_for_id = cu.line_header->file_file_name (fe); - cu.get_builder ()->start_subfile (filename, filename_for_id.c_str ()); -} - static void var_decode_location (struct attribute *attr, struct symbol *sym, struct dwarf2_cu *cu) diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index c29e414cc29..1a6d9767413 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -1410,29 +1410,6 @@ extern const dwarf2_section_info &get_section_for_ref extern struct dwarf2_section_info *get_debug_line_section (struct dwarf2_cu *cu); -/* Start a subfile for FE within CU. - - This routine tries to keep line numbers from identical absolute and - relative file names in a common subfile. - - Using the `list' example from the GDB testsuite, which resides in - /srcdir and compiling it with Irix6.2 cc in /compdir using a filename - of /srcdir/list0.c yields the following debugging information for list0.c: - - DW_AT_name: /srcdir/list0.c - DW_AT_comp_dir: /compdir - files.files[0].name: list0.h - files.files[0].dir: /srcdir - files.files[1].name: list0.c - files.files[1].dir: /srcdir - - The line number information for list0.c has to end up in a single - subfile, so that `break /srcdir/list0.c:1' works as expected. - start_subfile will ensure that this happens provided that we pass the - concatenation of files.files[1].dir and files.files[1].name as the - subfile's name. */ -extern void dwarf2_start_subfile (dwarf2_cu &cu, const file_entry &fe); - /* A helper function that decides if a given symbol is an Ada Pragma Import or Pragma Export. */