1 # Copyright 2009, 2010, 2011 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.
25 if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
26 verbose "Skipping x86_64 displaced stepping tests."
30 set newline "\[\r\n\]*"
32 set testfile "amd64-disp-step"
33 set srcfile ${testfile}.S
34 set binfile ${objdir}/${subdir}/${testfile}
36 set additional_flags "-Wa,-g"
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug $additional_flags]] != "" } {
39 untested amd64-disp-step.exp
47 gdb_reinitialize_dir $srcdir/$subdir
50 gdb_test "set displaced-stepping on" ""
51 gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
53 if ![runto_main] then {
54 fail "Can't run to main"
58 ##########################################
62 gdb_test "break test_call" \
63 "Breakpoint.*at.* file .*$srcfile, line.*" \
65 gdb_test "break test_call_end" \
66 "Breakpoint.*at.* file .*$srcfile, line.*" \
69 gdb_test "break test_ret" \
70 "Breakpoint.*at.* file .*$srcfile, line.*" \
72 gdb_test "break test_ret_end" \
73 "Breakpoint.*at.* file .*$srcfile, line.*" \
77 "Continuing.*Breakpoint.*, test_call ().*" \
78 "continue to test_call"
80 "Continuing.*Breakpoint.*, test_call_end ().*" \
81 "continue to test_call_end"
84 "Continuing.*Breakpoint.*, test_ret ().*" \
85 "continue to test_ret"
87 "Continuing.*Breakpoint.*, test_ret_end ().*" \
88 "continue to test_ret_end"
90 ##########################################
92 # Test abs-jmp/rep-ret.
94 gdb_test "break test_abs_jmp" \
95 "Breakpoint.*at.* file .*$srcfile, line.*" \
97 gdb_test "break test_abs_jmp_end" \
98 "Breakpoint.*at.* file .*$srcfile, line.*" \
99 "break test_abs_jmp_end"
101 gdb_test "break test_rep_ret" \
102 "Breakpoint.*at.* file .*$srcfile, line.*" \
104 gdb_test "break test_rep_ret_end" \
105 "Breakpoint.*at.* file .*$srcfile, line.*" \
106 "break test_rep_ret_end"
108 gdb_test "continue" \
109 "Continuing.*Breakpoint.*, test_abs_jmp ().*" \
110 "continue to test_abs_jmp"
111 gdb_test "continue" \
112 "Continuing.*Breakpoint.*, test_abs_jmp_end ().*" \
113 "continue to test_abs_jmp_end"
115 gdb_test "continue" \
116 "Continuing.*Breakpoint.*, test_rep_ret ().*" \
117 "continue to test_rep_ret"
118 gdb_test "continue" \
119 "Continuing.*Breakpoint.*, test_rep_ret_end ().*" \
120 "continue to test_rep_ret_end"
122 ##########################################
126 gdb_test "break test_syscall" \
127 "Breakpoint.*at.* file .*$srcfile, line.*" \
129 gdb_test "break test_syscall_end" \
130 "Breakpoint.*at.* file .*$srcfile, line.*" \
131 "break test_syscall_end"
133 gdb_test "continue" \
134 "Continuing.*Breakpoint.*, test_syscall ().*" \
135 "continue to test_syscall"
136 gdb_test "continue" \
137 "Continuing.*Breakpoint.*, test_syscall_end ().*" \
138 "continue to test_syscall_end"
140 ##########################################
142 # int3 (with prefixes)
143 # These don't occur in normal code, but gdb should still DTRT.
145 gdb_test "break test_int3" \
146 "Breakpoint.*at.* file .*$srcfile, line.*" \
148 gdb_test "break test_int3_end" \
149 "Breakpoint.*at.* file .*$srcfile, line.*" \
150 "break test_int3_end"
152 gdb_test "continue" \
153 "Continuing.*Breakpoint.*, test_int3 ().*" \
154 "continue to test_int3"
156 gdb_test "continue" \
157 "Continuing.*Breakpoint.*, test_int3_end ().*" \
158 "continue to test_int3_end"
160 ##########################################
163 # GDB picks a spare register to hold the rip-relative address.
164 # Exercise all the possibilities (rax-rdi, sans rsp).
166 # The order must much the order in srcfile.
167 set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" }
169 # Assign val to all specified regs.
171 proc set_regs { regs val } {
174 foreach reg ${regs} {
175 # Use send_gdb/gdb_expect so that these aren't logged as pass/fail.
176 send_gdb "set \$${reg} = ${val}\n"
178 -re "$gdb_prompt $" {
179 verbose "Setting ${reg} to ${val}." 2
182 warning "Couldn't set ${reg} to ${val}."
188 # Verify all REGS equal VAL, except REG which equals REG_VAL.
190 proc verify_regs { test_name regs val except_reg except_reg_val } {
193 foreach reg ${regs} {
195 if { "${reg}" == "${except_reg}" } {
196 set expected ${except_reg_val}
198 # The cast to (int) is because RBP is printed as a pointer.
199 gdb_test "p (int) \$${reg}" " = ${expected}${newline}" "${test_name} ${reg} expected value"
203 proc rip_test { reg } {
204 global srcfile rip_regs
206 set test_start_label "test_rip_${reg}"
207 set test_end_label "test_rip_${reg}_end"
209 gdb_test "break ${test_start_label}" \
210 "Breakpoint.*at.* file .*$srcfile, line.*" \
211 "break ${test_start_label}"
212 gdb_test "break ${test_end_label}" \
213 "Breakpoint.*at.* file .*$srcfile, line.*" \
214 "break ${test_end_label}"
216 gdb_test "continue" \
217 "Continuing.*Breakpoint.*, ${test_start_label} ().*" \
218 "continue to ${test_start_label}"
220 set_regs ${rip_regs} 0
222 gdb_test "continue" \
223 "Continuing.*Breakpoint.*, ${test_end_label} ().*" \
224 "continue to ${test_end_label}"
226 verify_regs "test rip w/${reg}" ${rip_regs} 0 ${reg} 42
229 foreach reg ${rip_regs} {
233 ##########################################
235 # Done, run program to exit.
237 gdb_continue_to_end "amd64-disp-step"