]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: Use multiple minimal_symbol_readers in mipscoff_symfile_read
authorGuinevere Larsen <guinevere@redhat.com>
Thu, 12 Dec 2024 12:37:36 +0000 (09:37 -0300)
committerGuinevere Larsen <guinevere@redhat.com>
Tue, 3 Jun 2025 16:36:32 +0000 (13:36 -0300)
Currently, mipscoff_symfile_read uses a single minimal_symbol_reader to
get all minimal symbols from mdebug-formatted debuginfo, and from
alphacoff. This pattern has been around since minimal_symbol_reader has
been introduced, and from own research, there's no need to use the same
reader. This made it so mipscoff_symfile_read could call
mdebug_build_psymtabs directly, since the latter needs a reference to
the minsym reader object. The issue is that future commits need a
unified entrance point to read debuginfo, and this pattern is very
different to how elf does mdebug reading.

In fact, the elf mdebug reader does some preparatory steps and then
calls mdebug_build_psymtabs, so what the mips version does is just
spread these preparatory steps through the mipscoff function instead.

To make it easier for future commits to query debuginfo support
dynamically (as opposed to assuming things at compile time), this commit
introduces a new mipsmdebug_build_psymtabs function, which does similar
preparatory steps as elfmdebug_build_psymtabs. It is added to
mdebugread.c to help with maintaining a separation between reading an
objfile (in mipsread.c) and its debuginfo (mdebug), so that in the
future we have an easier time selectively disabling debuginfo formats
at compilation time. This should have no visible changes for the end
user.

The new function must receive the pointers to ecoff_debug_swap and
ecoff_debug_info because finding those structures based on the bfd
object necessitates including the headers libcoff.h and libecoff.h,
and those headers can't be included at the same time as libaout.h
- which mdebugread.c already uses.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/mdebugread.c
gdb/mdebugread.h
gdb/mipsread.c

index 72af1175bc270c8ed3082aa9661759dbd6c650ad..51e224fa135d1db307b2507e49a5c0348c2491e9 100644 (file)
@@ -4792,6 +4792,27 @@ elfmdebug_build_psymtabs (struct objfile *objfile,
   reader.install ();
 }
 
+/* see mdebugread.h.  */
+
+void
+mipsmdebug_build_psymtabs (struct objfile *objfile,
+                          const struct ecoff_debug_swap *swap,
+                          struct ecoff_debug_info *info)
+{
+  bfd *abfd = objfile->obfd.get ();
+
+  minimal_symbol_reader reader (objfile);
+
+  if (!(*swap->read_debug_info) (abfd, nullptr,
+                                info))
+    error (_("Error reading ECOFF debugging information: %s"),
+          bfd_errmsg (bfd_get_error ()));
+
+  mdebug_build_psymtabs (reader, objfile, swap, info);
+
+  reader.install ();
+}
+
 void _initialize_mdebugread ();
 void
 _initialize_mdebugread ()
index be26f465adae1e3379ac4bbb5c5f135f8ef2c220..a4a5aa99b62800c54a665f0ba80a0f17507a7eda 100644 (file)
@@ -46,4 +46,12 @@ extern void elfmdebug_build_psymtabs (struct objfile *,
                                      const struct ecoff_debug_swap *,
                                      asection *);
 
+/* Read ECOFF debugging information from a BFD section.  This is
+   called from mipsread.c.  It parses the section into a
+   ecoff_debug_info struct, and then lets the rest of the file handle
+   it as normal.  */
+extern void mipsmdebug_build_psymtabs (struct objfile *,
+                                      const struct ecoff_debug_swap *,
+                                      struct ecoff_debug_info *);
+
 #endif /* GDB_MDEBUGREAD_H */
index 5ffb97f4befde3343b42335e0c67f48ab4966512..b726b989c6e9e4a7d694c4e7669a92903ea5f9a4 100644 (file)
@@ -66,20 +66,16 @@ mipscoff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 {
   bfd *abfd = objfile->obfd.get ();
 
-  minimal_symbol_reader reader (objfile);
-
   /* Now that the executable file is positioned at symbol table,
      process it and define symbols accordingly.  */
 
-  if (!((*ecoff_backend (abfd)->debug_swap.read_debug_info)
-       (abfd, NULL, &ecoff_data (abfd)->debug_info)))
-    error (_("Error reading symbol table: %s"), bfd_errmsg (bfd_get_error ()));
-
-  mdebug_build_psymtabs (reader, objfile, &ecoff_backend (abfd)->debug_swap,
-                        &ecoff_data (abfd)->debug_info);
+  mipsmdebug_build_psymtabs (objfile, &ecoff_backend (abfd)->debug_swap,
+                            &ecoff_data (abfd)->debug_info);
 
   /* Add alpha coff dynamic symbols.  */
 
+  minimal_symbol_reader reader (objfile);
+
   read_alphacoff_dynamic_symtab (reader, objfile);
 
   /* Install any minimal symbols that have been collected as the current