aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/NEWS3
-rw-r--r--gdb/doc/ChangeLog5
-rw-r--r--gdb/doc/gdb.texinfo8
-rw-r--r--gdb/maint.c59
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.base/maint-info-sections.exp68
7 files changed, 153 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e136c98..41e480a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
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...
(riscv_features_from_bfd): ...this. Change parameter type to
'bfd*', and update as required.
diff --git a/gdb/NEWS b/gdb/NEWS
index 1dfbbc6..7f5a745 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -47,6 +47,9 @@ maintenance flush register-cache
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]
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 7f324de..add31a0 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+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
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 90f0c76..80ccf74 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -20668,6 +20668,14 @@ COFF shared library information.
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
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,
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 4d2d543..ddc7c18 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
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.
2021-02-24 Andrew Burgess <andrew.burgess@embecosm.com>
diff --git a/gdb/testsuite/gdb.base/maint-info-sections.exp b/gdb/testsuite/gdb.base/maint-info-sections.exp
index 07c53b1..17e38eb 100644
--- a/gdb/testsuite/gdb.base/maint-info-sections.exp
+++ b/gdb/testsuite/gdb.base/maint-info-sections.exp
@@ -13,7 +13,8 @@
# 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
@@ -29,6 +30,65 @@ if ![runto_main] then {
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*
@@ -128,6 +188,8 @@ gdb_test_multiple "maint info sections DATA" "" {
}
}
+check_maint_info_target_sections_output "with executable"
+
# Restart GDB, but don't load the executable.
clean_restart
@@ -161,6 +223,10 @@ gdb_test_multiple "maint info sections -all-objects" "" {
}
}
+# 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 \