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