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