]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.arch/amd64-disp-step.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.arch / amd64-disp-step.exp
CommitLineData
213516ef 1# Copyright 2009-2023 Free Software Foundation, Inc.
35669430
DE
2
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.
7#
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.
12#
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/>.
15
16# This file is part of the gdb testsuite.
17
18# Test amd64 displaced stepping.
19
35669430 20
add265ae 21if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
35669430
DE
22 verbose "Skipping x86_64 displaced stepping tests."
23 return
24}
25
26set newline "\[\r\n\]*"
27
6e8b1ab2 28set opts {debug nopie}
de5f37e1 29standard_testfile .S
35669430 30
6e8b1ab2 31if { [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] } {
35669430
DE
32 return -1
33}
34
35669430
DE
35gdb_test "set displaced-stepping on" ""
36gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
37
75b6f386 38if {![runto_main]} {
35669430
DE
39 return 0
40}
41
42##########################################
43
44# Test call/ret.
45
46gdb_test "break test_call" \
d1e36019 47 "Breakpoint.*at.* file .*$srcfile, line.*"
35669430 48gdb_test "break test_call_end" \
d1e36019 49 "Breakpoint.*at.* file .*$srcfile, line.*"
35669430
DE
50
51gdb_test "break test_ret" \
d1e36019 52 "Breakpoint.*at.* file .*$srcfile, line.*"
35669430 53gdb_test "break test_ret_end" \
d1e36019 54 "Breakpoint.*at.* file .*$srcfile, line.*"
35669430
DE
55
56gdb_test "continue" \
57 "Continuing.*Breakpoint.*, test_call ().*" \
58 "continue to test_call"
59gdb_test "continue" \
60 "Continuing.*Breakpoint.*, test_call_end ().*" \
61 "continue to test_call_end"
62
63gdb_test "continue" \
64 "Continuing.*Breakpoint.*, test_ret ().*" \
65 "continue to test_ret"
66gdb_test "continue" \
67 "Continuing.*Breakpoint.*, test_ret_end ().*" \
68 "continue to test_ret_end"
69
70##########################################
71
72# Test abs-jmp/rep-ret.
73
74gdb_test "break test_abs_jmp" \
d1e36019 75 "Breakpoint.*at.* file .*$srcfile, line.*"
35669430 76gdb_test "break test_abs_jmp_end" \
d1e36019 77 "Breakpoint.*at.* file .*$srcfile, line.*"
35669430
DE
78
79gdb_test "break test_rep_ret" \
d1e36019 80 "Breakpoint.*at.* file .*$srcfile, line.*"
35669430 81gdb_test "break test_rep_ret_end" \
d1e36019 82 "Breakpoint.*at.* file .*$srcfile, line.*"
35669430
DE
83
84gdb_test "continue" \
85 "Continuing.*Breakpoint.*, test_abs_jmp ().*" \
86 "continue to test_abs_jmp"
87gdb_test "continue" \
88 "Continuing.*Breakpoint.*, test_abs_jmp_end ().*" \
89 "continue to test_abs_jmp_end"
90
91gdb_test "continue" \
92 "Continuing.*Breakpoint.*, test_rep_ret ().*" \
93 "continue to test_rep_ret"
94gdb_test "continue" \
95 "Continuing.*Breakpoint.*, test_rep_ret_end ().*" \
96 "continue to test_rep_ret_end"
97
98##########################################
99
100# Test syscall.
101
102gdb_test "break test_syscall" \
d1e36019 103 "Breakpoint.*at.* file .*$srcfile, line.*"
35669430 104gdb_test "break test_syscall_end" \
d1e36019 105 "Breakpoint.*at.* file .*$srcfile, line.*"
35669430
DE
106
107gdb_test "continue" \
108 "Continuing.*Breakpoint.*, test_syscall ().*" \
109 "continue to test_syscall"
110gdb_test "continue" \
111 "Continuing.*Breakpoint.*, test_syscall_end ().*" \
112 "continue to test_syscall_end"
113
114##########################################
115
1903f0e6
DE
116# int3 (with prefixes)
117# These don't occur in normal code, but gdb should still DTRT.
118
119gdb_test "break test_int3" \
d1e36019 120 "Breakpoint.*at.* file .*$srcfile, line.*"
1903f0e6 121gdb_test "break test_int3_end" \
d1e36019 122 "Breakpoint.*at.* file .*$srcfile, line.*"
1903f0e6
DE
123
124gdb_test "continue" \
125 "Continuing.*Breakpoint.*, test_int3 ().*" \
126 "continue to test_int3"
127
128gdb_test "continue" \
129 "Continuing.*Breakpoint.*, test_int3_end ().*" \
130 "continue to test_int3_end"
131
132##########################################
133
35669430
DE
134# Test rip-relative.
135# GDB picks a spare register to hold the rip-relative address.
136# Exercise all the possibilities (rax-rdi, sans rsp).
137
138# The order must much the order in srcfile.
139set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" }
140
141# Assign val to all specified regs.
142
143proc set_regs { regs val } {
144 global gdb_prompt
145
146 foreach reg ${regs} {
147 # Use send_gdb/gdb_expect so that these aren't logged as pass/fail.
148 send_gdb "set \$${reg} = ${val}\n"
149 gdb_expect 10 {
150 -re "$gdb_prompt $" {
151 verbose "Setting ${reg} to ${val}." 2
152 }
153 timeout {
154 warning "Couldn't set ${reg} to ${val}."
155 }
156 }
157 }
158}
159
160# Verify all REGS equal VAL, except REG which equals REG_VAL.
161
162proc verify_regs { test_name regs val except_reg except_reg_val } {
163 global newline
164
165 foreach reg ${regs} {
166 set expected ${val}
167 if { "${reg}" == "${except_reg}" } {
168 set expected ${except_reg_val}
169 }
170 # The cast to (int) is because RBP is printed as a pointer.
171 gdb_test "p (int) \$${reg}" " = ${expected}${newline}" "${test_name} ${reg} expected value"
172 }
173}
174
175proc rip_test { reg } {
176 global srcfile rip_regs
177
178 set test_start_label "test_rip_${reg}"
179 set test_end_label "test_rip_${reg}_end"
180
181 gdb_test "break ${test_start_label}" \
d1e36019 182 "Breakpoint.*at.* file .*$srcfile, line.*"
35669430 183 gdb_test "break ${test_end_label}" \
d1e36019 184 "Breakpoint.*at.* file .*$srcfile, line.*"
35669430
DE
185
186 gdb_test "continue" \
187 "Continuing.*Breakpoint.*, ${test_start_label} ().*" \
188 "continue to ${test_start_label}"
189
190 set_regs ${rip_regs} 0
191
192 gdb_test "continue" \
193 "Continuing.*Breakpoint.*, ${test_end_label} ().*" \
194 "continue to ${test_end_label}"
195
196 verify_regs "test rip w/${reg}" ${rip_regs} 0 ${reg} 42
197}
198
199foreach reg ${rip_regs} {
200 rip_test $reg
201}
202
203##########################################
204
205# Done, run program to exit.
206
207gdb_continue_to_end "amd64-disp-step"