-# Copyright 2012-2013 Free Software Foundation, Inc.
+# Copyright 2012-2019 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# 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 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
+
+# Test both the case of the JIT reader being included in the main
+# program directly, and the case of the JIT reader being split out to
+# a shared library.
+
+# For completeness, also test when the JIT descriptor does not change
+# address between runs.
+
if {[skip_shlib_tests]} {
- untested jit-simple.exp
+ untested "skipping shared library tests"
return -1
}
-if {[get_compiler_info]} {
- warning "Could not get compiler info"
- untested jit-simple.exp
- return 1
-}
+standard_testfile
-#
-# test running programs
-#
+set libname $testfile-jit
+set srcfile_lib $srcdir/$subdir/$libname.c
+set binfile_lib [standard_output_file $libname.so]
-set testfile jit-simple
-set srcfile ${testfile}.c
-set binfile ${objdir}/${subdir}/${testfile}
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
- untested jit-simple.exp
- return -1
+# Build a standalone JIT binary.
+
+proc build_standalone_jit {{options ""}} {
+ global testfile srcfile binfile
+
+ lappend options "debug"
+
+ if {[build_executable $testfile.exp $testfile $srcfile $options] == -1} {
+ return -1
+ }
+
+ return 0
}
-# A helper for jit_test_reread that invokes gdb_run_cmd.
-proc jit_run {msg} {
- global decimal gdb_prompt
+# Build the shared library JIT.
- gdb_run_cmd
- gdb_expect {
- -re "Inferior .* exited.*$gdb_prompt $" {
- pass $msg
- }
- -re ".*$gdb_prompt $" {
- fail $msg
- }
+proc build_shared_jit {{options ""}} {
+ global testfile
+ global srcfile_lib binfile_lib
+
+ lappend options "debug additional_flags=-fPIC"
+ if { [gdb_compile_shlib $srcfile_lib $binfile_lib $options] != "" } {
+ return -1
}
+
+ return 0
}
-# 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
+if {[build_standalone_jit] == -1} {
+ untested "failed to compile standalone testcase"
+ return
+}
- clean_restart $testfile
+if {[build_shared_jit] == -1} {
+ untested "failed to compile shared library testcase"
+ return
+}
+
+# Built the program that loads the JIT library.
+set srcfile_dl $testfile-dl.c
+set binfile_dl $binfile-dl
+set options [list debug shlib=${binfile_lib}]
+if {[gdb_compile ${srcdir}/${subdir}/${srcfile_dl} $binfile_dl executable \
+ [list debug shlib=$binfile_lib]] == -1 } {
+ untested "failed to compile"
+ return -1
+}
- # jit_run "initial run"
- runto_main
+# STANDALONE is true when the JIT reader is included directly in the
+# main program. False when the JIT reader is in a separate shared
+# library. If CHANGE_ADDR is true, force changing the JIT descriptor
+# changes address between runs.
+proc jit_test_reread {standalone change_addr} {
+ global testfile binfile subdir srcfile srcdir binfile_lib binfile_dl
+ global hex
+
+ with_test_prefix "initial run" {
+ if {$standalone} {
+ clean_restart $binfile
+ } else {
+ clean_restart $binfile_dl
+ }
- 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"
+ gdb_test "maint info breakpoints" \
+ "jit events keep y $hex <__jit_debug_register_code>.*" \
+ "maint info breakpoints shows jit breakpoint"
+ }
- # jit_run "second run"
+ 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
+
+ if ${change_addr} {
+ set options "additional_flags=-DSPACER"
+ if {$standalone} {
+ gdb_rename_execfile $binfile ${binfile}x
+ set res [build_standalone_jit $options]
+ } else {
+ gdb_rename_execfile $binfile_lib ${binfile_lib}x
+ set res [build_shared_jit $options]
+ }
+ if { $res == -1 } {
+ 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"]
+
+ # This used to crash in the JIT-in-shared-library case:
+ # https://sourceware.org/bugzilla/show_bug.cgi?id=11094
+ gdb_test "maint info breakpoints" \
+ "jit events keep y $hex <__jit_debug_register_code>.*" \
+ "maint info breakpoints shows jit breakpoint"
+ }
+
+ if ${change_addr} {
+ gdb_assert {$addr_before != $addr_after} "address changed"
+ } else {
+ gdb_assert {$addr_before == $addr_after} "address didn't change"
}
}
-jit_test_reread
+foreach standalone {1 0} {
+ with_test_prefix [expr ($standalone)?"standalone":"shared"] {
+ with_test_prefix "change addr" {
+ jit_test_reread $standalone 1
+ }
+ with_test_prefix "same addr" {
+ jit_test_reread $standalone 0
+ }
+ }
+}