2011-02-21 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.arch / amd64-disp-step.exp
1 # Copyright 2009, 2010, 2011 Free Software Foundation, Inc.
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
20 if $tracelevel {
21 strace $tracelevel
22 }
23
24
25 if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
26 verbose "Skipping x86_64 displaced stepping tests."
27 return
28 }
29
30 set newline "\[\r\n\]*"
31
32 set testfile "amd64-disp-step"
33 set srcfile ${testfile}.S
34 set binfile ${objdir}/${subdir}/${testfile}
35
36 set additional_flags "-Wa,-g"
37
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug $additional_flags]] != "" } {
39 untested amd64-disp-step.exp
40 return -1
41 }
42
43 # Get things started.
44
45 gdb_exit
46 gdb_start
47 gdb_reinitialize_dir $srcdir/$subdir
48 gdb_load ${binfile}
49
50 gdb_test "set displaced-stepping on" ""
51 gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
52
53 if ![runto_main] then {
54 fail "Can't run to main"
55 return 0
56 }
57
58 ##########################################
59
60 # Test call/ret.
61
62 gdb_test "break test_call" \
63 "Breakpoint.*at.* file .*$srcfile, line.*" \
64 "break test_call"
65 gdb_test "break test_call_end" \
66 "Breakpoint.*at.* file .*$srcfile, line.*" \
67 "break test_call_end"
68
69 gdb_test "break test_ret" \
70 "Breakpoint.*at.* file .*$srcfile, line.*" \
71 "break test_ret"
72 gdb_test "break test_ret_end" \
73 "Breakpoint.*at.* file .*$srcfile, line.*" \
74 "break test_ret_end"
75
76 gdb_test "continue" \
77 "Continuing.*Breakpoint.*, test_call ().*" \
78 "continue to test_call"
79 gdb_test "continue" \
80 "Continuing.*Breakpoint.*, test_call_end ().*" \
81 "continue to test_call_end"
82
83 gdb_test "continue" \
84 "Continuing.*Breakpoint.*, test_ret ().*" \
85 "continue to test_ret"
86 gdb_test "continue" \
87 "Continuing.*Breakpoint.*, test_ret_end ().*" \
88 "continue to test_ret_end"
89
90 ##########################################
91
92 # Test abs-jmp/rep-ret.
93
94 gdb_test "break test_abs_jmp" \
95 "Breakpoint.*at.* file .*$srcfile, line.*" \
96 "break test_abs_jmp"
97 gdb_test "break test_abs_jmp_end" \
98 "Breakpoint.*at.* file .*$srcfile, line.*" \
99 "break test_abs_jmp_end"
100
101 gdb_test "break test_rep_ret" \
102 "Breakpoint.*at.* file .*$srcfile, line.*" \
103 "break test_rep_ret"
104 gdb_test "break test_rep_ret_end" \
105 "Breakpoint.*at.* file .*$srcfile, line.*" \
106 "break test_rep_ret_end"
107
108 gdb_test "continue" \
109 "Continuing.*Breakpoint.*, test_abs_jmp ().*" \
110 "continue to test_abs_jmp"
111 gdb_test "continue" \
112 "Continuing.*Breakpoint.*, test_abs_jmp_end ().*" \
113 "continue to test_abs_jmp_end"
114
115 gdb_test "continue" \
116 "Continuing.*Breakpoint.*, test_rep_ret ().*" \
117 "continue to test_rep_ret"
118 gdb_test "continue" \
119 "Continuing.*Breakpoint.*, test_rep_ret_end ().*" \
120 "continue to test_rep_ret_end"
121
122 ##########################################
123
124 # Test syscall.
125
126 gdb_test "break test_syscall" \
127 "Breakpoint.*at.* file .*$srcfile, line.*" \
128 "break test_syscall"
129 gdb_test "break test_syscall_end" \
130 "Breakpoint.*at.* file .*$srcfile, line.*" \
131 "break test_syscall_end"
132
133 gdb_test "continue" \
134 "Continuing.*Breakpoint.*, test_syscall ().*" \
135 "continue to test_syscall"
136 gdb_test "continue" \
137 "Continuing.*Breakpoint.*, test_syscall_end ().*" \
138 "continue to test_syscall_end"
139
140 ##########################################
141
142 # int3 (with prefixes)
143 # These don't occur in normal code, but gdb should still DTRT.
144
145 gdb_test "break test_int3" \
146 "Breakpoint.*at.* file .*$srcfile, line.*" \
147 "break test_int3"
148 gdb_test "break test_int3_end" \
149 "Breakpoint.*at.* file .*$srcfile, line.*" \
150 "break test_int3_end"
151
152 gdb_test "continue" \
153 "Continuing.*Breakpoint.*, test_int3 ().*" \
154 "continue to test_int3"
155
156 gdb_test "continue" \
157 "Continuing.*Breakpoint.*, test_int3_end ().*" \
158 "continue to test_int3_end"
159
160 ##########################################
161
162 # Test rip-relative.
163 # GDB picks a spare register to hold the rip-relative address.
164 # Exercise all the possibilities (rax-rdi, sans rsp).
165
166 # The order must much the order in srcfile.
167 set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" }
168
169 # Assign val to all specified regs.
170
171 proc set_regs { regs val } {
172 global gdb_prompt
173
174 foreach reg ${regs} {
175 # Use send_gdb/gdb_expect so that these aren't logged as pass/fail.
176 send_gdb "set \$${reg} = ${val}\n"
177 gdb_expect 10 {
178 -re "$gdb_prompt $" {
179 verbose "Setting ${reg} to ${val}." 2
180 }
181 timeout {
182 warning "Couldn't set ${reg} to ${val}."
183 }
184 }
185 }
186 }
187
188 # Verify all REGS equal VAL, except REG which equals REG_VAL.
189
190 proc verify_regs { test_name regs val except_reg except_reg_val } {
191 global newline
192
193 foreach reg ${regs} {
194 set expected ${val}
195 if { "${reg}" == "${except_reg}" } {
196 set expected ${except_reg_val}
197 }
198 # The cast to (int) is because RBP is printed as a pointer.
199 gdb_test "p (int) \$${reg}" " = ${expected}${newline}" "${test_name} ${reg} expected value"
200 }
201 }
202
203 proc rip_test { reg } {
204 global srcfile rip_regs
205
206 set test_start_label "test_rip_${reg}"
207 set test_end_label "test_rip_${reg}_end"
208
209 gdb_test "break ${test_start_label}" \
210 "Breakpoint.*at.* file .*$srcfile, line.*" \
211 "break ${test_start_label}"
212 gdb_test "break ${test_end_label}" \
213 "Breakpoint.*at.* file .*$srcfile, line.*" \
214 "break ${test_end_label}"
215
216 gdb_test "continue" \
217 "Continuing.*Breakpoint.*, ${test_start_label} ().*" \
218 "continue to ${test_start_label}"
219
220 set_regs ${rip_regs} 0
221
222 gdb_test "continue" \
223 "Continuing.*Breakpoint.*, ${test_end_label} ().*" \
224 "continue to ${test_end_label}"
225
226 verify_regs "test rip w/${reg}" ${rip_regs} 0 ${reg} 42
227 }
228
229 foreach reg ${rip_regs} {
230 rip_test $reg
231 }
232
233 ##########################################
234
235 # Done, run program to exit.
236
237 gdb_continue_to_end "amd64-disp-step"
This page took 0.035796 seconds and 4 git commands to generate.