]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/sigbpt.exp
2010-06-08 Michael Snyder <msnyder@vmware.com>
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / sigbpt.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2004, 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 # Check that GDB can and only executes single instructions when
19 # stepping through a sequence of breakpoints interleaved by a signal
20 # handler.
21
22 # This test is known to tickle the following problems: kernel letting
23 # the inferior execute both the system call, and the instruction
24 # following, when single-stepping a system call; kernel failing to
25 # propogate the single-step state when single-stepping the sigreturn
26 # system call, instead resuming the inferior at full speed; GDB
27 # doesn't know how to software single-step across a sigreturn
28 # instruction. Since the kernel problems can be "fixed" using
29 # software single-step this is KFAILed rather than XFAILed.
30
31 if [target_info exists gdb,nosignals] {
32 verbose "Skipping sigbpt.exp because of nosignals."
33 continue
34 }
35
36 if $tracelevel {
37 strace $tracelevel
38 }
39
40
41 set testfile "sigbpt"
42 set srcfile ${testfile}.c
43 set binfile ${objdir}/${subdir}/${testfile}
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
45 untested sigbpt.exp
46 return -1
47 }
48
49 gdb_exit
50 gdb_start
51 gdb_reinitialize_dir $srcdir/$subdir
52 gdb_load ${binfile}
53
54 #
55 # Run to `main' where we begin our tests.
56 #
57
58 if ![runto_main] then {
59 gdb_suppress_tests
60 }
61
62 # If we can examine what's at memory address 0, it is possible that we
63 # could also execute it. This could probably make us run away,
64 # executing random code, which could have all sorts of ill effects,
65 # especially on targets without an MMU. Don't run the tests in that
66 # case.
67
68 gdb_test_multiple "x 0" "memory at address 0" {
69 -re "0x0:.*Cannot access memory at address 0x0.*$gdb_prompt $" { }
70 -re "0x0:.*Error accessing memory address 0x0.*$gdb_prompt $" { }
71 -re ".*$gdb_prompt $" {
72 untested "Memory at address 0 is possibly executable"
73 return
74 }
75 }
76
77 gdb_test "break keeper"
78
79 # Run to bowler, and then single step until there's a SIGSEGV. Record
80 # the address of each single-step instruction (up to and including the
81 # instruction that causes the SIGSEGV) in bowler_addrs, and the address
82 # of the actual SIGSEGV in segv_addr.
83 # Note: this test detects which signal is received. Usually it is SIGSEGV
84 # (and we use SIGSEGV in comments) but on Darwin it is SIGBUS.
85
86 set bowler_addrs bowler
87 set segv_addr none
88 gdb_test {display/i $pc}
89 gdb_test "advance *bowler" "bowler.*" "advance to the bowler"
90 set test "stepping to fault"
91 set signame "SIGSEGV"
92 gdb_test_multiple "stepi" "$test" {
93 -re "Program received signal (SIGBUS|SIGSEGV).*pc(\r\n| *) *=> (0x\[0-9a-f\]*).*$gdb_prompt $" {
94 set signame $expect_out(1,string)
95 set segv_addr $expect_out(3,string)
96 pass "$test"
97 }
98 -re " .*pc(\r\n| *)=> (0x\[0-9a-f\]*).*bowler.*$gdb_prompt $" {
99 set bowler_addrs [concat $expect_out(2,string) $bowler_addrs]
100 send_gdb "stepi\n"
101 exp_continue
102 }
103 }
104
105 # Now record the address of the instruction following the faulting
106 # instruction in bowler_addrs.
107
108 set test "get insn after fault"
109 gdb_test_multiple {x/2i $pc} "$test" {
110 -re "=> (0x\[0-9a-f\]*).*bowler.*(0x\[0-9a-f\]*).*bowler.*$gdb_prompt $" {
111 set bowler_addrs [concat $expect_out(2,string) $bowler_addrs]
112 pass "$test"
113 }
114 }
115
116 # Procedures for returning the address of the instruction before, at
117 # and after, the faulting instruction.
118
119 proc before_segv { } {
120 global bowler_addrs
121 return [lindex $bowler_addrs 2]
122 }
123
124 proc at_segv { } {
125 global bowler_addrs
126 return [lindex $bowler_addrs 1]
127 }
128
129 proc after_segv { } {
130 global bowler_addrs
131 return [lindex $bowler_addrs 0]
132 }
133
134 # Check that the address table and SIGSEGV correspond.
135
136 set test "Verify that ${signame} occurs at the last STEPI insn"
137 if {[string compare $segv_addr [at_segv]] == 0} {
138 pass "$test"
139 } else {
140 fail "$test ($segv_addr [at_segv])"
141 }
142
143 # Check that the inferior is correctly single stepped all the way back
144 # to a faulting instruction.
145
146 proc stepi_out { name args } {
147 global gdb_prompt
148 global signame
149
150 # Set SIGSEGV to pass+nostop and then run the inferior all the way
151 # through to the signal handler. With the handler is reached,
152 # disable SIGSEGV, ensuring that further signals stop the
153 # inferior. Stops a SIGSEGV infinite loop when a broke system
154 # keeps re-executing the faulting instruction.
155 rerun_to_main
156 gdb_test "handle ${signame} nostop print pass" ".*" "${name}; pass ${signame}"
157 gdb_test "continue" "keeper.*" "${name}; continue to keeper"
158 gdb_test "handle ${signame} stop print nopass" ".*" "${name}; nopass ${signame}"
159
160 # Insert all the breakpoints. To avoid the need to step over
161 # these instructions, this is delayed until after the keeper has
162 # been reached.
163 for {set i 0} {$i < [llength $args]} {incr i} {
164 gdb_test "break [lindex $args $i]" "Breakpoint.*" \
165 "${name}; set breakpoint $i of [llength $args]"
166 }
167
168 # Single step our way out of the keeper, through the signal
169 # trampoline, and back to the instruction that faulted.
170 set test "${name}; stepi out of handler"
171 gdb_test_multiple "stepi" "$test" {
172 -re "Could not insert single-step breakpoint.*$gdb_prompt $" {
173 setup_kfail gdb/1736 "sparc*-*-openbsd*"
174 fail "$test (could not insert single-step breakpoint)"
175 }
176 -re "keeper.*$gdb_prompt $" {
177 send_gdb "stepi\n"
178 exp_continue
179 }
180 -re "signal handler.*$gdb_prompt $" {
181 send_gdb "stepi\n"
182 exp_continue
183 }
184 -re "Program received signal SIGSEGV.*$gdb_prompt $" {
185 kfail gdb/1702 "$test (executed fault insn)"
186 }
187 -re "Breakpoint.*pc(\r\n| *)[at_segv] .*bowler.*$gdb_prompt $" {
188 pass "$test (at breakpoint)"
189 }
190 -re "Breakpoint.*pc(\r\n| *)[after_segv] .*bowler.*$gdb_prompt $" {
191 kfail gdb/1702 "$test (executed breakpoint)"
192 }
193 -re "pc(\r\n| *)[at_segv] .*bowler.*$gdb_prompt $" {
194 pass "$test"
195 }
196 -re "pc(\r\n| *)[after_segv] .*bowler.*$gdb_prompt $" {
197 kfail gdb/1702 "$test (skipped fault insn)"
198 }
199 -re "pc(\r\n| *)=> 0x\[a-z0-9\]* .*bowler.*$gdb_prompt $" {
200 kfail gdb/1702 "$test (corrupt pc)"
201 }
202 }
203
204 # Clear any breakpoints
205 for {set i 0} {$i < [llength $args]} {incr i} {
206 gdb_test "clear [lindex $args $i]" "Deleted .*" \
207 "${name}; clear breakpoint $i of [llength $args]"
208 }
209 }
210
211 # Let a signal handler exit, returning to a breakpoint instruction
212 # inserted at the original fault instruction. Check that the
213 # breakpoint is hit, and that single stepping off that breakpoint
214 # executes the underlying fault instruction causing a SIGSEGV.
215
216 proc cont_out { name args } {
217 global gdb_prompt
218 global signame
219
220 # Set SIGSEGV to pass+nostop and then run the inferior all the way
221 # through to the signal handler. With the handler is reached,
222 # disable SIGSEGV, ensuring that further signals stop the
223 # inferior. Stops a SIGSEGV infinite loop when a broke system
224 # keeps re-executing the faulting instruction.
225 rerun_to_main
226 gdb_test "handle ${signame} nostop print pass" ".*" "${name}; pass ${signame}"
227 gdb_test "continue" "keeper.*" "${name}; continue to keeper"
228 gdb_test "handle ${signame} stop print nopass" ".*" "${name}; nopass ${signame}"
229
230 # Insert all the breakpoints. To avoid the need to step over
231 # these instructions, this is delayed until after the keeper has
232 # been reached. Always set a breakpoint at the signal trampoline
233 # instruction.
234 set args [concat $args "*[at_segv]"]
235 for {set i 0} {$i < [llength $args]} {incr i} {
236 gdb_test "break [lindex $args $i]" "Breakpoint.*" \
237 "${name}; set breakpoint $i of [llength $args]"
238 }
239
240 # Let the handler return, it should "appear to hit" the breakpoint
241 # inserted at the faulting instruction. Note that the breakpoint
242 # instruction wasn't executed, rather the inferior was SIGTRAPed
243 # with the PC at the breakpoint.
244 gdb_test "continue" "Breakpoint.*pc(\r\n| *)=> [at_segv] .*" \
245 "${name}; continue to breakpoint at fault"
246
247 # Now single step the faulted instrction at that breakpoint.
248 gdb_test "stepi" \
249 "Program received signal ${signame}.*pc(\r\n| *)=> [at_segv] .*" \
250 "${name}; stepi fault"
251
252 # Clear any breakpoints
253 for {set i 0} {$i < [llength $args]} {incr i} {
254 gdb_test "clear [lindex $args $i]" "Deleted .*" \
255 "${name}; clear breakpoint $i of [llength $args]"
256 }
257
258 }
259
260
261
262 # Try to confuse DECR_PC_AFTER_BREAK architectures by scattering
263 # breakpoints around the faulting address. In all cases the inferior
264 # should single-step out of the signal trampoline halting (but not
265 # executing) the fault instruction.
266
267 stepi_out "stepi"
268 stepi_out "stepi bp before segv" "*[before_segv]"
269 stepi_out "stepi bp at segv" "*[at_segv]"
270 stepi_out "stepi bp before and at segv" "*[at_segv]" "*[before_segv]"
271
272
273 # Try to confuse DECR_PC_AFTER_BREAK architectures by scattering
274 # breakpoints around the faulting address. In all cases the inferior
275 # should exit the signal trampoline halting at the breakpoint that
276 # replaced the fault instruction.
277 cont_out "cont"
278 cont_out "cont bp after segv" "*[before_segv]"
279 cont_out "cont bp before and after segv" "*[before_segv]" "*[after_segv]"