]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: move subfile and symtab creation into dwarf2_cu method
authorAndrew Burgess <aburgess@redhat.com>
Thu, 27 Nov 2025 17:42:19 +0000 (17:42 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Tue, 6 Jan 2026 10:53:13 +0000 (10:53 +0000)
There are two places in the dwarf2/ code where we create subfiles and
symtabs for the entries in a dwarf2_cu's line_header.  The code in
each location is basically the same.

Move this code into a new dwarf2_cu member function.

In dwarf2/read.c the existing code had an additional task; this is
left in dwarf2/read.c in its own loop immediately after the call to
the new member function.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/cu.c
gdb/dwarf2/cu.h
gdb/dwarf2/line-program.c
gdb/dwarf2/read.c

index d2e630069354e041804b81ef1f732d6fdc5293dc..0abf25bf8a14e490ec6aa39b7f486c6ab5759c26 100644 (file)
@@ -23,6 +23,7 @@
 #include "filenames.h"
 #include "producer.h"
 #include "gdbsupport/pathstuff.h"
+#include "dwarf2/line-header.h"
 
 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE.  */
 
@@ -238,3 +239,24 @@ dwarf2_cu::set_producer (const char *producer)
 
   m_checked_producer = true;
 }
+
+/* See dwarf2/cu.h.  */
+
+void
+dwarf2_cu::create_subfiles_and_symtabs ()
+{
+  buildsym_compunit *builder = this->get_builder ();
+  compunit_symtab *cust = builder->get_compunit_symtab ();
+
+  for (file_entry &fe : this->line_header->file_names ())
+    {
+      dwarf2_start_subfile (*this, fe);
+      subfile *sf = builder->get_current_subfile ();
+
+      if (sf->symtab == nullptr)
+       sf->symtab = allocate_symtab (cust, sf->name.c_str (),
+                                     sf->name_for_id.c_str ());
+
+      fe.symtab = sf->symtab;
+    }
+}
index af444cfeb967eaec88c81f0568eaab5de70c6d01..c0596c35876a6e125ad4ea1b7f6a36835203ddf2 100644 (file)
@@ -72,6 +72,9 @@ struct dwarf2_cu
                                                 const char *comp_dir,
                                                 CORE_ADDR low_pc);
 
+  /* Create a subfile and symtab for every entry in the line_header.  */
+  void create_subfiles_and_symtabs ();
+
   /* Reset the builder.  */
   void reset_builder () { m_builder.reset (); }
 
index 06eb762eb8ac221bcaee6a4e869a977b22a609d7..0b8af07d47a01da031183d875deb71a74a0df71e 100644 (file)
@@ -699,18 +699,5 @@ dwarf_decode_lines (struct dwarf2_cu *cu, unrelocated_addr lowpc,
   /* Make sure a symtab is created for every file, even files
      which contain only variables (i.e. no code with associated
      line numbers).  */
-  buildsym_compunit *builder = cu->get_builder ();
-  struct compunit_symtab *cust = builder->get_compunit_symtab ();
-
-  for (file_entry &fe : cu->line_header->file_names ())
-    {
-      dwarf2_start_subfile (*cu, fe);
-      subfile *sf = builder->get_current_subfile ();
-
-      if (sf->symtab == nullptr)
-       sf->symtab = allocate_symtab (cust, sf->name.c_str (),
-                                     sf->name_for_id.c_str ());
-
-      fe.symtab = sf->symtab;
-    }
+  cu->create_subfiles_and_symtabs ();
 }
index 2f4cbd60720f7f70ede8e5f0822629827c021213..a99a2760af54ef3cce760c91280d9dc0b3464712 100644 (file)
@@ -6261,27 +6261,13 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
        = XOBNEWVEC (&cust->objfile ()->objfile_obstack,
                     struct symtab *, line_header->file_names_size ());
 
+      this->create_subfiles_and_symtabs ();
+
       auto &file_names = line_header->file_names ();
       for (i = 0; i < file_names.size (); ++i)
        {
          file_entry &fe = file_names[i];
-         dwarf2_start_subfile (*this, fe);
-         buildsym_compunit *b = get_builder ();
-         subfile *sf = b->get_current_subfile ();
-
-         if (sf->symtab == nullptr)
-           {
-             /* NOTE: start_subfile will recognize when it's been
-                passed a file it has already seen.  So we can't
-                assume there's a simple mapping from
-                cu->line_header->file_names to subfiles, plus
-                cu->line_header->file_names may contain dups.  */
-             const char *name = sf->name.c_str ();
-             const char *name_for_id = sf->name_for_id.c_str ();
-             sf->symtab = allocate_symtab (cust, name, name_for_id);
-           }
-
-         fe.symtab = b->get_current_subfile ()->symtab;
+         gdb_assert (fe.symtab != nullptr);
          tug_unshare->symtabs[i] = fe.symtab;
        }
     }