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