IPA: Move getauxval out of #ifndef IN_PROCESS_AGENT
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / jit.exp
1 # Copyright 2011-2016 Free Software Foundation, Inc.
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
16 if {[skip_shlib_tests]} {
17 untested jit.exp
18 return -1
19 }
20
21 if {[get_compiler_info]} {
22 warning "Could not get compiler info"
23 untested jit.exp
24 return 1
25 }
26
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.
31
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
36
37 set testfile jit-main
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]] != "" } {
42 untested $testname
43 return -1
44 }
45
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"
50
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}] != "" } {
56 untested $testname
57 return -1
58 }
59
60 if {[is_remote target]} {
61 set solib_binfile_target [gdb_download ${solib_binfile}]
62 } else {
63 set solib_binfile_target $solib_binfile
64 }
65
66 return 0
67 }
68
69 # Detach, restart GDB, and re-attach to the program.
70
71 proc clean_reattach {} {
72 global decimal gdb_prompt srcfile testfile
73
74 # Get PID of test program.
75 set testpid -1
76 set test "get inferior process ID"
77 gdb_test_multiple "p mypid" $test {
78 -re ".* = ($decimal).*$gdb_prompt $" {
79 set testpid $expect_out(1,string)
80 pass $test
81 }
82 }
83
84 gdb_test_no_output "set var wait_for_gdb = 1"
85 gdb_test "detach" "Detaching from .*"
86
87 clean_restart $testfile
88
89 set test "attach"
90 gdb_test_multiple "attach $testpid" "$test" {
91 -re "Attaching to program.*.*main.*at .*$srcfile:.*$gdb_prompt $" {
92 pass "$test"
93 }
94 }
95
96 gdb_test_no_output "set var wait_for_gdb = 0"
97 }
98
99 # Continue to LOCATION in the program. If REATTACH, detach and
100 # re-attach to the program from scratch.
101 proc continue_to_test_location {location reattach} {
102 gdb_breakpoint [gdb_get_line_number $location]
103 gdb_continue_to_breakpoint $location
104 if {$reattach} {
105 with_test_prefix "$location" {
106 clean_reattach
107 }
108 }
109 }
110
111 proc one_jit_test {count match_str reattach} {
112 with_test_prefix "one_jit_test-$count" {
113 global verbose testfile solib_binfile_target solib_binfile_test_msg
114
115 clean_restart $testfile
116
117 # This is just to help debugging when things fail
118 if {$verbose > 0} {
119 gdb_test "set debug jit 1"
120 }
121
122 if { ![runto_main] } {
123 fail "Can't run to main"
124 return
125 }
126
127 gdb_breakpoint [gdb_get_line_number "break here 0"]
128 gdb_continue_to_breakpoint "break here 0"
129
130 # Poke desired values directly into inferior instead of using "set args"
131 # because "set args" does not work under gdbserver.
132 gdb_test_no_output "set var argc = 2"
133 gdb_test_no_output "set var libname = \"$solib_binfile_target\"" "set var libname = \"$solib_binfile_test_msg\""
134 gdb_test_no_output "set var count = $count"
135
136 continue_to_test_location "break here 1" $reattach
137
138 gdb_test "info function ^jit_function" "$match_str"
139
140 # This is just to help debugging when things fail
141 if {$verbose > 0} {
142 gdb_test "maintenance print objfiles"
143 gdb_test "maintenance info break"
144 }
145
146 continue_to_test_location "break here 2" $reattach
147
148 # All jit librares must have been unregistered
149 gdb_test "info function jit_function" \
150 "All functions matching regular expression \"jit_function\":"
151 }
152 }
153
154 if {[compile_jit_test jit.exp "" {}] < 0} {
155 return
156 }
157 one_jit_test 1 "${hex} jit_function_0000" 0
158 one_jit_test 2 "${hex} jit_function_0000\[\r\n\]+${hex} jit_function_0001" 0
159
160 # Test attaching to an inferior with some JIT libraries already
161 # registered. We reuse the normal test, and detach/reattach at
162 # specific interesting points.
163 if {[can_spawn_for_attach]} {
164 if {[compile_jit_test "jit.exp attach tests" \
165 "-attach" {additional_flags=-DATTACH=1}] < 0} {
166 return
167 }
168
169 with_test_prefix attach {
170 one_jit_test 2 "${hex} jit_function_0000\[\r\n\]+${hex} jit_function_0001" 1
171 }
172 }
173
174 with_test_prefix PIE {
175 if {[compile_jit_test "jit.exp PIE tests" \
176 "-pie" {additional_flags=-fPIE ldflags=-pie}] < 0} {
177 return
178 }
179
180 one_jit_test 1 "${hex} jit_function_0000" 0
181 }
This page took 0.035614 seconds and 4 git commands to generate.