1 # Copyright 2009-2014 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\]*"
30 set additional_flags "-Wa,-g"
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug $additional_flags]] != "" } {
33 untested amd64-disp-step.exp
41 gdb_reinitialize_dir $srcdir/$subdir
44 gdb_test "set displaced-stepping on" ""
45 gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
47 if ![runto_main] then {
48 fail "Can't run to main"
52 ##########################################
56 gdb_test "break test_call" \
57 "Breakpoint.*at.* file .*$srcfile, line.*" \
59 gdb_test "break test_call_end" \
60 "Breakpoint.*at.* file .*$srcfile, line.*" \
63 gdb_test "break test_ret" \
64 "Breakpoint.*at.* file .*$srcfile, line.*" \
66 gdb_test "break test_ret_end" \
67 "Breakpoint.*at.* file .*$srcfile, line.*" \
71 "Continuing.*Breakpoint.*, test_call ().*" \
72 "continue to test_call"
74 "Continuing.*Breakpoint.*, test_call_end ().*" \
75 "continue to test_call_end"
78 "Continuing.*Breakpoint.*, test_ret ().*" \
79 "continue to test_ret"
81 "Continuing.*Breakpoint.*, test_ret_end ().*" \
82 "continue to test_ret_end"
84 ##########################################
86 # Test abs-jmp/rep-ret.
88 gdb_test "break test_abs_jmp" \
89 "Breakpoint.*at.* file .*$srcfile, line.*" \
91 gdb_test "break test_abs_jmp_end" \
92 "Breakpoint.*at.* file .*$srcfile, line.*" \
93 "break test_abs_jmp_end"
95 gdb_test "break test_rep_ret" \
96 "Breakpoint.*at.* file .*$srcfile, line.*" \
98 gdb_test "break test_rep_ret_end" \
99 "Breakpoint.*at.* file .*$srcfile, line.*" \
100 "break test_rep_ret_end"
102 gdb_test "continue" \
103 "Continuing.*Breakpoint.*, test_abs_jmp ().*" \
104 "continue to test_abs_jmp"
105 gdb_test "continue" \
106 "Continuing.*Breakpoint.*, test_abs_jmp_end ().*" \
107 "continue to test_abs_jmp_end"
109 gdb_test "continue" \
110 "Continuing.*Breakpoint.*, test_rep_ret ().*" \
111 "continue to test_rep_ret"
112 gdb_test "continue" \
113 "Continuing.*Breakpoint.*, test_rep_ret_end ().*" \
114 "continue to test_rep_ret_end"
116 ##########################################
120 gdb_test "break test_syscall" \
121 "Breakpoint.*at.* file .*$srcfile, line.*" \
123 gdb_test "break test_syscall_end" \
124 "Breakpoint.*at.* file .*$srcfile, line.*" \
125 "break test_syscall_end"
127 gdb_test "continue" \
128 "Continuing.*Breakpoint.*, test_syscall ().*" \
129 "continue to test_syscall"
130 gdb_test "continue" \
131 "Continuing.*Breakpoint.*, test_syscall_end ().*" \
132 "continue to test_syscall_end"
134 ##########################################
136 # int3 (with prefixes)
137 # These don't occur in normal code, but gdb should still DTRT.
139 gdb_test "break test_int3" \
140 "Breakpoint.*at.* file .*$srcfile, line.*" \
142 gdb_test "break test_int3_end" \
143 "Breakpoint.*at.* file .*$srcfile, line.*" \
144 "break test_int3_end"
146 gdb_test "continue" \
147 "Continuing.*Breakpoint.*, test_int3 ().*" \
148 "continue to test_int3"
150 gdb_test "continue" \
151 "Continuing.*Breakpoint.*, test_int3_end ().*" \
152 "continue to test_int3_end"
154 ##########################################
157 # GDB picks a spare register to hold the rip-relative address.
158 # Exercise all the possibilities (rax-rdi, sans rsp).
160 # The order must much the order in srcfile.
161 set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" }
163 # Assign val to all specified regs.
165 proc set_regs { regs val } {
168 foreach reg ${regs} {
169 # Use send_gdb/gdb_expect so that these aren't logged as pass/fail.
170 send_gdb "set \$${reg} = ${val}\n"
172 -re "$gdb_prompt $" {
173 verbose "Setting ${reg} to ${val}." 2
176 warning "Couldn't set ${reg} to ${val}."
182 # Verify all REGS equal VAL, except REG which equals REG_VAL.
184 proc verify_regs { test_name regs val except_reg except_reg_val } {
187 foreach reg ${regs} {
189 if { "${reg}" == "${except_reg}" } {
190 set expected ${except_reg_val}
192 # The cast to (int) is because RBP is printed as a pointer.
193 gdb_test "p (int) \$${reg}" " = ${expected}${newline}" "${test_name} ${reg} expected value"
197 proc rip_test { reg } {
198 global srcfile rip_regs
200 set test_start_label "test_rip_${reg}"
201 set test_end_label "test_rip_${reg}_end"
203 gdb_test "break ${test_start_label}" \
204 "Breakpoint.*at.* file .*$srcfile, line.*" \
205 "break ${test_start_label}"
206 gdb_test "break ${test_end_label}" \
207 "Breakpoint.*at.* file .*$srcfile, line.*" \
208 "break ${test_end_label}"
210 gdb_test "continue" \
211 "Continuing.*Breakpoint.*, ${test_start_label} ().*" \
212 "continue to ${test_start_label}"
214 set_regs ${rip_regs} 0
216 gdb_test "continue" \
217 "Continuing.*Breakpoint.*, ${test_end_label} ().*" \
218 "continue to ${test_end_label}"
220 verify_regs "test rip w/${reg}" ${rip_regs} 0 ${reg} 42
223 foreach reg ${rip_regs} {
227 ##########################################
229 # Done, run program to exit.
231 gdb_continue_to_end "amd64-disp-step"