gdb/:
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / sigbpt.exp
CommitLineData
45a83408
AC
1# This testcase is part of GDB, the GNU debugger.
2
6aba47ca 3# Copyright 2004, 2005, 2007 Free Software Foundation, Inc.
45a83408
AC
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 2 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, write to the Free Software
17# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19# Check that GDB can and only executes single instructions when
20# stepping through a sequence of breakpoints interleaved by a signal
21# handler.
22
23# This test is known to tickle the following problems: kernel letting
24# the inferior execute both the system call, and the instruction
25# following, when single-stepping a system call; kernel failing to
26# propogate the single-step state when single-stepping the sigreturn
27# system call, instead resuming the inferior at full speed; GDB
28# doesn't know how to software single-step across a sigreturn
29# instruction. Since the kernel problems can be "fixed" using
30# software single-step this is KFAILed rather than XFAILed.
31
5f579bc5 32if [target_info exists gdb,nosignals] {
446ab585 33 verbose "Skipping sigbpt.exp because of nosignals."
5f579bc5
NS
34 continue
35}
36
45a83408
AC
37if $tracelevel {
38 strace $tracelevel
39}
40
41set prms_id 0
42set bug_id 0
43
44set testfile "sigbpt"
45set srcfile ${testfile}.c
46set binfile ${objdir}/${subdir}/${testfile}
47if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b60f0898
JB
48 untested sigbpt.exp
49 return -1
45a83408
AC
50}
51
52gdb_exit
53gdb_start
54gdb_reinitialize_dir $srcdir/$subdir
55gdb_load ${binfile}
56
57#
58# Run to `main' where we begin our tests.
59#
60
61if ![runto_main] then {
62 gdb_suppress_tests
63}
64
65# If we can examine what's at memory address 0, it is possible that we
66# could also execute it. This could probably make us run away,
67# executing random code, which could have all sorts of ill effects,
68# especially on targets without an MMU. Don't run the tests in that
69# case.
70
71send_gdb "x 0\n"
72gdb_expect {
73 -re "0x0:.*Cannot access memory at address 0x0.*$gdb_prompt $" { }
74 -re "0x0:.*Error accessing memory address 0x0.*$gdb_prompt $" { }
75 -re ".*$gdb_prompt $" {
76 untested "Memory at address 0 is possibly executable"
77 return
78 }
79}
80
81gdb_test "break keeper"
82
83# Run to bowler, and then single step until there's a SIGSEGV. Record
84# the address of each single-step instruction (up to and including the
85# instruction that causes the SIGSEGV) in bowler_addrs, and the address
86# of the actual SIGSEGV in segv_addr.
87
88set bowler_addrs bowler
d12371a9 89set segv_addr none
45a83408
AC
90gdb_test {display/i $pc}
91gdb_test "advance *bowler" "bowler.*" "advance to the bowler"
92set test "stepping to SIGSEGV"
93gdb_test_multiple "stepi" "$test" {
94 -re "Program received signal SIGSEGV.*pc *(0x\[0-9a-f\]*).*$gdb_prompt $" {
95 set segv_addr $expect_out(1,string)
96 pass "$test"
97 }
98 -re " .*pc *(0x\[0-9a-f\]*).*bowler.*$gdb_prompt $" {
99 set bowler_addrs [concat $expect_out(1,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
108set test "get insn after fault"
109gdb_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
119proc before_segv { } {
120 global bowler_addrs
121 return [lindex $bowler_addrs 2]
122}
123
124proc at_segv { } {
125 global bowler_addrs
126 return [lindex $bowler_addrs 1]
127}
128
129proc after_segv { } {
130 global bowler_addrs
131 return [lindex $bowler_addrs 0]
132}
133
134# Check that the address table and SIGSEGV correspond.
135
136set test "Verify that SIGSEGV occurs at the last STEPI insn"
137if {[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
146proc stepi_out { name args } {
147 global gdb_prompt
148
149 # Set SIGSEGV to pass+nostop and then run the inferior all the way
150 # through to the signal handler. With the handler is reached,
151 # disable SIGSEGV, ensuring that further signals stop the
152 # inferior. Stops a SIGSEGV infinite loop when a broke system
153 # keeps re-executing the faulting instruction.
154 rerun_to_main
1544280f
AC
155 gdb_test "handle SIGSEGV nostop print pass" "" "${name}; pass SIGSEGV"
156 gdb_test "continue" "keeper.*" "${name}; continue to keeper"
157 gdb_test "handle SIGSEGV stop print nopass" "" "${name}; nopass SIGSEGV"
45a83408
AC
158
159 # Insert all the breakpoints. To avoid the need to step over
160 # these instructions, this is delayed until after the keeper has
161 # been reached.
162 for {set i 0} {$i < [llength $args]} {incr i} {
163 gdb_test "break [lindex $args $i]" "Breakpoint.*" \
1544280f 164 "${name}; set breakpoint $i of [llength $args]"
45a83408
AC
165 }
166
167 # Single step our way out of the keeper, through the signal
168 # trampoline, and back to the instruction that faulted.
1544280f 169 set test "${name}; stepi out of handler"
45a83408 170 gdb_test_multiple "stepi" "$test" {
8608915f
MK
171 -re "Could not insert single-step breakpoint.*$gdb_prompt $" {
172 setup_kfail "sparc*-*-openbsd*" gdb/1736
173 fail "$test (could not insert single-step breakpoint)"
174 }
45a83408
AC
175 -re "keeper.*$gdb_prompt $" {
176 send_gdb "stepi\n"
177 exp_continue
178 }
179 -re "signal handler.*$gdb_prompt $" {
180 send_gdb "stepi\n"
181 exp_continue
182 }
183 -re "Program received signal SIGSEGV.*$gdb_prompt $" {
184 kfail gdb/1702 "$test (executed fault insn)"
185 }
186 -re "Breakpoint.*pc *[at_segv] .*bowler.*$gdb_prompt $" {
187 pass "$test (at breakpoint)"
188 }
189 -re "Breakpoint.*pc *[after_segv] .*bowler.*$gdb_prompt $" {
190 kfail gdb/1702 "$test (executed breakpoint)"
191 }
192 -re "pc *[at_segv] .*bowler.*$gdb_prompt $" {
193 pass "$test"
194 }
195 -re "pc *[after_segv] .*bowler.*$gdb_prompt $" {
196 kfail gdb/1702 "$test (skipped fault insn)"
197 }
56401cd5
AC
198 -re "pc *0x\[a-z0-9\]* .*bowler.*$gdb_prompt $" {
199 kfail gdb/1702 "$test (corrupt pc)"
200 }
45a83408
AC
201 }
202
203 # Clear any breakpoints
204 for {set i 0} {$i < [llength $args]} {incr i} {
205 gdb_test "clear [lindex $args $i]" "Deleted .*" \
1544280f 206 "${name}; clear breakpoint $i of [llength $args]"
45a83408
AC
207 }
208}
209
210# Let a signal handler exit, returning to a breakpoint instruction
211# inserted at the original fault instruction. Check that the
212# breakpoint is hit, and that single stepping off that breakpoint
213# executes the underlying fault instruction causing a SIGSEGV.
214
215proc cont_out { name args } {
216 global gdb_prompt
217
218 # Set SIGSEGV to pass+nostop and then run the inferior all the way
219 # through to the signal handler. With the handler is reached,
220 # disable SIGSEGV, ensuring that further signals stop the
221 # inferior. Stops a SIGSEGV infinite loop when a broke system
222 # keeps re-executing the faulting instruction.
223 rerun_to_main
1544280f
AC
224 gdb_test "handle SIGSEGV nostop print pass" "" "${name}; pass SIGSEGV"
225 gdb_test "continue" "keeper.*" "${name}; continue to keeper"
226 gdb_test "handle SIGSEGV stop print nopass" "" "${name}; nopass SIGSEGV"
45a83408
AC
227
228 # Insert all the breakpoints. To avoid the need to step over
229 # these instructions, this is delayed until after the keeper has
230 # been reached. Always set a breakpoint at the signal trampoline
231 # instruction.
232 set args [concat $args "*[at_segv]"]
233 for {set i 0} {$i < [llength $args]} {incr i} {
234 gdb_test "break [lindex $args $i]" "Breakpoint.*" \
1544280f 235 "${name}; set breakpoint $i of [llength $args]"
45a83408
AC
236 }
237
238 # Let the handler return, it should "appear to hit" the breakpoint
239 # inserted at the faulting instruction. Note that the breakpoint
240 # instruction wasn't executed, rather the inferior was SIGTRAPed
241 # with the PC at the breakpoint.
242 gdb_test "continue" "Breakpoint.*pc *[at_segv] .*" \
1544280f 243 "${name}; continue to breakpoint at fault"
45a83408
AC
244
245 # Now single step the faulted instrction at that breakpoint.
246 gdb_test "stepi" \
247 "Program received signal SIGSEGV.*pc *[at_segv] .*" \
1544280f 248 "${name}; stepi fault"
45a83408
AC
249
250 # Clear any breakpoints
251 for {set i 0} {$i < [llength $args]} {incr i} {
252 gdb_test "clear [lindex $args $i]" "Deleted .*" \
1544280f 253 "${name}; clear breakpoint $i of [llength $args]"
45a83408
AC
254 }
255
256}
257
258
259
260# Try to confuse DECR_PC_AFTER_BREAK architectures by scattering
261# breakpoints around the faulting address. In all cases the inferior
262# should single-step out of the signal trampoline halting (but not
263# executing) the fault instruction.
264
265stepi_out "stepi"
266stepi_out "stepi bp before segv" "*[before_segv]"
267stepi_out "stepi bp at segv" "*[at_segv]"
268stepi_out "stepi bp before and at segv" "*[at_segv]" "*[before_segv]"
269
270
271# Try to confuse DECR_PC_AFTER_BREAK architectures by scattering
272# breakpoints around the faulting address. In all cases the inferior
273# should exit the signal trampoline halting at the breakpoint that
274# replaced the fault instruction.
275cont_out "cont"
276cont_out "cont bp after segv" "*[before_segv]"
277cont_out "cont bp before and after segv" "*[before_segv]" "*[after_segv]"
This page took 0.304622 seconds and 4 git commands to generate.