[PATCHv4,5/7] gdb/dwarf: rename dwarf2_start_subfile to dwarf2_cu::start_subfile

Message ID 66d978fa035c1b674dc895eaa63b8c5db6651672.1767024363.git.aburgess@redhat.com
State New
Headers
Series Fixes related to misplaced symtabs originating from dwz files |

Commit Message

Andrew Burgess Dec. 29, 2025, 4:15 p.m. UTC
  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.
---
 gdb/dwarf2/cu.c           | 29 ++++++++++++++++++++++++++++-
 gdb/dwarf2/cu.h           |  4 ++++
 gdb/dwarf2/line-program.c |  4 ++--
 gdb/dwarf2/read.c         | 26 --------------------------
 gdb/dwarf2/read.h         | 23 -----------------------
 5 files changed, 34 insertions(+), 52 deletions(-)
  

Comments

Tom Tromey Jan. 5, 2026, 5:39 p.m. UTC | #1
>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:

Andrew> Rename dwarf2_start_subfile to dwarf2_cu::start_subfile.  This
Andrew> refactor continues the work started in the previous commit.

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

Tom
  
Andrew Burgess Jan. 6, 2026, 1:22 p.m. UTC | #2
Tom Tromey <tom@tromey.com> writes:

>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
>
> Andrew> Rename dwarf2_start_subfile to dwarf2_cu::start_subfile.  This
> Andrew> refactor continues the work started in the previous commit.
>
> Thanks.
> Approved-By: Tom Tromey <tom@tromey.com>

I pushed patches #1 to #5 from this series.  I'll wait a bit longer with
the last two patches to see if anyone wants to comment.

Thanks,
Andrew
  

Patch

diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c
index b4da4dfe248..eb27dc2ff1b 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 d4a5ae65f3c..0fd64425e32 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 3e4e30fb227..2fc5c283c00 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 09568c02715..2c15deb0454 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -15976,32 +15976,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 4ae2236466f..e00383ce2e8 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.  */