1 # Copyright 2012-2019 Free Software Foundation, Inc.
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.
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.
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/>.
16 standard_testfile jithost.c
18 if { (![istarget x86_64-*-*] && ![istarget i?86-*-*]) || ![is_lp64_target] } {
22 if {[skip_shlib_tests]} {
30 if {[get_compiler_info]} {
31 untested "could not get compiler info"
35 set jit_host_src $srcfile
36 set jit_host_bin $binfile
38 # We inject the complete path to jit-reader.h into the source file
39 # lest we end up (incorrectly) building against a system-installed
41 set jit_reader_header [standard_output_file "../../../../../gdb/jit-reader.h"]
42 set jit_reader_flag "-DJIT_READER_H=\"$jit_reader_header\""
44 if { [gdb_compile "${srcdir}/${subdir}/${jit_host_src}" "${jit_host_bin}" \
45 executable [list debug additional_flags=$jit_reader_flag]] != "" } {
46 untested "failed to compile"
50 set jit_reader jitreader
51 set jit_reader_src ${jit_reader}.c
52 set jit_reader_bin [standard_output_file ${jit_reader}.so]
54 if { [gdb_compile_shlib "${srcdir}/${subdir}/${jit_reader_src}" "${jit_reader_bin}" \
55 [list debug additional_flags=$jit_reader_flag]] != "" } {
56 untested "failed to compile"
60 # Test "info registers" in the current frame, expecting RSP's value to
63 proc info_registers_current_frame {sp} {
68 gdb_test "info registers" \
70 "rax $hex +$decimal" \
71 "rbx $hex +$decimal" \
72 "rcx $hex +$decimal" \
73 "rdx $hex +$decimal" \
74 "rsi $hex +$decimal" \
75 "rdi $hex +$decimal" \
80 "r10 $hex +$decimal" \
81 "r11 $hex +$decimal" \
82 "r12 $hex +$decimal" \
83 "r13 $hex +$decimal" \
84 "r14 $hex +$decimal" \
85 "r15 $hex +$decimal" \
86 "rip $hex +$hex$any" \
87 "eflags $hex +\\\[$any\\\]" \
97 proc jit_reader_test {} {
105 clean_restart $jit_host_bin
106 gdb_load_shlib $jit_reader_bin
109 gdb_test_no_output "set debug jit 1"
112 gdb_test_no_output "jit-reader-load ${jit_reader_bin}" "jit-reader-load"
114 gdb_test "" "Program received signal SIGTRAP, .*" "expect SIGTRAP"
116 # Test the JIT reader unwinder.
117 with_test_prefix "with jit-reader" {
119 with_test_prefix "before mangling" {
122 "#0 ${any} in jit_function_00 ${any}" \
123 "#1 ${any} in main ${any}" \
127 set sp_before_mangling \
128 [get_hexadecimal_valueof "\$sp" 0 "get sp"]
130 gdb_test "up" "#1 $any in main $any\r\n$any function $any" \
134 [get_hexadecimal_valueof "\$sp" 0 "get caller sp"]
137 # Step over the instruction that mangles the stack pointer.
138 # While that confuses GDB's built-in unwinder, the JIT
139 # reader's unwinder understands the mangling and should thus
140 # be able to unwind at that location.
141 with_test_prefix "after mangling" {
142 gdb_test "si" "in jit_function_00 .*" "step over stack mangling"
144 set sp_after_mangling \
145 [get_hexadecimal_valueof "\$sp" 0 "get sp"]
147 gdb_assert {$sp_before_mangling != $sp_after_mangling} \
150 # Check that the jit unwinder manages to backtrace through
151 # the mangled stack pointer.
154 "#0 ${any} in jit_function_00 ${any}" \
155 "#1 ${any} in main ${any}" \
159 with_test_prefix "current frame" {
160 info_registers_current_frame $sp_after_mangling
162 gdb_test "info frame" \
163 "Stack level 0, frame at $sp_before_mangling.*in jit_function_00.*"
166 with_test_prefix "caller frame" {
167 gdb_test "up" "#1 $any in main $any\r\n$any function $any" \
170 # Since the JIT unwinder only provides RIP/RSP/RBP,
171 # all other registers should show as "<not saved>".
172 gdb_test "info registers" \
181 "rsp $caller_sp +$caller_sp" \
190 "rip $hex +$hex $any" \
191 "eflags <not saved>" \
200 # Make sure that "info frame" doesn't crash.
201 gdb_test "info frame" "Stack level 1, .*in main.*"
203 # ... and that neither does printing a pseudo
205 gdb_test "print /x \$ebp" " = $hex" "print pseudo register"
207 # There's no way for the JIT reader API to support
208 # modifyiable values.
209 gdb_test "print \$rbp = -1" \
210 "Attempt to assign to an unmodifiable value\." \
211 "cannot assign to register"
216 # Now unload the jit reader, and ensure that backtracing really
217 # doesn't work without it.
218 with_test_prefix "without jit-reader" {
219 gdb_test_no_output "jit-reader-unload ${jit_reader_bin}" \
222 # Check that we're no longer using the JIT unwinder, and that
223 # the built-in unwinder cannot backtrace through the mangled
227 "Backtrace stopped: Cannot access memory at address $sp_after_mangling" \
231 gdb_test "info frame" "Cannot access memory at address.*" \
232 "info frame shows error"
233 info_registers_current_frame $sp_after_mangling
234 gdb_test "up" "Initial frame selected; you cannot go up\\." \
238 with_test_prefix "with jit-reader again" {
239 gdb_test_no_output "jit-reader-load ${jit_reader_bin}" "jit-reader-load"
241 # Check that the jit unwinder manages to backtrace through
242 # the mangled stack pointer.
245 "#0 ${any} in jit_function_00 ${any}" \
246 "#1 ${any} in main ${any}" \