1 # Copyright 2009, 2010 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.
27 if ![istarget "x86_64-*-linux*"] then {
28 verbose "Skipping x86_64 displaced stepping tests."
32 set newline "\[\r\n\]*"
34 set testfile "amd64-disp-step"
35 set srcfile ${testfile}.S
36 set binfile ${objdir}/${subdir}/${testfile}
38 set additional_flags "-Wa,-g"
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug $additional_flags]] != "" } {
41 untested amd64-disp-step.exp
49 gdb_reinitialize_dir $srcdir/$subdir
52 gdb_test "set displaced-stepping on" ""
53 gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
55 if ![runto_main] then {
56 fail "Can't run to main"
60 ##########################################
64 gdb_test "break test_call" \
65 "Breakpoint.*at.* file .*$srcfile, line.*" \
67 gdb_test "break test_call_end" \
68 "Breakpoint.*at.* file .*$srcfile, line.*" \
71 gdb_test "break test_ret" \
72 "Breakpoint.*at.* file .*$srcfile, line.*" \
74 gdb_test "break test_ret_end" \
75 "Breakpoint.*at.* file .*$srcfile, line.*" \
79 "Continuing.*Breakpoint.*, test_call ().*" \
80 "continue to test_call"
82 "Continuing.*Breakpoint.*, test_call_end ().*" \
83 "continue to test_call_end"
86 "Continuing.*Breakpoint.*, test_ret ().*" \
87 "continue to test_ret"
89 "Continuing.*Breakpoint.*, test_ret_end ().*" \
90 "continue to test_ret_end"
92 ##########################################
94 # Test abs-jmp/rep-ret.
96 gdb_test "break test_abs_jmp" \
97 "Breakpoint.*at.* file .*$srcfile, line.*" \
99 gdb_test "break test_abs_jmp_end" \
100 "Breakpoint.*at.* file .*$srcfile, line.*" \
101 "break test_abs_jmp_end"
103 gdb_test "break test_rep_ret" \
104 "Breakpoint.*at.* file .*$srcfile, line.*" \
106 gdb_test "break test_rep_ret_end" \
107 "Breakpoint.*at.* file .*$srcfile, line.*" \
108 "break test_rep_ret_end"
110 gdb_test "continue" \
111 "Continuing.*Breakpoint.*, test_abs_jmp ().*" \
112 "continue to test_abs_jmp"
113 gdb_test "continue" \
114 "Continuing.*Breakpoint.*, test_abs_jmp_end ().*" \
115 "continue to test_abs_jmp_end"
117 gdb_test "continue" \
118 "Continuing.*Breakpoint.*, test_rep_ret ().*" \
119 "continue to test_rep_ret"
120 gdb_test "continue" \
121 "Continuing.*Breakpoint.*, test_rep_ret_end ().*" \
122 "continue to test_rep_ret_end"
124 ##########################################
128 gdb_test "break test_syscall" \
129 "Breakpoint.*at.* file .*$srcfile, line.*" \
131 gdb_test "break test_syscall_end" \
132 "Breakpoint.*at.* file .*$srcfile, line.*" \
133 "break test_syscall_end"
135 gdb_test "continue" \
136 "Continuing.*Breakpoint.*, test_syscall ().*" \
137 "continue to test_syscall"
138 gdb_test "continue" \
139 "Continuing.*Breakpoint.*, test_syscall_end ().*" \
140 "continue to test_syscall_end"
142 ##########################################
144 # int3 (with prefixes)
145 # These don't occur in normal code, but gdb should still DTRT.
147 gdb_test "break test_int3" \
148 "Breakpoint.*at.* file .*$srcfile, line.*" \
150 gdb_test "break test_int3_end" \
151 "Breakpoint.*at.* file .*$srcfile, line.*" \
152 "break test_int3_end"
154 gdb_test "continue" \
155 "Continuing.*Breakpoint.*, test_int3 ().*" \
156 "continue to test_int3"
158 gdb_test "continue" \
159 "Continuing.*Breakpoint.*, test_int3_end ().*" \
160 "continue to test_int3_end"
162 ##########################################
165 # GDB picks a spare register to hold the rip-relative address.
166 # Exercise all the possibilities (rax-rdi, sans rsp).
168 # The order must much the order in srcfile.
169 set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" }
171 # Assign val to all specified regs.
173 proc set_regs { regs val } {
176 foreach reg ${regs} {
177 # Use send_gdb/gdb_expect so that these aren't logged as pass/fail.
178 send_gdb "set \$${reg} = ${val}\n"
180 -re "$gdb_prompt $" {
181 verbose "Setting ${reg} to ${val}." 2
184 warning "Couldn't set ${reg} to ${val}."
190 # Verify all REGS equal VAL, except REG which equals REG_VAL.
192 proc verify_regs { test_name regs val except_reg except_reg_val } {
195 foreach reg ${regs} {
197 if { "${reg}" == "${except_reg}" } {
198 set expected ${except_reg_val}
200 # The cast to (int) is because RBP is printed as a pointer.
201 gdb_test "p (int) \$${reg}" " = ${expected}${newline}" "${test_name} ${reg} expected value"
205 proc rip_test { reg } {
206 global srcfile rip_regs
208 set test_start_label "test_rip_${reg}"
209 set test_end_label "test_rip_${reg}_end"
211 gdb_test "break ${test_start_label}" \
212 "Breakpoint.*at.* file .*$srcfile, line.*" \
213 "break ${test_start_label}"
214 gdb_test "break ${test_end_label}" \
215 "Breakpoint.*at.* file .*$srcfile, line.*" \
216 "break ${test_end_label}"
218 gdb_test "continue" \
219 "Continuing.*Breakpoint.*, ${test_start_label} ().*" \
220 "continue to ${test_start_label}"
222 set_regs ${rip_regs} 0
224 gdb_test "continue" \
225 "Continuing.*Breakpoint.*, ${test_end_label} ().*" \
226 "continue to ${test_end_label}"
228 verify_regs "test rip w/${reg}" ${rip_regs} 0 ${reg} 42
231 foreach reg ${rip_regs} {
235 ##########################################
237 # Done, run program to exit.
239 gdb_continue_to_end "amd64-disp-step"