diff options
author | Tom de Vries <tdevries@suse.de> | 2021-09-24 16:56:50 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2021-09-24 16:56:50 +0200 |
commit | fbd6ddfdbf6c41fed3f355e278f68e8e0433ad0d (patch) | |
tree | 19b00fb9b7a8e105b2df76e18dfe208b98fd8ef8 | |
parent | 66484acafd396ecb9bffd9f00ff3c37aec549c83 (diff) | |
download | fsf-binutils-gdb-fbd6ddfdbf6c41fed3f355e278f68e8e0433ad0d.zip fsf-binutils-gdb-fbd6ddfdbf6c41fed3f355e278f68e8e0433ad0d.tar.gz fsf-binutils-gdb-fbd6ddfdbf6c41fed3f355e278f68e8e0433ad0d.tar.bz2 |
[gdb/testsuite] Don't leave gdb instance running after function_range
A typical dwarf assembly test-case start like this:
...
standard_testfile .c -debug.S
set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
...
}
if { [prepare_for_testing "failed to prepare" ${testfile} \
[list $srcfile $asm_file] {nodebug}] } {
return -1
}
...
When accidentally using build_for_executable instead of
prepare_for_testing (or intentionally using it but forgetting to add
clean_restart $binfile or some such) the mistake may not be caught, because
another gdb instance is still running, and we may silently end up testing
compiler-generated DWARF.
This can be caused by something relatively obvious, like an earlier
prepare_for_testing or clean_restart, but also by something more obscure like
function_range, which may even be triggered by dwarf assembly like this:
...
{MACRO_AT_func {main}}
...
Fix this by calling gdb_exit at the end of function_range.
Also fix the fallout of that in test-case gdb.dwarf2/dw2-bad-elf.exp, where a
get_sizeof call used the gdb instance left lingering by function_range.
[ A better and more complete fix would add a new proc get_exec_info, that would
be called at the start of the dwarf assembly body:
...
Dwarf::assemble $asm_file {
get_exec_info {main foo} {int void*}
...
that would:
- do a prepare_for_testing with $srcfile (roughtly equivalent to what
MACRO_AT_func does,
- call function_range for all functions main and foo, without starting a
new gdb instance
- set corresponding variables at the call-site: main_start, main_len,
main_end, foo_start, foo_len, foo_end.
- get size for types int and void*
- set corresponding variables at the call-site: int_size, void_ptr_size.
- do a gdb_exit. ]
Tested on x86_64-linux.
-rw-r--r-- | gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp | 11 | ||||
-rw-r--r-- | gdb/testsuite/lib/dwarf.exp | 1 |
2 files changed, 9 insertions, 3 deletions
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp b/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp index 5ab08c18..d276bf8 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp @@ -36,10 +36,17 @@ if {![dwarf2_support]} { standard_testfile main.c -other.S -dwarf.S +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { + untested "failed to compile" + return -1 +} + +set int_size [get_sizeof "int" 4] + # Make some DWARF for the test. set asm_file [standard_output_file $srcfile3] Dwarf::assemble $asm_file { - global srcdir subdir srcfile srcfile2 + global srcdir subdir srcfile srcfile2 int_size declare_labels ranges_label_1 ranges_label_2 L1 L2 @@ -47,8 +54,6 @@ Dwarf::assemble $asm_file { set main_start [lindex $main_result 0] set main_length [lindex $main_result 1] - set int_size [get_sizeof "int" 4] - cu {} { DW_TAG_compile_unit { {DW_AT_language @DW_LANG_C} diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp index 87bb6c1..c248296 100644 --- a/gdb/testsuite/lib/dwarf.exp +++ b/gdb/testsuite/lib/dwarf.exp @@ -271,6 +271,7 @@ proc function_range { func src {options {debug}} } { } } + gdb_exit return [list "${func}_label - $func_label_offset" $func_length] } |