diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-02-05 11:16:31 +0000 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-02-11 10:26:18 +0000 |
commit | 4790db149699b21113c566b8b9249953038fd3a7 (patch) | |
tree | 7db522b99ff19d4ba66e78141059bcedacbf59df /gdb/testsuite/gdb.base | |
parent | f4be677293a68a4d54f978bccbd703c3909b5149 (diff) | |
download | gdb-4790db149699b21113c566b8b9249953038fd3a7.zip gdb-4790db149699b21113c566b8b9249953038fd3a7.tar.gz gdb-4790db149699b21113c566b8b9249953038fd3a7.tar.bz2 |
gdb: 'maint info sections' - handle the no executable case
The 'maint info sections' command is split into two blocks or work,
first if there's an executable then the sections from the executable,
and optionally all other loaded object files are printed. Then all
the sections from any core file are printed.
I ran into a situation where (for various reasons) I wasn't using a
main executable. Instead I connected to a remote target and used
add-symbol-file. This allowed me to debug an image that was already
loaded on the remote system.
Unfortunately, when I tried to use 'maint info sections' I saw
nothing. The reason is that the loop over all object files is hidden
behind a check that we have a main executable.
This commit removes this check and merges together some duplicate
code. I also (I think) made the output of this command cleaner.
Here is the original output of 'maint info sections':
Exec file:
`/tmp/hello.x', file type elf64-x86-64.
[0] 0x004002a8->0x004002c4 at 0x000002a8: .interp ALLOC LOAD READONLY DATA HAS_CONTENTS
[1] 0x004002c4->0x004002e8 at 0x000002c4: .note.gnu.build-id ALLOC LOAD READONLY DATA HAS_CONTENTS
...
And my modified output:
Exec file: `/home/andrew/tmp/hello.x', file type elf64-x86-64.
[0] 0x004002a8->0x004002c4 at 0x000002a8: .interp ALLOC LOAD READONLY DATA HAS_CONTENTS
[1] 0x004002c4->0x004002e8 at 0x000002c4: .note.gnu.build-id ALLOC LOAD READONLY DATA HAS_CONTENTS
...
The forced newline after 'Exec file: ' has been removed. This is now
a wrap point (in case the filename is very long).
Here is the original output of 'maint info sections ALLOBJ':
Exec file:
`/tmp/hello.x', file type elf64-x86-64.
Object file: /tmp/hello.x
[0] 0x004002a8->0x004002c4 at 0x000002a8: .interp ALLOC LOAD READONLY DATA HAS_CONTENTS
[1] 0x004002c4->0x004002e8 at 0x000002c4: .note.gnu.build-id ALLOC LOAD READONLY DATA HAS_CONTENTS
...
Object file: /lib64/ld-linux-x86-64.so.2
[0] 0x7ffff7fd12a8->0x7ffff7fd12c8 at 0x000002a8: .note.gnu.property ALLOC LOAD READONLY DATA HAS_CONTENTS
[1] 0x7ffff7fd12c8->0x7ffff7fd12ec at 0x000002c8: .note.gnu.build-id ALLOC LOAD READONLY DATA HAS_CONTENTS
...
And my modified output:
Exec file: `/tmp/hello.x', file type elf64-x86-64.
[0] 0x004002a8->0x004002c4 at 0x000002a8: .interp ALLOC LOAD READONLY DATA HAS_CONTENTS
[1] 0x004002c4->0x004002e8 at 0x000002c4: .note.gnu.build-id ALLOC LOAD READONLY DATA HAS_CONTENTS
...
Object file: `/lib64/ld-linux-x86-64.so.2', file type elf64-x86-64.
[0] 0x7ffff7fd12a8->0x7ffff7fd12c8 at 0x000002a8: .note.gnu.property ALLOC LOAD READONLY DATA HAS_CONTENTS
[1] 0x7ffff7fd12c8->0x7ffff7fd12ec at 0x000002c8: .note.gnu.build-id ALLOC LOAD READONLY DATA HAS_CONTENTS
...
The executable now only gets a single header line. The header line
for the additional object files is no longer indented as it was
before, and the line is laid out in a similar style to the main
executable line (with quotes and file type information).
And of course, the biggest change. If GDB is started with no
executable, but then the user does 'add-symbol-file ....' followed by
'maint info sections ALLOBJ', previously they got nothing, now they
get:
Object file: `/tmp/hello.x', file type elf64-x86-64.
[0] 0x004002a8->0x004002c4 at 0x000002a8: .interp ALLOC LOAD READONLY DATA HAS_CONTENTS
[1] 0x004002c4->0x004002e8 at 0x000002c4: .note.gnu.build-id ALLOC LOAD READONLY DATA HAS_CONTENTS
...
gdb/ChangeLog:
* maint.c (print_bfd_section_info_maybe_relocated): Delete,
functionality merged into...
(maint_print_all_sections): ...this new function.
(maintenance_info_sections): Make use of maint_print_all_sections,
allow all objects to be printed even where there's no executable.
gdb/testsuite/ChangeLog:
* gdb.base/maint-info-sections.exp: Update expected output, and
add additional tests.
Diffstat (limited to 'gdb/testsuite/gdb.base')
-rw-r--r-- | gdb/testsuite/gdb.base/maint-info-sections.exp | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/gdb/testsuite/gdb.base/maint-info-sections.exp b/gdb/testsuite/gdb.base/maint-info-sections.exp index 6c41ff2..19e5c12 100644 --- a/gdb/testsuite/gdb.base/maint-info-sections.exp +++ b/gdb/testsuite/gdb.base/maint-info-sections.exp @@ -34,7 +34,7 @@ if ![runto_main] then { set seen_header false set seen_a_section false gdb_test_multiple "maint info sections" "general output check" { - -re "Exec file:\r\n\[\t ]+`\[^'\]+', file type \[^.\]+\.\r\n" { + -re "Exec file: `\[^'\]+', file type \[^.\]+\.\r\n" { set seen_header true exp_continue } @@ -63,18 +63,18 @@ set text_section ".text" set data_section ".data" gdb_test_multiple "maint info sections" "" { - -re -wrap "Exec file:\r\n.*${binfile}., file type.*ER_RO.*" { + -re -wrap "Exec file: .*${binfile}., file type.*ER_RO.*" { # Looks like RealView which uses different section names. set text_section ER_RO set data_section ER_RW pass "maint info sections" } - -re -wrap "Exec file:\r\n.*${binfile}., file type.*neardata.*" { + -re -wrap "Exec file: .*${binfile}., file type.*neardata.*" { # c6x doesn't have .data section. It has .neardata and .fardata section. set data_section ".neardata" pass "maint info sections" } - -re -wrap "Exec file:\r\n.*${binfile}., file type.*" { + -re -wrap "Exec file: .*${binfile}., file type.*" { pass "maint info sections" } } @@ -125,3 +125,36 @@ gdb_test_multiple "maint info sections DATA" "" { pass $gdb_test_name } } + +# Restart GDB, but don't load the executable. +clean_restart + +# Now load the executable in as a symbol file. +gdb_test "add-symbol-file ${binfile}" ".*" \ + "load the executable as a symbol file" \ + "add symbol table from file \"${binfile}\"\r\n\\(y or n\\) " \ + "y" + +# As we have no object file 'maint info sections' will print nothing. +gdb_test_no_output "maint info sections" \ + "no output when no executable is set" + +# Check that the executable shows up as an object file when ALLOBJ is +# used. +set seen_header false +set seen_a_section false +gdb_test_multiple "maint info sections ALLOBJ" "" { + -re "Object file: `${binfile}', file type \[^.\]+\.\r\n" { + set seen_header true + exp_continue + } + -re "^ \\\[\[0-9\]+\\\]\[\t \]+$hex->$hex at $hex: \[^*\r\]+\r\n" { + set seen_a_section true + exp_continue + } + -re "^$gdb_prompt $" { + gdb_assert { $seen_header && $seen_a_section } \ + "ensure header and section seen in ALLOBJ case" + pass $gdb_test_name + } +} |