1 # Copyright 2011-2016 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 if {[skip_shlib_tests]} {
21 if {[get_compiler_info]} {
22 warning "Could not get compiler info"
27 # Compile the testcase program and library. BINSUFFIX is the suffix
28 # to append to the program and library filenames, to make them unique
29 # between invocations. OPTIONS is passed to gdb_compile when
30 # compiling the program.
32 proc compile_jit_test {testname binsuffix options} {
33 global testfile srcfile binfile srcdir subdir
34 global solib_testfile solib_srcfile solib_binfile solib_binfile_test_msg
35 global solib_binfile_target
38 set srcfile ${testfile}.c
39 set binfile [standard_output_file $testfile$binsuffix]
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
41 executable [concat debug $options]] != "" } {
46 set solib_testfile "jit-solib"
47 set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c"
48 set solib_binfile [standard_output_file ${solib_testfile}$binsuffix.so]
49 set solib_binfile_test_msg "SHLIBDIR/${solib_testfile}$binsuffix.so"
51 # Note: compiling without debug info: the library goes through
52 # symbol renaming by munging on its symbol table, and that
53 # wouldn't work for .debug sections. Also, output for "info
54 # function" changes when debug info is present.
55 if { [gdb_compile_shlib ${solib_srcfile} ${solib_binfile} {-fPIC}] != "" } {
60 set solib_binfile_target [gdb_remote_download target ${solib_binfile}]
65 # Detach, restart GDB, and re-attach to the program.
67 proc clean_reattach {} {
68 global decimal gdb_prompt srcfile testfile
70 # Get PID of test program.
72 set test "get inferior process ID"
73 gdb_test_multiple "p mypid" $test {
74 -re ".* = ($decimal).*$gdb_prompt $" {
75 set testpid $expect_out(1,string)
80 gdb_test_no_output "set var wait_for_gdb = 1"
81 gdb_test "detach" "Detaching from .*"
83 clean_restart $testfile
86 gdb_test_multiple "attach $testpid" "$test" {
87 -re "Attaching to program.*.*main.*at .*$srcfile:.*$gdb_prompt $" {
92 gdb_test_no_output "set var wait_for_gdb = 0"
95 # Continue to LOCATION in the program. If REATTACH, detach and
96 # re-attach to the program from scratch.
97 proc continue_to_test_location {location reattach} {
98 gdb_breakpoint [gdb_get_line_number $location]
99 gdb_continue_to_breakpoint $location
101 with_test_prefix "$location" {
107 proc one_jit_test {count match_str reattach} {
108 with_test_prefix "one_jit_test-$count" {
109 global verbose testfile solib_binfile_target solib_binfile_test_msg
111 clean_restart $testfile
113 # This is just to help debugging when things fail
115 gdb_test "set debug jit 1"
118 if { ![runto_main] } {
119 fail "can't run to main"
123 gdb_breakpoint [gdb_get_line_number "break here 0"]
124 gdb_continue_to_breakpoint "break here 0"
126 # Poke desired values directly into inferior instead of using "set args"
127 # because "set args" does not work under gdbserver.
128 gdb_test_no_output "set var argc = 2"
129 gdb_test_no_output "set var libname = \"$solib_binfile_target\"" "set var libname = \"$solib_binfile_test_msg\""
130 gdb_test_no_output "set var count = $count"
132 continue_to_test_location "break here 1" $reattach
134 gdb_test "info function ^jit_function" "$match_str"
136 # This is just to help debugging when things fail
138 gdb_test "maintenance print objfiles"
139 gdb_test "maintenance info break"
142 continue_to_test_location "break here 2" $reattach
144 # All jit librares must have been unregistered
145 gdb_test "info function jit_function" \
146 "All functions matching regular expression \"jit_function\":"
150 if {[compile_jit_test jit.exp "" {}] < 0} {
153 one_jit_test 1 "${hex} jit_function_0000" 0
154 one_jit_test 2 "${hex} jit_function_0000\[\r\n\]+${hex} jit_function_0001" 0
156 # Test attaching to an inferior with some JIT libraries already
157 # registered. We reuse the normal test, and detach/reattach at
158 # specific interesting points.
159 if {[can_spawn_for_attach]} {
160 if {[compile_jit_test "jit.exp attach tests" \
161 "-attach" {additional_flags=-DATTACH=1}] < 0} {
165 with_test_prefix attach {
166 one_jit_test 2 "${hex} jit_function_0000\[\r\n\]+${hex} jit_function_0001" 1
170 with_test_prefix PIE {
171 if {[compile_jit_test "jit.exp PIE tests" \
172 "-pie" {additional_flags=-fPIE ldflags=-pie}] < 0} {
176 one_jit_test 1 "${hex} jit_function_0000" 0