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