1 # Copyright 2009-2023 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 # This file is part of the gdb testsuite.
18 # Test amd64 displaced stepping.
21 if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
22 verbose "Skipping x86_64 displaced stepping tests."
26 set newline "\[\r\n\]*"
28 set opts {debug nopie}
31 if { [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] } {
35 gdb_test "set displaced-stepping on" ""
36 gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
42 ##########################################
46 gdb_test "break test_call" \
47 "Breakpoint.*at.* file .*$srcfile, line.*"
48 gdb_test "break test_call_end" \
49 "Breakpoint.*at.* file .*$srcfile, line.*"
51 gdb_test "break test_ret" \
52 "Breakpoint.*at.* file .*$srcfile, line.*"
53 gdb_test "break test_ret_end" \
54 "Breakpoint.*at.* file .*$srcfile, line.*"
57 "Continuing.*Breakpoint.*, test_call ().*" \
58 "continue to test_call"
60 "Continuing.*Breakpoint.*, test_call_end ().*" \
61 "continue to test_call_end"
64 "Continuing.*Breakpoint.*, test_ret ().*" \
65 "continue to test_ret"
67 "Continuing.*Breakpoint.*, test_ret_end ().*" \
68 "continue to test_ret_end"
70 ##########################################
72 # Test abs-jmp/rep-ret.
74 gdb_test "break test_abs_jmp" \
75 "Breakpoint.*at.* file .*$srcfile, line.*"
76 gdb_test "break test_abs_jmp_end" \
77 "Breakpoint.*at.* file .*$srcfile, line.*"
79 gdb_test "break test_rep_ret" \
80 "Breakpoint.*at.* file .*$srcfile, line.*"
81 gdb_test "break test_rep_ret_end" \
82 "Breakpoint.*at.* file .*$srcfile, line.*"
85 "Continuing.*Breakpoint.*, test_abs_jmp ().*" \
86 "continue to test_abs_jmp"
88 "Continuing.*Breakpoint.*, test_abs_jmp_end ().*" \
89 "continue to test_abs_jmp_end"
92 "Continuing.*Breakpoint.*, test_rep_ret ().*" \
93 "continue to test_rep_ret"
95 "Continuing.*Breakpoint.*, test_rep_ret_end ().*" \
96 "continue to test_rep_ret_end"
98 ##########################################
102 gdb_test "break test_syscall" \
103 "Breakpoint.*at.* file .*$srcfile, line.*"
104 gdb_test "break test_syscall_end" \
105 "Breakpoint.*at.* file .*$srcfile, line.*"
107 gdb_test "continue" \
108 "Continuing.*Breakpoint.*, test_syscall ().*" \
109 "continue to test_syscall"
110 gdb_test "continue" \
111 "Continuing.*Breakpoint.*, test_syscall_end ().*" \
112 "continue to test_syscall_end"
114 ##########################################
116 # int3 (with prefixes)
117 # These don't occur in normal code, but gdb should still DTRT.
119 gdb_test "break test_int3" \
120 "Breakpoint.*at.* file .*$srcfile, line.*"
121 gdb_test "break test_int3_end" \
122 "Breakpoint.*at.* file .*$srcfile, line.*"
124 gdb_test "continue" \
125 "Continuing.*Breakpoint.*, test_int3 ().*" \
126 "continue to test_int3"
128 gdb_test "continue" \
129 "Continuing.*Breakpoint.*, test_int3_end ().*" \
130 "continue to test_int3_end"
132 ##########################################
135 # GDB picks a spare register to hold the rip-relative address.
136 # Exercise all the possibilities (rax-rdi, sans rsp).
138 # The order must much the order in srcfile.
139 set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" }
141 # Assign val to all specified regs.
143 proc set_regs { regs val } {
146 foreach reg ${regs} {
147 # Use send_gdb/gdb_expect so that these aren't logged as pass/fail.
148 send_gdb "set \$${reg} = ${val}\n"
150 -re "$gdb_prompt $" {
151 verbose "Setting ${reg} to ${val}." 2
154 warning "Couldn't set ${reg} to ${val}."
160 # Verify all REGS equal VAL, except REG which equals REG_VAL.
162 proc verify_regs { test_name regs val except_reg except_reg_val } {
165 foreach reg ${regs} {
167 if { "${reg}" == "${except_reg}" } {
168 set expected ${except_reg_val}
170 # The cast to (int) is because RBP is printed as a pointer.
171 gdb_test "p (int) \$${reg}" " = ${expected}${newline}" "${test_name} ${reg} expected value"
175 proc rip_test { reg } {
176 global srcfile rip_regs
178 set test_start_label "test_rip_${reg}"
179 set test_end_label "test_rip_${reg}_end"
181 gdb_test "break ${test_start_label}" \
182 "Breakpoint.*at.* file .*$srcfile, line.*"
183 gdb_test "break ${test_end_label}" \
184 "Breakpoint.*at.* file .*$srcfile, line.*"
186 gdb_test "continue" \
187 "Continuing.*Breakpoint.*, ${test_start_label} ().*" \
188 "continue to ${test_start_label}"
190 set_regs ${rip_regs} 0
192 gdb_test "continue" \
193 "Continuing.*Breakpoint.*, ${test_end_label} ().*" \
194 "continue to ${test_end_label}"
196 verify_regs "test rip w/${reg}" ${rip_regs} 0 ${reg} 42
199 foreach reg ${rip_regs} {
203 ##########################################
205 # Done, run program to exit.
207 gdb_continue_to_end "amd64-disp-step"