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