diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-02-12 16:10:56 +0000 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-02-24 16:58:02 +0000 |
commit | 02a79309925c71591d825f8fc4e2b79ce0faa45b (patch) | |
tree | 45cef59400fc764b30f655e1933f46b30d2ed087 /gdb/maint.c | |
parent | 895b7b4e4bed9eee9d4a3d55bee876055736bfd3 (diff) | |
download | gdb-02a79309925c71591d825f8fc4e2b79ce0faa45b.zip gdb-02a79309925c71591d825f8fc4e2b79ce0faa45b.tar.gz gdb-02a79309925c71591d825f8fc4e2b79ce0faa45b.tar.bz2 |
gdb: add a new 'maint info target-sections' command
We already have a command 'maint info sections', this command prints
all sections from all known object files.
However, GDB maintains a second section table internally. This
section table is used when GDB wants to read directly from an object
file rather than actually reading memory on the target. As such only
some sections (the allocatable ones) are added to this secondary
section table.
I recently ran into a situation where some of GDB's optimisations for
reading directly from the files were not working. In 'maint info
sections' I could see that GDB knew about the object file, and did
know about the sections that it _should_ have been reading from. But
I couldn't ask GDB which sections it had copied into its secondary
section table.
This commit adds a new command 'maint info target-sections' that fills
this gap. This command lists only those sections that GDB has copied
into its secondary table.
You'll notice that the testsuite includes a comment indicating that
there's a bug in GDB. Normally this is not something I would add to
the testsuite, instead we should raise an actual bugzilla bug and then
mark an xfail, however, a later patch in this series will remove this
comment once the actual bug in GDB is fixed.
gdb/ChangeLog:
* NEWS: Mention new 'maint info target-sections' command.
* maint.c (maintenance_info_target_sections): New function.
(_initialize_maint_cmds): Register new command.
gdb/doc/ChangeLog:
* gdb.texinfo (Files): Document new 'maint info target-sections'
command.
gdb/testsuite/ChangeLog:
* gdb.base/maint-info-sections.exp: Add new tests.
(check_maint_info_target_sections_output): New proc.
Diffstat (limited to 'gdb/maint.c')
-rw-r--r-- | gdb/maint.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/gdb/maint.c b/gdb/maint.c index 707d156..bfdd1d5 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -464,6 +464,56 @@ maintenance_info_sections (const char *arg, int from_tty) maint_print_all_sections (_("Core file: "), core_bfd, nullptr, arg); } +/* Implement the "maintenance info target-sections" command. */ + +static void +maintenance_info_target_sections (const char *arg, int from_tty) +{ + bfd *abfd = nullptr; + int digits = 0; + const target_section_table *table + = target_get_section_table (current_top_target ()); + if (table == nullptr) + return; + + for (const target_section &sec : *table) + { + if (abfd == nullptr || sec.the_bfd_section->owner != abfd) + { + abfd = sec.the_bfd_section->owner; + digits = std::max (index_digits (gdb_bfd_count_sections (abfd)), + digits); + } + } + + struct gdbarch *gdbarch = nullptr; + int addr_size = 0; + abfd = nullptr; + for (const target_section &sec : *table) + { + if (sec.the_bfd_section->owner != abfd) + { + abfd = sec.the_bfd_section->owner; + gdbarch = gdbarch_from_bfd (abfd); + addr_size = gdbarch_addr_bit (gdbarch) / 8; + + printf_filtered (_("From '%s', file type %s:\n"), + bfd_get_filename (abfd), bfd_get_target (abfd)); + } + print_bfd_section_info (abfd, + sec.the_bfd_section, + nullptr, + digits); + /* The magic '8 + digits' here ensures that the 'Start' is aligned + with the output of print_bfd_section_info. */ + printf_filtered ("%*sStart: %s, End: %s, Owner token: %p\n", + (8 + digits), "", + hex_string_custom (sec.addr, addr_size), + hex_string_custom (sec.endaddr, addr_size), + sec.owner); + } +} + static void maintenance_print_statistics (const char *args, int from_tty) { @@ -1122,6 +1172,15 @@ Options:\n\ &maintenanceinfolist); set_cmd_completer_handle_brkchars (cmd, maint_info_sections_completer); + add_cmd ("target-sections", class_maintenance, + maintenance_info_target_sections, _("\ +List GDB's internal section table.\n\ +\n\ +Print the current targets section list. This is a sub-set of all\n\ +sections, from all objects currently loaded. Usually the ALLOC\n\ +sectoins."), + &maintenanceinfolist); + add_basic_prefix_cmd ("print", class_maintenance, _("Maintenance command for printing GDB internal state."), &maintenanceprintlist, "maintenance print ", 0, |