Commit | Line | Data |
---|---|---|
3666a048 | 1 | # Copyright 2012-2021 Free Software Foundation, Inc. |
03bef283 TT |
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 | ||
4a556533 PA |
16 | # Test re-running an inferior with a JIT descriptor, where the JIT |
17 | # descriptor changes address between runs. | |
18 | # http://sourceware.org/bugzilla/show_bug.cgi?id=13431 | |
19 | ||
20 | # Test both the case of the JIT reader being included in the main | |
21 | # program directly, and the case of the JIT reader being split out to | |
22 | # a shared library. | |
23 | ||
24 | # For completeness, also test when the JIT descriptor does not change | |
25 | # address between runs. | |
26 | ||
03bef283 | 27 | if {[skip_shlib_tests]} { |
5b362f04 | 28 | untested "skipping shared library tests" |
03bef283 TT |
29 | return -1 |
30 | } | |
31 | ||
f8b41b00 TT |
32 | standard_testfile |
33 | ||
4a556533 PA |
34 | set libname $testfile-jit |
35 | set srcfile_lib $srcdir/$subdir/$libname.c | |
36 | set binfile_lib [standard_output_file $libname.so] | |
c8474dc3 | 37 | set binfile_lib2 [standard_output_file ${libname}2.so] |
4a556533 PA |
38 | |
39 | # Build a standalone JIT binary. | |
40 | ||
41 | proc build_standalone_jit {{options ""}} { | |
42 | global testfile srcfile binfile | |
43 | ||
44 | lappend options "debug" | |
45 | ||
46 | if {[build_executable $testfile.exp $testfile $srcfile $options] == -1} { | |
47 | return -1 | |
48 | } | |
49 | ||
50 | return 0 | |
51 | } | |
52 | ||
53 | # Build the shared library JIT. | |
54 | ||
55 | proc build_shared_jit {{options ""}} { | |
56 | global testfile | |
c8474dc3 | 57 | global srcfile_lib binfile_lib binfile_lib2 |
4a556533 | 58 | |
2f413264 | 59 | lappend options "debug" |
4a556533 PA |
60 | if { [gdb_compile_shlib $srcfile_lib $binfile_lib $options] != "" } { |
61 | return -1 | |
62 | } | |
c8474dc3 TBA |
63 | if { [gdb_compile_shlib $srcfile_lib $binfile_lib2 $options] != "" } { |
64 | return -1 | |
65 | } | |
4a556533 PA |
66 | |
67 | return 0 | |
68 | } | |
69 | ||
70 | if {[build_standalone_jit] == -1} { | |
84c93cd5 | 71 | untested "failed to compile standalone testcase" |
4a556533 PA |
72 | return |
73 | } | |
74 | ||
75 | if {[build_shared_jit] == -1} { | |
84c93cd5 | 76 | untested "failed to compile shared library testcase" |
4a556533 PA |
77 | return |
78 | } | |
79 | ||
ff08abb8 | 80 | # Build the program that loads the JIT library. |
4a556533 PA |
81 | set srcfile_dl $testfile-dl.c |
82 | set binfile_dl $binfile-dl | |
83 | set options [list debug shlib=${binfile_lib}] | |
84 | if {[gdb_compile ${srcdir}/${subdir}/${srcfile_dl} $binfile_dl executable \ | |
ff08abb8 | 85 | $options] == -1 } { |
5b362f04 | 86 | untested "failed to compile" |
03bef283 TT |
87 | return -1 |
88 | } | |
89 | ||
c8474dc3 TBA |
90 | # Build the program that loads *two* JIT libraries. |
91 | set binfile_dl2 $binfile-dl2 | |
92 | set options [list debug shlib=${binfile_lib} shlib=${binfile_lib2}] | |
93 | if {[gdb_compile ${srcdir}/${subdir}/${srcfile_dl} $binfile_dl2 executable \ | |
94 | $options] == -1 } { | |
95 | untested "failed to compile two-jitter binary" | |
96 | return -1 | |
97 | } | |
98 | ||
4a556533 PA |
99 | # STANDALONE is true when the JIT reader is included directly in the |
100 | # main program. False when the JIT reader is in a separate shared | |
101 | # library. If CHANGE_ADDR is true, force changing the JIT descriptor | |
102 | # changes address between runs. | |
103 | proc jit_test_reread {standalone change_addr} { | |
104 | global testfile binfile subdir srcfile srcdir binfile_lib binfile_dl | |
5a122fbc | 105 | global hex |
03bef283 | 106 | |
5a122fbc | 107 | with_test_prefix "initial run" { |
4a556533 PA |
108 | if {$standalone} { |
109 | clean_restart $binfile | |
110 | } else { | |
111 | clean_restart $binfile_dl | |
112 | } | |
03bef283 | 113 | |
5a122fbc | 114 | runto_main |
03bef283 | 115 | |
5a122fbc PA |
116 | set addr_before [get_hexadecimal_valueof "&__jit_debug_descriptor" 0 \ |
117 | "get address of __jit_debug_descriptor"] | |
4a556533 PA |
118 | |
119 | gdb_test "maint info breakpoints" \ | |
120 | "jit events keep y $hex <__jit_debug_register_code>.*" \ | |
121 | "maint info breakpoints shows jit breakpoint" | |
5a122fbc | 122 | } |
03bef283 | 123 | |
5a122fbc PA |
124 | with_test_prefix "second run" { |
125 | # Ensure that the new executable is at least one second newer | |
126 | # than the old. If the recompilation happens in the same | |
127 | # second, gdb might not reload the executable automatically. | |
128 | sleep 1 | |
03bef283 | 129 | |
4a556533 PA |
130 | if ${change_addr} { |
131 | set options "additional_flags=-DSPACER" | |
132 | if {$standalone} { | |
133 | gdb_rename_execfile $binfile ${binfile}x | |
134 | set res [build_standalone_jit $options] | |
135 | } else { | |
136 | gdb_rename_execfile $binfile_lib ${binfile_lib}x | |
137 | set res [build_shared_jit $options] | |
138 | } | |
139 | if { $res == -1 } { | |
140 | fail "recompile" | |
141 | return | |
142 | } else { | |
143 | pass "recompile" | |
144 | } | |
5a122fbc | 145 | } |
03bef283 TT |
146 | |
147 | runto_main | |
5a122fbc PA |
148 | |
149 | set addr_after [get_hexadecimal_valueof "&__jit_debug_descriptor" 0 \ | |
150 | "get address of __jit_debug_descriptor"] | |
4a556533 PA |
151 | |
152 | # This used to crash in the JIT-in-shared-library case: | |
153 | # https://sourceware.org/bugzilla/show_bug.cgi?id=11094 | |
154 | gdb_test "maint info breakpoints" \ | |
155 | "jit events keep y $hex <__jit_debug_register_code>.*" \ | |
156 | "maint info breakpoints shows jit breakpoint" | |
03bef283 | 157 | } |
5a122fbc | 158 | |
4a556533 PA |
159 | if ${change_addr} { |
160 | gdb_assert {$addr_before != $addr_after} "address changed" | |
161 | } else { | |
162 | gdb_assert {$addr_before == $addr_after} "address didn't change" | |
163 | } | |
03bef283 TT |
164 | } |
165 | ||
4a556533 PA |
166 | foreach standalone {1 0} { |
167 | with_test_prefix [expr ($standalone)?"standalone":"shared"] { | |
168 | with_test_prefix "change addr" { | |
169 | jit_test_reread $standalone 1 | |
170 | } | |
171 | with_test_prefix "same addr" { | |
172 | jit_test_reread $standalone 0 | |
173 | } | |
174 | } | |
175 | } | |
c8474dc3 TBA |
176 | |
177 | # Now start the program that loads two JITer libraries and expect to | |
178 | # see JIT breakpoints defined for both. | |
179 | ||
180 | with_test_prefix "two JITers" { | |
181 | clean_restart $binfile_dl2 | |
182 | ||
183 | if {![runto_main]} { | |
184 | untested "could not run to main" | |
185 | return -1 | |
186 | } | |
187 | ||
188 | set num_bps 0 | |
189 | set ws "\[ \t\]+" | |
190 | gdb_test_multiple "maint info breakpoints" "have two jit breakpoints" { | |
191 | -re "jit events${ws}keep y${ws}$hex <__jit_debug_register_code> inf 1\r\n" { | |
192 | incr num_bps | |
193 | exp_continue | |
194 | } | |
195 | -re "$gdb_prompt $" { | |
196 | if {$num_bps == 2} { | |
197 | pass $gdb_test_name | |
198 | } else { | |
199 | fail $gdb_test_name | |
200 | } | |
201 | } | |
202 | } | |
203 | } |