+2021-02-24 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * NEWS: Mention new 'maint info target-sections' command.
+ * maint.c (maintenance_info_target_sections): New function.
+ (_initialize_maint_cmds): Register new command.
+
2021-02-24 Andrew Burgess <andrew.burgess@embecosm.com>
* riscv-tdep.c (riscv_features_from_gdbarch_info): Rename to...
maintenance flush dcache
A new command to flush the dcache.
+maintenance info target-sections
+ Print GDB's internal target sections table.
+
* Changed commands
break [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]
+2021-02-24 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * gdb.texinfo (Files): Document new 'maint info target-sections'
+ command.
+
2021-02-17 Lancelot Six <lsix@lancelotsix.com>
PR cli/17290
Section contains common symbols.
@end table
@end table
+
+@kindex maint info target-sections
+@item maint info target-sections
+This command prints @value{GDBN}'s internal section table. For each
+target @value{GDBN} maintains a table containing the allocatable
+sections from all currently mapped objects, along with information
+about where the section is mapped.
+
@kindex set trust-readonly-sections
@cindex read-only sections
@item set trust-readonly-sections on
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)
{
&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,
+2021-02-24 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * gdb.base/maint-info-sections.exp: Add new tests.
+ (check_maint_info_target_sections_output): New proc.
+
2021-02-24 Andrew Burgess <andrew.burgess@embecosm.com>
* gdb.arch/riscv-default-tdesc.exp: New file.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# Test just for the 'maintenance info sections' command.
+# Test just for the 'maintenance info sections' command and the
+# 'maintenance info target-sections' command.
load_lib completion-support.exp
return -1
}
+# Check the output of 'maint info target-sections' command.
+proc check_maint_info_target_sections_output {prefix} {
+ global hex gdb_prompt
+
+ with_test_prefix $prefix {
+ # Check the output of the 'maint info target-sections' command.
+ # Ensures that all the lines have the expected format, and that we see
+ # an auxiliary information line after every section information line.
+ #
+ # We also check that every bfd section has the ALLOC flag.
+ set seen_header false
+ set seen_a_section false
+ set seen_aux_info false
+ set expecting_aux_info false
+ gdb_test_multiple "maint info target-sections" "" {
+ -re "^maint info target-sections\r\n" {
+ # Consume the command we sent to GDB that the terminal echo'd
+ # back.
+ exp_continue
+ }
+ -re "^From '\[^\r\n\]+', file type \[^\r\n\]+:\r\n" {
+ # There might be more than one header, but there should be at
+ # least one.
+ set seen_header true
+ if { $expecting_aux_info } {
+ fail $gdb_test_name
+ } else {
+ exp_continue
+ }
+ }
+ -re "^ \\\[\[0-9\]+\\\]\\s+$hex->$hex at $hex: \[^*\r\]+\\yALLOC\\y\[^*\r\]*\r\n" {
+ # A bfd section description line.
+ set seen_a_section true
+ if { $expecting_aux_info } {
+ fail $gdb_test_name
+ } else {
+ set expecting_aux_info true
+ exp_continue
+ }
+ }
+ -re "^\\s+Start: $hex, End: $hex, Owner token: $hex\r\n" {
+ # A target section auxiliary information line.
+ set seen_aux_info true
+ if { !$expecting_aux_info } {
+ fail $gdb_test_name
+ } else {
+ set expecting_aux_info false
+ exp_continue
+ }
+ }
+ -re "^$gdb_prompt $" {
+ gdb_assert { $seen_header && $seen_a_section && $seen_aux_info }
+ gdb_assert { !$expecting_aux_info }
+ pass $gdb_test_name
+ }
+ }
+ }
+}
+
# Check that 'maint info sections' output looks correct. When
# checking the lines for each section we reject section names starting
# with a '*' character, the internal *COM*, *UND*, *ABS*, and *IND*
}
}
+check_maint_info_target_sections_output "with executable"
+
# Restart GDB, but don't load the executable.
clean_restart
}
}
+# NOTE: We would like to check 'maint info target-sections' again
+# here, but GDB currently doesn't display the target sections table in
+# this case. This is a bug and will be fixed shortly!!
+
# Test the command line completion on 'maint info sections'. First
# the command line flag.
test_gdb_complete_unique \