Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.arch / amd64-disp-step.exp
blobdbd2b37fe7f3b6735cf95fc03910ce1b32df8d4b
1 # Copyright 2009-2023 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."
23     return
26 set newline "\[\r\n\]*"
28 set opts {debug nopie}
29 standard_testfile .S
31 if { [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] } {
32     return -1
35 gdb_test "set displaced-stepping on" ""
36 gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
38 if {![runto_main]} {
39     return 0
42 ##########################################
44 # Test call/ret.
46 gdb_test "break test_call" \
47     "Breakpoint.*at.* file .*$srcfile, line.*"
48 gdb_test "break test_call_end" \
49     "Breakpoint.*at.* file .*$srcfile, line.*"
51 gdb_test "break test_ret" \
52     "Breakpoint.*at.* file .*$srcfile, line.*"
53 gdb_test "break test_ret_end" \
54     "Breakpoint.*at.* file .*$srcfile, line.*"
56 gdb_test "continue" \
57     "Continuing.*Breakpoint.*, test_call ().*" \
58     "continue to test_call"
59 gdb_test "continue" \
60     "Continuing.*Breakpoint.*, test_call_end ().*" \
61     "continue to test_call_end"
63 gdb_test "continue" \
64     "Continuing.*Breakpoint.*, test_ret ().*" \
65     "continue to test_ret"
66 gdb_test "continue" \
67     "Continuing.*Breakpoint.*, test_ret_end ().*" \
68     "continue to test_ret_end"
70 ##########################################
72 # Test abs-jmp/rep-ret.
74 gdb_test "break test_abs_jmp" \
75     "Breakpoint.*at.* file .*$srcfile, line.*"
76 gdb_test "break test_abs_jmp_end" \
77     "Breakpoint.*at.* file .*$srcfile, line.*"
79 gdb_test "break test_rep_ret" \
80     "Breakpoint.*at.* file .*$srcfile, line.*"
81 gdb_test "break test_rep_ret_end" \
82     "Breakpoint.*at.* file .*$srcfile, line.*"
84 gdb_test "continue" \
85     "Continuing.*Breakpoint.*, test_abs_jmp ().*" \
86     "continue to test_abs_jmp"
87 gdb_test "continue" \
88     "Continuing.*Breakpoint.*, test_abs_jmp_end ().*" \
89     "continue to test_abs_jmp_end"
91 gdb_test "continue" \
92     "Continuing.*Breakpoint.*, test_rep_ret ().*" \
93     "continue to test_rep_ret"
94 gdb_test "continue" \
95     "Continuing.*Breakpoint.*, test_rep_ret_end ().*" \
96     "continue to test_rep_ret_end"
98 ##########################################
100 # Test syscall.
102 gdb_test "break test_syscall" \
103     "Breakpoint.*at.* file .*$srcfile, line.*"
104 gdb_test "break test_syscall_end" \
105     "Breakpoint.*at.* file .*$srcfile, line.*"
107 gdb_test "continue" \
108     "Continuing.*Breakpoint.*, test_syscall ().*" \
109     "continue to test_syscall"
110 gdb_test "continue" \
111     "Continuing.*Breakpoint.*, test_syscall_end ().*" \
112     "continue to test_syscall_end"
114 ##########################################
116 # int3 (with prefixes)
117 # These don't occur in normal code, but gdb should still DTRT.
119 gdb_test "break test_int3" \
120     "Breakpoint.*at.* file .*$srcfile, line.*"
121 gdb_test "break test_int3_end" \
122     "Breakpoint.*at.* file .*$srcfile, line.*"
124 gdb_test "continue" \
125     "Continuing.*Breakpoint.*, test_int3 ().*" \
126     "continue to test_int3"
128 gdb_test "continue" \
129     "Continuing.*Breakpoint.*, test_int3_end ().*" \
130     "continue to test_int3_end"
132 ##########################################
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).
138 # The order must much the order in srcfile.
139 set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" }
141 # Assign val to all specified regs.
143 proc set_regs { regs val } {
144     global gdb_prompt
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     }
160 # Verify all REGS equal VAL, except REG which equals REG_VAL.
162 proc verify_regs { test_name regs val except_reg except_reg_val } {
163     global newline
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     }
175 proc rip_test { reg } {
176     global srcfile rip_regs
178     set test_start_label "test_rip_${reg}"
179     set test_end_label "test_rip_${reg}_end"
181     gdb_test "break ${test_start_label}" \
182         "Breakpoint.*at.* file .*$srcfile, line.*"
183     gdb_test "break ${test_end_label}" \
184         "Breakpoint.*at.* file .*$srcfile, line.*"
186     gdb_test "continue" \
187         "Continuing.*Breakpoint.*, ${test_start_label} ().*" \
188         "continue to ${test_start_label}"
190     set_regs ${rip_regs} 0
192     gdb_test "continue" \
193         "Continuing.*Breakpoint.*, ${test_end_label} ().*" \
194         "continue to ${test_end_label}"
196     verify_regs "test rip w/${reg}" ${rip_regs} 0 ${reg} 42
199 foreach reg ${rip_regs} {
200     rip_test $reg
203 ##########################################
205 # Done, run program to exit.
207 gdb_continue_to_end "amd64-disp-step"