]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: move loops into locate_dw{o,z}_sections
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 6 May 2025 17:03:46 +0000 (13:03 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 12 May 2025 18:05:21 +0000 (14:05 -0400)
For a subsequent patch, it would be easier if the loop over sections
inside locate_dwo_sections (I want to maintain some state for the
duration of the loop).  Move the for loop in there.  And because
locate_dwz_sections is very similar, modify that one too, to keep both
in sync.

Change-Id: I90b3d44184910cc2d86af265bb4b41828a5d2c2e
Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/dwz.c
gdb/dwarf2/read.c
gdb/dwarf2/read.h

index 583103b4bae4e121bf4dd5cbe620565a782b5788..59fe8e4886b4290a945bef663e8fa3ad4a745fc4 100644 (file)
@@ -56,35 +56,37 @@ dwz_file::read_string (struct objfile *objfile, LONGEST str_offset)
 /* A helper function to find the sections for a .dwz file.  */
 
 static void
-locate_dwz_sections (struct objfile *objfile, bfd *abfd, asection *sectp,
-                    dwz_file *dwz_file)
+locate_dwz_sections (objfile *objfile, dwz_file &dwz_file)
 {
-  dwarf2_section_info *sect = nullptr;
+  for (asection *sec : gdb_bfd_sections (dwz_file.dwz_bfd))
+    {
+      dwarf2_section_info *sect = nullptr;
 
-  /* Note that we only support the standard ELF names, because .dwz
+      /* Note that we only support the standard ELF names, because .dwz
      is ELF-only (at the time of writing).  */
-  if (dwarf2_elf_names.abbrev.matches (sectp->name))
-    sect = &dwz_file->abbrev;
-  else if (dwarf2_elf_names.info.matches (sectp->name))
-    sect = &dwz_file->info;
-  else if (dwarf2_elf_names.str.matches (sectp->name))
-    sect = &dwz_file->str;
-  else if (dwarf2_elf_names.line.matches (sectp->name))
-    sect = &dwz_file->line;
-  else if (dwarf2_elf_names.macro.matches (sectp->name))
-    sect = &dwz_file->macro;
-  else if (dwarf2_elf_names.gdb_index.matches (sectp->name))
-    sect = &dwz_file->gdb_index;
-  else if (dwarf2_elf_names.debug_names.matches (sectp->name))
-    sect = &dwz_file->debug_names;
-  else if (dwarf2_elf_names.types.matches (sectp->name))
-    sect = &dwz_file->types;
-
-  if (sect != nullptr)
-    {
-      sect->s.section = sectp;
-      sect->size = bfd_section_size (sectp);
-      sect->read (objfile);
+      if (dwarf2_elf_names.abbrev.matches (sec->name))
+       sect = &dwz_file.abbrev;
+      else if (dwarf2_elf_names.info.matches (sec->name))
+       sect = &dwz_file.info;
+      else if (dwarf2_elf_names.str.matches (sec->name))
+       sect = &dwz_file.str;
+      else if (dwarf2_elf_names.line.matches (sec->name))
+       sect = &dwz_file.line;
+      else if (dwarf2_elf_names.macro.matches (sec->name))
+       sect = &dwz_file.macro;
+      else if (dwarf2_elf_names.gdb_index.matches (sec->name))
+       sect = &dwz_file.gdb_index;
+      else if (dwarf2_elf_names.debug_names.matches (sec->name))
+       sect = &dwz_file.debug_names;
+      else if (dwarf2_elf_names.types.matches (sec->name))
+       sect = &dwz_file.types;
+
+      if (sect != nullptr)
+       {
+         sect->s.section = sec;
+         sect->size = bfd_section_size (sec);
+         sect->read (objfile);
+       }
     }
 }
 
@@ -392,9 +394,7 @@ dwz_file::read_dwz_file (dwarf2_per_objfile *per_objfile)
 
   dwz_file_up result (new dwz_file (std::move (dwz_bfd)));
 
-  for (asection *sec : gdb_bfd_sections (result->dwz_bfd))
-    locate_dwz_sections (per_objfile->objfile, result->dwz_bfd.get (),
-                        sec, result.get ());
+  locate_dwz_sections (per_objfile->objfile, *result);
 
   gdb_bfd_record_inclusion (per_bfd->obfd, result->dwz_bfd.get ());
   bfd_cache_close (result->dwz_bfd.get ());
index 71fa793315ff66881b2a0282f8e5e46ac26ee305..550968abc95c9eb8b35fa2718cc3f1305dd8664c 100644 (file)
@@ -7512,45 +7512,48 @@ cutu_reader::open_dwo_file (dwarf2_per_bfd *per_bfd, const char *file_name,
    size of each of the DWO debugging sections we are interested in.  */
 
 void
-cutu_reader::locate_dwo_sections (struct objfile *objfile, bfd *abfd,
-                                 asection *sectp, dwo_sections *dwo_sections)
+cutu_reader::locate_dwo_sections (objfile *objfile, dwo_file &dwo_file)
 {
   const struct dwop_section_names *names = &dwop_section_names;
-
-  struct dwarf2_section_info *dw_sect = nullptr;
-
-  if (names->abbrev_dwo.matches (sectp->name))
-    dw_sect = &dwo_sections->abbrev;
-  else if (names->info_dwo.matches (sectp->name))
-    dw_sect = &dwo_sections->infos.emplace_back (dwarf2_section_info {});
-  else if (names->line_dwo.matches (sectp->name))
-    dw_sect = &dwo_sections->line;
-  else if (names->loc_dwo.matches (sectp->name))
-    dw_sect = &dwo_sections->loc;
-  else if (names->loclists_dwo.matches (sectp->name))
-    dw_sect = &dwo_sections->loclists;
-  else if (names->macinfo_dwo.matches (sectp->name))
-    dw_sect = &dwo_sections->macinfo;
-  else if (names->macro_dwo.matches (sectp->name))
-    dw_sect = &dwo_sections->macro;
-  else if (names->rnglists_dwo.matches (sectp->name))
-    dw_sect = &dwo_sections->rnglists;
-  else if (names->str_dwo.matches (sectp->name))
-    dw_sect = &dwo_sections->str;
-  else if (names->str_offsets_dwo.matches (sectp->name))
-    dw_sect = &dwo_sections->str_offsets;
-  else if (names->types_dwo.matches (sectp->name))
-    dw_sect = &dwo_sections->types.emplace_back (dwarf2_section_info {});
-
-  if (dw_sect != nullptr)
-    {
-      /* Make sure we don't overwrite a section info that has been filled in
+  dwo_sections &dwo_sections = dwo_file.sections;
+
+  for (asection *sec : gdb_bfd_sections (dwo_file.dbfd))
+    {
+      struct dwarf2_section_info *dw_sect = nullptr;
+
+      if (names->abbrev_dwo.matches (sec->name))
+       dw_sect = &dwo_sections.abbrev;
+      else if (names->info_dwo.matches (sec->name))
+       dw_sect = &dwo_sections.infos.emplace_back (dwarf2_section_info {});
+      else if (names->line_dwo.matches (sec->name))
+       dw_sect = &dwo_sections.line;
+      else if (names->loc_dwo.matches (sec->name))
+       dw_sect = &dwo_sections.loc;
+      else if (names->loclists_dwo.matches (sec->name))
+       dw_sect = &dwo_sections.loclists;
+      else if (names->macinfo_dwo.matches (sec->name))
+       dw_sect = &dwo_sections.macinfo;
+      else if (names->macro_dwo.matches (sec->name))
+       dw_sect = &dwo_sections.macro;
+      else if (names->rnglists_dwo.matches (sec->name))
+       dw_sect = &dwo_sections.rnglists;
+      else if (names->str_dwo.matches (sec->name))
+       dw_sect = &dwo_sections.str;
+      else if (names->str_offsets_dwo.matches (sec->name))
+       dw_sect = &dwo_sections.str_offsets;
+      else if (names->types_dwo.matches (sec->name))
+       dw_sect = &dwo_sections.types.emplace_back (dwarf2_section_info {});
+
+      if (dw_sect != nullptr)
+       {
+         /* Make sure we don't overwrite a section info that has been filled in
         already.  */
-      gdb_assert (!dw_sect->readin);
+         gdb_assert (!dw_sect->readin);
 
-      dw_sect->s.section = sectp;
-      dw_sect->size = bfd_section_size (sectp);
-      dw_sect->read (objfile);
+         dw_sect->s.section = sec;
+         dw_sect->size = bfd_section_size (sec);
+         dw_sect->read (objfile);
+       }
     }
 }
 
@@ -7578,9 +7581,7 @@ cutu_reader::open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
   dwo_file->comp_dir = comp_dir;
   dwo_file->dbfd = std::move (dbfd);
 
-  for (asection *sec : gdb_bfd_sections (dwo_file->dbfd))
-    this->locate_dwo_sections (per_objfile->objfile, dwo_file->dbfd.get (), sec,
-                              &dwo_file->sections);
+  this->locate_dwo_sections (per_objfile->objfile, *dwo_file);
 
   /* There is normally just one .debug_info.dwo section in a DWO file.  But when
      building with -fdebug-types-section, gcc produces multiple .debug_info.dwo
index 5b4c8f673a0f0b01edf929749f8cb9a8af9e3e88..aaac5e7cbbfc6ae1dab321c89fa2918c8e45b66b 100644 (file)
@@ -1029,8 +1029,7 @@ private:
   dwo_file_up open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
                                      const char *comp_dir);
 
-  void locate_dwo_sections (struct objfile *objfile, bfd *abfd, asection *sectp,
-                           struct dwo_sections *dwo_sections);
+  void locate_dwo_sections (objfile *objfile, dwo_file &dwo_file);
 
   void create_dwo_unit_hash_tables (dwo_file &dwo_file, dwarf2_cu &skeleton_cu,
                                    dwarf2_section_info &section,