]>
Commit | Line | Data |
---|---|---|
3666a048 | 1 | # Copyright 2011-2021 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 | 16 | if {[skip_shlib_tests]} { |
84c93cd5 | 17 | untested "skipping shared library tests" |
d3f0f853 PP |
18 | return -1 |
19 | } | |
20 | ||
4c93b1db | 21 | if {[get_compiler_info]} { |
84c93cd5 | 22 | untested "could not get compiler info" |
d3f0f853 PP |
23 | return 1 |
24 | } | |
25 | ||
f8012071 MS |
26 | load_lib jit-elf-helpers.exp |
27 | ||
5144dfba TV |
28 | # Increase this to see more detail. |
29 | set test_verbose 0 | |
30 | ||
9a946945 | 31 | # The main code that loads and registers JIT objects. |
f8012071 | 32 | set main_basename "jit-elf-main" |
9a946945 MSG |
33 | set main_srcfile ${srcdir}/${subdir}/${main_basename}.c |
34 | set main_binfile [standard_output_file ${main_basename}] | |
d3f0f853 | 35 | |
9a946945 MSG |
36 | # The shared library that gets loaded as JIT objects. |
37 | set jit_solib_basename jit-elf-solib | |
38 | set jit_solib_srcfile ${srcdir}/${subdir}/${jit_solib_basename}.c | |
d3f0f853 | 39 | |
64cdf930 | 40 | # Detach, restart GDB, and re-attach to the program. |
64cdf930 | 41 | proc clean_reattach {} { |
9a946945 MSG |
42 | global decimal gdb_prompt |
43 | global main_binfile main_srcfile | |
64cdf930 PA |
44 | |
45 | # Get PID of test program. | |
46 | set testpid -1 | |
47 | set test "get inferior process ID" | |
48 | gdb_test_multiple "p mypid" $test { | |
49 | -re ".* = ($decimal).*$gdb_prompt $" { | |
50 | set testpid $expect_out(1,string) | |
51 | pass $test | |
52 | } | |
53 | } | |
54 | ||
55 | gdb_test_no_output "set var wait_for_gdb = 1" | |
56 | gdb_test "detach" "Detaching from .*" | |
57 | ||
9a946945 | 58 | clean_restart ${main_binfile} |
64cdf930 PA |
59 | |
60 | set test "attach" | |
61 | gdb_test_multiple "attach $testpid" "$test" { | |
9a946945 | 62 | -re "Attaching to program.*.*main.*at .*$main_srcfile:.*$gdb_prompt $" { |
64cdf930 PA |
63 | pass "$test" |
64 | } | |
65 | } | |
66 | ||
67 | gdb_test_no_output "set var wait_for_gdb = 0" | |
68 | } | |
69 | ||
70 | # Continue to LOCATION in the program. If REATTACH, detach and | |
71 | # re-attach to the program from scratch. | |
72 | proc continue_to_test_location {location reattach} { | |
9a946945 MSG |
73 | global main_srcfile |
74 | ||
75 | gdb_breakpoint [gdb_get_line_number $location $main_srcfile] | |
64cdf930 PA |
76 | gdb_continue_to_breakpoint $location |
77 | if {$reattach} { | |
78 | with_test_prefix "$location" { | |
79 | clean_reattach | |
80 | } | |
81 | } | |
82 | } | |
83 | ||
9a946945 MSG |
84 | proc one_jit_test {jit_solibs_target match_str reattach} { |
85 | set count [llength $jit_solibs_target] | |
86 | ||
0a251e08 | 87 | with_test_prefix "one_jit_test-$count" { |
5144dfba | 88 | global test_verbose |
9a946945 | 89 | global main_binfile main_srcfile |
0a251e08 | 90 | |
9a946945 | 91 | clean_restart ${main_binfile} |
0a251e08 YQ |
92 | |
93 | # This is just to help debugging when things fail | |
5144dfba | 94 | if {$test_verbose > 0} { |
0a251e08 YQ |
95 | gdb_test "set debug jit 1" |
96 | } | |
97 | ||
98 | if { ![runto_main] } { | |
bc6c7af4 | 99 | fail "can't run to main" |
0a251e08 YQ |
100 | return |
101 | } | |
102 | ||
0a251e08 YQ |
103 | # Poke desired values directly into inferior instead of using "set args" |
104 | # because "set args" does not work under gdbserver. | |
9a946945 MSG |
105 | incr count |
106 | gdb_test_no_output "set var argc=$count" "forging argc" | |
107 | gdb_test_no_output "set var argv=fake_argv" "forging argv" | |
108 | for {set i 1} {$i < $count} {incr i} { | |
109 | set jit_solib_target [lindex $jit_solibs_target [expr $i-1]] | |
110 | gdb_test_no_output "set var argv\[$i\]=\"${jit_solib_target}\"" \ | |
111 | "forging argv\[$i\]" | |
112 | } | |
113 | ||
114 | gdb_breakpoint [gdb_get_line_number "break here 0" $main_srcfile] | |
115 | gdb_continue_to_breakpoint "break here 0" | |
116 | ||
0a251e08 | 117 | |
64cdf930 | 118 | continue_to_test_location "break here 1" $reattach |
0a251e08 | 119 | |
d9a47287 | 120 | gdb_test "info function ^jit_function" "$match_str" |
0a251e08 YQ |
121 | |
122 | # This is just to help debugging when things fail | |
5144dfba | 123 | if {$test_verbose > 0} { |
0a251e08 YQ |
124 | gdb_test "maintenance print objfiles" |
125 | gdb_test "maintenance info break" | |
126 | } | |
127 | ||
64cdf930 PA |
128 | continue_to_test_location "break here 2" $reattach |
129 | ||
0a251e08 YQ |
130 | # All jit librares must have been unregistered |
131 | gdb_test "info function jit_function" \ | |
132 | "All functions matching regular expression \"jit_function\":" | |
d3f0f853 | 133 | } |
0a251e08 | 134 | } |
d3f0f853 | 135 | |
9a946945 | 136 | # Compile two shared libraries to use as JIT objects. |
f8012071 MS |
137 | set jit_solibs_target [compile_and_download_n_jit_so \ |
138 | $jit_solib_basename $jit_solib_srcfile 2] | |
9a946945 | 139 | if { $jit_solibs_target == -1 } { |
f25c0135 TT |
140 | return |
141 | } | |
9a946945 MSG |
142 | |
143 | # Compile the main code (which loads the JIT objects). | |
f8012071 | 144 | if { [compile_jit_main ${main_srcfile} ${main_binfile} {}] == 0 } { |
9a946945 MSG |
145 | one_jit_test [lindex $jit_solibs_target 0] "${hex} jit_function_0001" 0 |
146 | one_jit_test $jit_solibs_target "${hex} jit_function_0001\[\r\n\]+${hex} jit_function_0002" 0 | |
147 | } | |
64cdf930 PA |
148 | |
149 | # Test attaching to an inferior with some JIT libraries already | |
150 | # registered. We reuse the normal test, and detach/reattach at | |
151 | # specific interesting points. | |
152 | if {[can_spawn_for_attach]} { | |
c7c66341 | 153 | if { [compile_jit_main ${main_srcfile} "${main_binfile}-attach" \ |
f8012071 | 154 | {additional_flags=-DATTACH=1}] == 0 } { |
9a946945 MSG |
155 | with_test_prefix attach { |
156 | one_jit_test $jit_solibs_target "${hex} jit_function_0001\[\r\n\]+${hex} jit_function_0002" 1 | |
157 | } | |
64cdf930 PA |
158 | } |
159 | } | |
f25c0135 | 160 | |
c7c66341 TV |
161 | if { [compile_jit_main ${main_srcfile} "${main_binfile}-pie" \ |
162 | {additional_flags=-fPIE ldflags=-pie}] == 0 } { | |
9a946945 MSG |
163 | with_test_prefix PIE { |
164 | one_jit_test [lindex $jit_solibs_target 0] "${hex} jit_function_0001" 0 | |
f25c0135 | 165 | } |
f25c0135 | 166 | } |