Skip to content

Commit

Permalink
Fix a few gdb.base/jit-simple.exp problems
Browse files Browse the repository at this point in the history
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  <[email protected]>

	* 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.
  • Loading branch information
palves committed Oct 6, 2016
1 parent 6bd7996 commit 5a122fb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
9 changes: 9 additions & 0 deletions gdb/testsuite/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2016-10-06 Pedro Alves <[email protected]>

* 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 <[email protected]>

* gdb.xml/extra-regs.xml: Update, end field now required, default type
Expand Down
54 changes: 24 additions & 30 deletions gdb/testsuite/gdb.base/jit-simple.exp
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,50 @@ 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} {
untested jit-simple.exp
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

0 comments on commit 5a122fb

Please sign in to comment.