1 # Copyright 2009-2021 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.*"
38 if ![runto_main] then {
39 fail "can't run to main"
43 ##########################################
47 gdb_test "break test_call" \
48 "Breakpoint.*at.* file .*$srcfile, line.*"
49 gdb_test "break test_call_end" \
50 "Breakpoint.*at.* file .*$srcfile, line.*"
52 gdb_test "break test_ret" \
53 "Breakpoint.*at.* file .*$srcfile, line.*"
54 gdb_test "break test_ret_end" \
55 "Breakpoint.*at.* file .*$srcfile, line.*"
58 "Continuing.*Breakpoint.*, test_call ().*" \
59 "continue to test_call"
61 "Continuing.*Breakpoint.*, test_call_end ().*" \
62 "continue to test_call_end"
65 "Continuing.*Breakpoint.*, test_ret ().*" \
66 "continue to test_ret"
68 "Continuing.*Breakpoint.*, test_ret_end ().*" \
69 "continue to test_ret_end"
71 ##########################################
73 # Test abs-jmp/rep-ret.
75 gdb_test "break test_abs_jmp" \
76 "Breakpoint.*at.* file .*$srcfile, line.*"
77 gdb_test "break test_abs_jmp_end" \
78 "Breakpoint.*at.* file .*$srcfile, line.*"
80 gdb_test "break test_rep_ret" \
81 "Breakpoint.*at.* file .*$srcfile, line.*"
82 gdb_test "break test_rep_ret_end" \
83 "Breakpoint.*at.* file .*$srcfile, line.*"
86 "Continuing.*Breakpoint.*, test_abs_jmp ().*" \
87 "continue to test_abs_jmp"
89 "Continuing.*Breakpoint.*, test_abs_jmp_end ().*" \
90 "continue to test_abs_jmp_end"
93 "Continuing.*Breakpoint.*, test_rep_ret ().*" \
94 "continue to test_rep_ret"
96 "Continuing.*Breakpoint.*, test_rep_ret_end ().*" \
97 "continue to test_rep_ret_end"
99 ##########################################
103 gdb_test "break test_syscall" \
104 "Breakpoint.*at.* file .*$srcfile, line.*"
105 gdb_test "break test_syscall_end" \
106 "Breakpoint.*at.* file .*$srcfile, line.*"
108 gdb_test "continue" \
109 "Continuing.*Breakpoint.*, test_syscall ().*" \
110 "continue to test_syscall"
111 gdb_test "continue" \
112 "Continuing.*Breakpoint.*, test_syscall_end ().*" \
113 "continue to test_syscall_end"
115 ##########################################
117 # int3 (with prefixes)
118 # These don't occur in normal code, but gdb should still DTRT.
120 gdb_test "break test_int3" \
121 "Breakpoint.*at.* file .*$srcfile, line.*"
122 gdb_test "break test_int3_end" \
123 "Breakpoint.*at.* file .*$srcfile, line.*"
125 gdb_test "continue" \
126 "Continuing.*Breakpoint.*, test_int3 ().*" \
127 "continue to test_int3"
129 gdb_test "continue" \
130 "Continuing.*Breakpoint.*, test_int3_end ().*" \
131 "continue to test_int3_end"
133 ##########################################
136 # GDB picks a spare register to hold the rip-relative address.
137 # Exercise all the possibilities (rax-rdi, sans rsp).
139 # The order must much the order in srcfile.
140 set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" }
142 # Assign val to all specified regs.
144 proc set_regs { regs val } {
147 foreach reg ${regs} {
148 # Use send_gdb/gdb_expect so that these aren't logged as pass/fail.
149 send_gdb "set \$${reg} = ${val}\n"
151 -re "$gdb_prompt $" {
152 verbose "Setting ${reg} to ${val}." 2
155 warning "Couldn't set ${reg} to ${val}."
161 # Verify all REGS equal VAL, except REG which equals REG_VAL.
163 proc verify_regs { test_name regs val except_reg except_reg_val } {
166 foreach reg ${regs} {
168 if { "${reg}" == "${except_reg}" } {
169 set expected ${except_reg_val}
171 # The cast to (int) is because RBP is printed as a pointer.
172 gdb_test "p (int) \$${reg}" " = ${expected}${newline}" "${test_name} ${reg} expected value"
176 proc rip_test { reg } {
177 global srcfile rip_regs
179 set test_start_label "test_rip_${reg}"
180 set test_end_label "test_rip_${reg}_end"
182 gdb_test "break ${test_start_label}" \
183 "Breakpoint.*at.* file .*$srcfile, line.*"
184 gdb_test "break ${test_end_label}" \
185 "Breakpoint.*at.* file .*$srcfile, line.*"
187 gdb_test "continue" \
188 "Continuing.*Breakpoint.*, ${test_start_label} ().*" \
189 "continue to ${test_start_label}"
191 set_regs ${rip_regs} 0
193 gdb_test "continue" \
194 "Continuing.*Breakpoint.*, ${test_end_label} ().*" \
195 "continue to ${test_end_label}"
197 verify_regs "test rip w/${reg}" ${rip_regs} 0 ${reg} 42
200 foreach reg ${rip_regs} {
204 ##########################################
206 # Done, run program to exit.
208 gdb_continue_to_end "amd64-disp-step"