From: Pedro Alves Date: Thu, 6 Oct 2016 11:53:51 +0000 (+0100) Subject: Fix a few gdb.base/jit-simple.exp problems X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5a122fbc307f35093b8fe038a8e6caa51b4d0dae;p=binutils-gdb.git Fix a few gdb.base/jit-simple.exp problems I noticed that we sometimes get this: (gdb) print &__jit_debug_descriptor $1 = (struct jit_descriptor *) 0x601040 <__jit_debug_descriptor> (gdb) PASS: gdb.base/jit-simple.exp: blah 1 [...] (gdb) run [...] Starting program: build/gdb/testsuite/outputs/gdb.base/jit-simple/jit-simple Unsupported JIT protocol version 4 in descriptor (expected 1) Breakpoint 2, main () at src/gdb/testsuite/gdb.base/jit-simple.c:36 36 return 0; (gdb) print &__jit_debug_descriptor $2 = (struct jit_descriptor *) 0x601040 <__jit_debug_descriptor> (gdb) PASS: gdb.base/jit-simple.exp: blah 1 All tests PASSed, but note the "Unsupported JIT protocol version 4" message. Also notice that "__jit_debug_descriptor" has the same address before and after the rerun, while the test is built in a way that should make that address change between runs. The test doesn't catch any of this because it doesn't compare before/after addresses. And then notice the "blah 1" test messages. "blah" is clearly a WIP message, but it should be at least "blah 2" the second time. :-) The reason this sometimes happens is that the test recompiles the program and expects gdb to reload it automaticallyt on "run". However, if the original program and the new recompilation happen to be in the same second, then gdb does not realize that the binary needs to be reloaded. (This is an old problem out of scope of this series.) If that happens, then GDB ends up using the wrong symbols for the program that it spawns, reads the JIT descriptor out of the wrong address, finds garbage, and prints that "unsupported version" notice. Fix that in the same way gdb.base/reread.exp handles it -- by sleeping one second before recompiling. gdb/testsuite/ChangeLog: 2016-10-06 Pedro Alves * gdb.base/jit-simple.exp (top level) Delete get_compiler_info call. (jit_run): Delete. (jit_test_reread): Use with_test_prefix. Reload the main binary explicitly. Compare the before/after addresses of the JIT descriptor. --- diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index c38b9778594..5335344a06a 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2016-10-06 Pedro Alves + + * gdb.base/jit-simple.exp (top level) Delete get_compiler_info + call. + (jit_run): Delete. + (jit_test_reread): Use with_test_prefix. Reload the main binary + explicitly. Compare the before/after addresses of the JIT + descriptor. + 2016-08-15 Doug Evans * gdb.xml/extra-regs.xml: Update, end field now required, default type diff --git a/gdb/testsuite/gdb.base/jit-simple.exp b/gdb/testsuite/gdb.base/jit-simple.exp index ad99c3086e0..6fe6011baa1 100644 --- a/gdb/testsuite/gdb.base/jit-simple.exp +++ b/gdb/testsuite/gdb.base/jit-simple.exp @@ -18,16 +18,6 @@ if {[skip_shlib_tests]} { return -1 } -if {[get_compiler_info]} { - warning "Could not get compiler info" - untested jit-simple.exp - return 1 -} - -# -# test running programs -# - standard_testfile if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} { @@ -35,39 +25,43 @@ if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} { return -1 } -# A helper for jit_test_reread that invokes gdb_run_cmd. -proc jit_run {msg} { - global decimal gdb_prompt - - gdb_run_cmd - gdb_test "" "Inferior .* exited.*" $msg -} - # Test re-running an inferior with a JIT descriptor, where the JIT # descriptor changes address between runs. # http://sourceware.org/bugzilla/show_bug.cgi?id=13431 proc jit_test_reread {} { global testfile binfile subdir srcfile srcdir + global hex - clean_restart $testfile + with_test_prefix "initial run" { + clean_restart $testfile - # jit_run "initial run" - runto_main - - gdb_test "print &__jit_debug_descriptor" "= .*" "blah 1" + runto_main - gdb_rename_execfile $binfile ${binfile}x + set addr_before [get_hexadecimal_valueof "&__jit_debug_descriptor" 0 \ + "get address of __jit_debug_descriptor"] + } - if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DSPACER}] != "" } { - fail "recompile $srcfile" - } else { - pass "recompile $srcfile" + with_test_prefix "second run" { + # Ensure that the new executable is at least one second newer + # than the old. If the recompilation happens in the same + # second, gdb might not reload the executable automatically. + sleep 1 - # jit_run "second run" + gdb_rename_execfile $binfile ${binfile}x + if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DSPACER}] != "" } { + fail "recompile" + return + } else { + pass "recompile" + } runto_main - gdb_test "print &__jit_debug_descriptor" "= .*" "blah 1" + + set addr_after [get_hexadecimal_valueof "&__jit_debug_descriptor" 0 \ + "get address of __jit_debug_descriptor"] } + + gdb_assert {$addr_before != $addr_after} "address changed" } jit_test_reread