From: Guinevere Larsen Date: Thu, 12 Dec 2024 12:37:36 +0000 (-0300) Subject: gdb: Use multiple minimal_symbol_readers in mipscoff_symfile_read X-Git-Tag: binutils-2_45~419 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6844666471cca07bd1eaa8f13af74eda7f373d90;p=thirdparty%2Fbinutils-gdb.git gdb: Use multiple minimal_symbol_readers in mipscoff_symfile_read 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 --- diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 72af1175bc2..51e224fa135 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -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 () diff --git a/gdb/mdebugread.h b/gdb/mdebugread.h index be26f465ada..a4a5aa99b62 100644 --- a/gdb/mdebugread.h +++ b/gdb/mdebugread.h @@ -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 */ diff --git a/gdb/mipsread.c b/gdb/mipsread.c index 5ffb97f4bef..b726b989c6e 100644 --- a/gdb/mipsread.c +++ b/gdb/mipsread.c @@ -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