Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] gdb/dwarf: move loops into locate_dw{o,z}_sections
@ 2025-05-06 17:03 Simon Marchi
  2025-05-06 17:03 ` [PATCH 2/2] gdb/dwarf: skip broken .debug_macro.dwo Simon Marchi
  2025-05-12 17:52 ` [PATCH 1/2] gdb/dwarf: move loops into locate_dw{o,z}_sections Tom Tromey
  0 siblings, 2 replies; 8+ messages in thread
From: Simon Marchi @ 2025-05-06 17:03 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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
---
 gdb/dwarf2/dwz.c  | 60 ++++++++++++++++++-------------------
 gdb/dwarf2/read.c | 75 ++++++++++++++++++++++++-----------------------
 gdb/dwarf2/read.h |  3 +-
 3 files changed, 69 insertions(+), 69 deletions(-)

diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c
index 583103b4bae4..59fe8e4886b4 100644
--- a/gdb/dwarf2/dwz.c
+++ b/gdb/dwarf2/dwz.c
@@ -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;
-
-  /* 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)
+  for (asection *sec : gdb_bfd_sections (dwz_file.dwz_bfd))
     {
-      sect->s.section = sectp;
-      sect->size = bfd_section_size (sectp);
-      sect->read (objfile);
+      dwarf2_section_info *sect = nullptr;
+
+      /* 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 (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 ());
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 71fa793315ff..550968abc95c 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -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;
+  dwo_sections &dwo_sections = dwo_file.sections;
 
-  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)
+  for (asection *sec : gdb_bfd_sections (dwo_file.dbfd))
     {
-      /* Make sure we don't overwrite a section info that has been filled in
-	 already.  */
-      gdb_assert (!dw_sect->readin);
+      struct dwarf2_section_info *dw_sect = nullptr;
 
-      dw_sect->s.section = sectp;
-      dw_sect->size = bfd_section_size (sectp);
-      dw_sect->read (objfile);
+      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);
+
+	  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
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 5b4c8f673a0f..aaac5e7cbbfc 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -1029,8 +1029,7 @@ class cutu_reader
   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,

base-commit: 998165ba99a3bcc80ba0b196223f4d49623e87b4
-- 
2.49.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-05-12 21:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-06 17:03 [PATCH 1/2] gdb/dwarf: move loops into locate_dw{o,z}_sections Simon Marchi
2025-05-06 17:03 ` [PATCH 2/2] gdb/dwarf: skip broken .debug_macro.dwo Simon Marchi
2025-05-12 17:55   ` Tom Tromey
2025-05-12 18:08     ` Simon Marchi
2025-05-12 18:48       ` Tom Tromey
2025-05-12 18:50         ` Simon Marchi
2025-05-12 21:06           ` Tom Tromey
2025-05-12 17:52 ` [PATCH 1/2] gdb/dwarf: move loops into locate_dw{o,z}_sections Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox