1 # Copyright
2009-2019 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.*" \
50 gdb_test
"break test_call_end" \
51 "Breakpoint.*at.* file .*$srcfile, line.*" \
54 gdb_test
"break test_ret" \
55 "Breakpoint.*at.* file .*$srcfile, line.*" \
57 gdb_test
"break test_ret_end" \
58 "Breakpoint.*at.* file .*$srcfile, line.*" \
62 "Continuing.*Breakpoint.*, test_call ().*" \
63 "continue to test_call"
65 "Continuing.*Breakpoint.*, test_call_end ().*" \
66 "continue to test_call_end"
69 "Continuing.*Breakpoint.*, test_ret ().*" \
70 "continue to test_ret"
72 "Continuing.*Breakpoint.*, test_ret_end ().*" \
73 "continue to test_ret_end"
75 ##########################################
77 # Test
abs-jmp
/rep
-ret.
79 gdb_test
"break test_abs_jmp" \
80 "Breakpoint.*at.* file .*$srcfile, line.*" \
82 gdb_test
"break test_abs_jmp_end" \
83 "Breakpoint.*at.* file .*$srcfile, line.*" \
84 "break test_abs_jmp_end"
86 gdb_test
"break test_rep_ret" \
87 "Breakpoint.*at.* file .*$srcfile, line.*" \
89 gdb_test
"break test_rep_ret_end" \
90 "Breakpoint.*at.* file .*$srcfile, line.*" \
91 "break test_rep_ret_end"
94 "Continuing.*Breakpoint.*, test_abs_jmp ().*" \
95 "continue to test_abs_jmp"
97 "Continuing.*Breakpoint.*, test_abs_jmp_end ().*" \
98 "continue to test_abs_jmp_end"
100 gdb_test
"continue" \
101 "Continuing.*Breakpoint.*, test_rep_ret ().*" \
102 "continue to test_rep_ret"
103 gdb_test
"continue" \
104 "Continuing.*Breakpoint.*, test_rep_ret_end ().*" \
105 "continue to test_rep_ret_end"
107 ##########################################
111 gdb_test
"break test_syscall" \
112 "Breakpoint.*at.* file .*$srcfile, line.*" \
114 gdb_test
"break test_syscall_end" \
115 "Breakpoint.*at.* file .*$srcfile, line.*" \
116 "break test_syscall_end"
118 gdb_test
"continue" \
119 "Continuing.*Breakpoint.*, test_syscall ().*" \
120 "continue to test_syscall"
121 gdb_test
"continue" \
122 "Continuing.*Breakpoint.*, test_syscall_end ().*" \
123 "continue to test_syscall_end"
125 ##########################################
127 # int3
(with prefixes
)
128 # These don
't occur in normal code, but gdb should still DTRT.
130 gdb_test "break test_int3" \
131 "Breakpoint.*at.* file .*$srcfile, line.*" \
133 gdb_test "break test_int3_end" \
134 "Breakpoint.*at.* file .*$srcfile, line.*" \
135 "break test_int3_end"
137 gdb_test "continue" \
138 "Continuing.*Breakpoint.*, test_int3 ().*" \
139 "continue to test_int3"
141 gdb_test "continue" \
142 "Continuing.*Breakpoint.*, test_int3_end ().*" \
143 "continue to test_int3_end"
145 ##########################################
148 # GDB picks a spare register to hold the rip-relative address.
149 # Exercise all the possibilities (rax-rdi, sans rsp).
151 # The order must much the order in srcfile.
152 set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" }
154 # Assign val to all specified regs.
156 proc set_regs { regs val } {
159 foreach reg ${regs} {
160 # Use send_gdb/gdb_expect so that these aren't logged as pass
/fail.
161 send_gdb
"set \$${reg} = ${val}\n"
163 -re
"$gdb_prompt $" {
164 verbose
"Setting ${reg} to ${val}." 2
167 warning
"Couldn't set ${reg} to ${val}."
173 # Verify all REGS equal VAL
, except REG which equals REG_VAL.
175 proc verify_regs
{ test_name regs val except_reg except_reg_val
} {
178 foreach reg $
{regs
} {
180 if { "${reg}" == "${except_reg}" } {
181 set expected $
{except_reg_val
}
183 # The cast to
(int) is because RBP is printed as a pointer.
184 gdb_test
"p (int) \$${reg}" " = ${expected}${newline}" "${test_name} ${reg} expected value"
188 proc rip_test
{ reg
} {
189 global srcfile rip_regs
191 set test_start_label
"test_rip_${reg}"
192 set test_end_label
"test_rip_${reg}_end"
194 gdb_test
"break ${test_start_label}" \
195 "Breakpoint.*at.* file .*$srcfile, line.*" \
196 "break ${test_start_label}"
197 gdb_test
"break ${test_end_label}" \
198 "Breakpoint.*at.* file .*$srcfile, line.*" \
199 "break ${test_end_label}"
201 gdb_test
"continue" \
202 "Continuing.*Breakpoint.*, ${test_start_label} ().*" \
203 "continue to ${test_start_label}"
205 set_regs $
{rip_regs
} 0
207 gdb_test
"continue" \
208 "Continuing.*Breakpoint.*, ${test_end_label} ().*" \
209 "continue to ${test_end_label}"
211 verify_regs
"test rip w/${reg}" ${rip_regs} 0 ${reg} 42
214 foreach reg $
{rip_regs
} {
218 ##########################################
220 # Done
, run
program to exit.
222 gdb_continue_to_end
"amd64-disp-step"