Fix skip.exp test failure observed with gcc-9.2.0
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / jit.exp
CommitLineData
42a4f53d 1# Copyright 2011-2019 Free Software Foundation, Inc.
d3f0f853
PP
2
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.
7#
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.
12#
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/>.
15
d3f0f853 16if {[skip_shlib_tests]} {
84c93cd5 17 untested "skipping shared library tests"
d3f0f853
PP
18 return -1
19}
20
4c93b1db 21if {[get_compiler_info]} {
84c93cd5 22 untested "could not get compiler info"
d3f0f853
PP
23 return 1
24}
25
40dea8cb
PA
26# Compile the testcase program and library. BINSUFFIX is the suffix
27# to append to the program and library filenames, to make them unique
28# between invocations. OPTIONS is passed to gdb_compile when
29# compiling the program.
d3f0f853 30
40dea8cb 31proc compile_jit_test {testname binsuffix options} {
f25c0135
TT
32 global testfile srcfile binfile srcdir subdir
33 global solib_testfile solib_srcfile solib_binfile solib_binfile_test_msg
34 global solib_binfile_target
35
36 set testfile jit-main
37 set srcfile ${testfile}.c
40dea8cb 38 set binfile [standard_output_file $testfile$binsuffix]
f25c0135
TT
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
40 executable [concat debug $options]] != "" } {
41 untested $testname
42 return -1
43 }
d3f0f853 44
f25c0135
TT
45 set solib_testfile "jit-solib"
46 set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c"
40dea8cb
PA
47 set solib_binfile [standard_output_file ${solib_testfile}$binsuffix.so]
48 set solib_binfile_test_msg "SHLIBDIR/${solib_testfile}$binsuffix.so"
f25c0135
TT
49
50 # Note: compiling without debug info: the library goes through
51 # symbol renaming by munging on its symbol table, and that
52 # wouldn't work for .debug sections. Also, output for "info
53 # function" changes when debug info is present.
54 if { [gdb_compile_shlib ${solib_srcfile} ${solib_binfile} {-fPIC}] != "" } {
55 untested $testname
56 return -1
57 }
d3f0f853 58
7817ea46 59 set solib_binfile_target [gdb_remote_download target ${solib_binfile}]
d3f0f853 60
f25c0135
TT
61 return 0
62}
724f4f80 63
64cdf930
PA
64# Detach, restart GDB, and re-attach to the program.
65
66proc clean_reattach {} {
67 global decimal gdb_prompt srcfile testfile
68
69 # Get PID of test program.
70 set testpid -1
71 set test "get inferior process ID"
72 gdb_test_multiple "p mypid" $test {
73 -re ".* = ($decimal).*$gdb_prompt $" {
74 set testpid $expect_out(1,string)
75 pass $test
76 }
77 }
78
79 gdb_test_no_output "set var wait_for_gdb = 1"
80 gdb_test "detach" "Detaching from .*"
81
82 clean_restart $testfile
83
84 set test "attach"
85 gdb_test_multiple "attach $testpid" "$test" {
86 -re "Attaching to program.*.*main.*at .*$srcfile:.*$gdb_prompt $" {
87 pass "$test"
88 }
89 }
90
91 gdb_test_no_output "set var wait_for_gdb = 0"
92}
93
94# Continue to LOCATION in the program. If REATTACH, detach and
95# re-attach to the program from scratch.
96proc continue_to_test_location {location reattach} {
97 gdb_breakpoint [gdb_get_line_number $location]
98 gdb_continue_to_breakpoint $location
99 if {$reattach} {
100 with_test_prefix "$location" {
101 clean_reattach
102 }
103 }
104}
105
106proc one_jit_test {count match_str reattach} {
0a251e08
YQ
107 with_test_prefix "one_jit_test-$count" {
108 global verbose testfile solib_binfile_target solib_binfile_test_msg
109
110 clean_restart $testfile
111
112 # This is just to help debugging when things fail
113 if {$verbose > 0} {
114 gdb_test "set debug jit 1"
115 }
116
117 if { ![runto_main] } {
bc6c7af4 118 fail "can't run to main"
0a251e08
YQ
119 return
120 }
121
122 gdb_breakpoint [gdb_get_line_number "break here 0"]
123 gdb_continue_to_breakpoint "break here 0"
124
125 # Poke desired values directly into inferior instead of using "set args"
126 # because "set args" does not work under gdbserver.
127 gdb_test_no_output "set var argc = 2"
128 gdb_test_no_output "set var libname = \"$solib_binfile_target\"" "set var libname = \"$solib_binfile_test_msg\""
129 gdb_test_no_output "set var count = $count"
130
64cdf930 131 continue_to_test_location "break here 1" $reattach
0a251e08 132
d9a47287 133 gdb_test "info function ^jit_function" "$match_str"
0a251e08
YQ
134
135 # This is just to help debugging when things fail
136 if {$verbose > 0} {
137 gdb_test "maintenance print objfiles"
138 gdb_test "maintenance info break"
139 }
140
64cdf930
PA
141 continue_to_test_location "break here 2" $reattach
142
0a251e08
YQ
143 # All jit librares must have been unregistered
144 gdb_test "info function jit_function" \
145 "All functions matching regular expression \"jit_function\":"
d3f0f853 146 }
0a251e08 147}
d3f0f853 148
40dea8cb 149if {[compile_jit_test jit.exp "" {}] < 0} {
f25c0135
TT
150 return
151}
64cdf930
PA
152one_jit_test 1 "${hex} jit_function_0000" 0
153one_jit_test 2 "${hex} jit_function_0000\[\r\n\]+${hex} jit_function_0001" 0
154
155# Test attaching to an inferior with some JIT libraries already
156# registered. We reuse the normal test, and detach/reattach at
157# specific interesting points.
158if {[can_spawn_for_attach]} {
159 if {[compile_jit_test "jit.exp attach tests" \
160 "-attach" {additional_flags=-DATTACH=1}] < 0} {
161 return
162 }
163
164 with_test_prefix attach {
165 one_jit_test 2 "${hex} jit_function_0000\[\r\n\]+${hex} jit_function_0001" 1
166 }
167}
f25c0135
TT
168
169with_test_prefix PIE {
170 if {[compile_jit_test "jit.exp PIE tests" \
40dea8cb 171 "-pie" {additional_flags=-fPIE ldflags=-pie}] < 0} {
f25c0135
TT
172 return
173 }
174
64cdf930 175 one_jit_test 1 "${hex} jit_function_0000" 0
f25c0135 176}
This page took 1.137133 seconds and 4 git commands to generate.