Commit | Line | Data |
---|---|---|
45a83408 AC |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
4c38e0a4 | 3 | # Copyright 2004, 2005, 2007, 2008, 2009, 2010 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 | |
e22f8b7c | 7 | # the Free Software Foundation; either version 3 of the License, or |
45a83408 AC |
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 | |
e22f8b7c | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
45a83408 AC |
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 | ||
5f579bc5 | 31 | if [target_info exists gdb,nosignals] { |
446ab585 | 32 | verbose "Skipping sigbpt.exp because of nosignals." |
5f579bc5 NS |
33 | continue |
34 | } | |
35 | ||
45a83408 AC |
36 | if $tracelevel { |
37 | strace $tracelevel | |
38 | } | |
39 | ||
40 | set prms_id 0 | |
41 | set bug_id 0 | |
42 | ||
43 | set testfile "sigbpt" | |
44 | set srcfile ${testfile}.c | |
45 | set binfile ${objdir}/${subdir}/${testfile} | |
46 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
b60f0898 JB |
47 | untested sigbpt.exp |
48 | return -1 | |
45a83408 AC |
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. | |
aacd552b TG |
86 | # Note: this test detects which signal is received. Usually it is SIGSEGV |
87 | # (and we use SIGSEGV in comments) but on Darwin it is SIGBUS. | |
45a83408 AC |
88 | |
89 | set bowler_addrs bowler | |
d12371a9 | 90 | set segv_addr none |
45a83408 AC |
91 | gdb_test {display/i $pc} |
92 | gdb_test "advance *bowler" "bowler.*" "advance to the bowler" | |
aacd552b TG |
93 | set test "stepping to fault" |
94 | set signame "SIGSEGV" | |
45a83408 | 95 | gdb_test_multiple "stepi" "$test" { |
2b28d209 | 96 | -re "Program received signal (SIGBUS|SIGSEGV).*pc(\r\n| *) *=> (0x\[0-9a-f\]*).*$gdb_prompt $" { |
aacd552b TG |
97 | set signame $expect_out(1,string) |
98 | set segv_addr $expect_out(3,string) | |
45a83408 AC |
99 | pass "$test" |
100 | } | |
2b28d209 | 101 | -re " .*pc(\r\n| *)=> (0x\[0-9a-f\]*).*bowler.*$gdb_prompt $" { |
6a2eb474 | 102 | set bowler_addrs [concat $expect_out(2,string) $bowler_addrs] |
45a83408 AC |
103 | send_gdb "stepi\n" |
104 | exp_continue | |
105 | } | |
106 | } | |
107 | ||
108 | # Now record the address of the instruction following the faulting | |
109 | # instruction in bowler_addrs. | |
110 | ||
111 | set test "get insn after fault" | |
112 | gdb_test_multiple {x/2i $pc} "$test" { | |
2b28d209 | 113 | -re "=> (0x\[0-9a-f\]*).*bowler.*(0x\[0-9a-f\]*).*bowler.*$gdb_prompt $" { |
45a83408 AC |
114 | set bowler_addrs [concat $expect_out(2,string) $bowler_addrs] |
115 | pass "$test" | |
116 | } | |
117 | } | |
118 | ||
119 | # Procedures for returning the address of the instruction before, at | |
120 | # and after, the faulting instruction. | |
121 | ||
122 | proc before_segv { } { | |
123 | global bowler_addrs | |
124 | return [lindex $bowler_addrs 2] | |
125 | } | |
126 | ||
127 | proc at_segv { } { | |
128 | global bowler_addrs | |
129 | return [lindex $bowler_addrs 1] | |
130 | } | |
131 | ||
132 | proc after_segv { } { | |
133 | global bowler_addrs | |
134 | return [lindex $bowler_addrs 0] | |
135 | } | |
136 | ||
137 | # Check that the address table and SIGSEGV correspond. | |
138 | ||
aacd552b | 139 | set test "Verify that ${signame} occurs at the last STEPI insn" |
45a83408 AC |
140 | if {[string compare $segv_addr [at_segv]] == 0} { |
141 | pass "$test" | |
142 | } else { | |
143 | fail "$test ($segv_addr [at_segv])" | |
144 | } | |
145 | ||
146 | # Check that the inferior is correctly single stepped all the way back | |
147 | # to a faulting instruction. | |
148 | ||
149 | proc stepi_out { name args } { | |
150 | global gdb_prompt | |
aacd552b | 151 | global signame |
45a83408 AC |
152 | |
153 | # Set SIGSEGV to pass+nostop and then run the inferior all the way | |
154 | # through to the signal handler. With the handler is reached, | |
155 | # disable SIGSEGV, ensuring that further signals stop the | |
156 | # inferior. Stops a SIGSEGV infinite loop when a broke system | |
157 | # keeps re-executing the faulting instruction. | |
158 | rerun_to_main | |
aacd552b | 159 | gdb_test "handle ${signame} nostop print pass" "" "${name}; pass ${signame}" |
1544280f | 160 | gdb_test "continue" "keeper.*" "${name}; continue to keeper" |
aacd552b | 161 | gdb_test "handle ${signame} stop print nopass" "" "${name}; nopass ${signame}" |
45a83408 AC |
162 | |
163 | # Insert all the breakpoints. To avoid the need to step over | |
164 | # these instructions, this is delayed until after the keeper has | |
165 | # been reached. | |
166 | for {set i 0} {$i < [llength $args]} {incr i} { | |
167 | gdb_test "break [lindex $args $i]" "Breakpoint.*" \ | |
1544280f | 168 | "${name}; set breakpoint $i of [llength $args]" |
45a83408 AC |
169 | } |
170 | ||
171 | # Single step our way out of the keeper, through the signal | |
172 | # trampoline, and back to the instruction that faulted. | |
1544280f | 173 | set test "${name}; stepi out of handler" |
45a83408 | 174 | gdb_test_multiple "stepi" "$test" { |
8608915f MK |
175 | -re "Could not insert single-step breakpoint.*$gdb_prompt $" { |
176 | setup_kfail "sparc*-*-openbsd*" gdb/1736 | |
177 | fail "$test (could not insert single-step breakpoint)" | |
178 | } | |
45a83408 AC |
179 | -re "keeper.*$gdb_prompt $" { |
180 | send_gdb "stepi\n" | |
181 | exp_continue | |
182 | } | |
183 | -re "signal handler.*$gdb_prompt $" { | |
184 | send_gdb "stepi\n" | |
185 | exp_continue | |
186 | } | |
187 | -re "Program received signal SIGSEGV.*$gdb_prompt $" { | |
188 | kfail gdb/1702 "$test (executed fault insn)" | |
189 | } | |
6a2eb474 | 190 | -re "Breakpoint.*pc(\r\n| *)[at_segv] .*bowler.*$gdb_prompt $" { |
45a83408 AC |
191 | pass "$test (at breakpoint)" |
192 | } | |
6a2eb474 | 193 | -re "Breakpoint.*pc(\r\n| *)[after_segv] .*bowler.*$gdb_prompt $" { |
45a83408 AC |
194 | kfail gdb/1702 "$test (executed breakpoint)" |
195 | } | |
6a2eb474 | 196 | -re "pc(\r\n| *)[at_segv] .*bowler.*$gdb_prompt $" { |
45a83408 AC |
197 | pass "$test" |
198 | } | |
6a2eb474 | 199 | -re "pc(\r\n| *)[after_segv] .*bowler.*$gdb_prompt $" { |
45a83408 AC |
200 | kfail gdb/1702 "$test (skipped fault insn)" |
201 | } | |
2b28d209 | 202 | -re "pc(\r\n| *)=> 0x\[a-z0-9\]* .*bowler.*$gdb_prompt $" { |
56401cd5 AC |
203 | kfail gdb/1702 "$test (corrupt pc)" |
204 | } | |
45a83408 AC |
205 | } |
206 | ||
207 | # Clear any breakpoints | |
208 | for {set i 0} {$i < [llength $args]} {incr i} { | |
209 | gdb_test "clear [lindex $args $i]" "Deleted .*" \ | |
1544280f | 210 | "${name}; clear breakpoint $i of [llength $args]" |
45a83408 AC |
211 | } |
212 | } | |
213 | ||
214 | # Let a signal handler exit, returning to a breakpoint instruction | |
215 | # inserted at the original fault instruction. Check that the | |
216 | # breakpoint is hit, and that single stepping off that breakpoint | |
217 | # executes the underlying fault instruction causing a SIGSEGV. | |
218 | ||
219 | proc cont_out { name args } { | |
220 | global gdb_prompt | |
aacd552b | 221 | global signame |
45a83408 AC |
222 | |
223 | # Set SIGSEGV to pass+nostop and then run the inferior all the way | |
224 | # through to the signal handler. With the handler is reached, | |
225 | # disable SIGSEGV, ensuring that further signals stop the | |
226 | # inferior. Stops a SIGSEGV infinite loop when a broke system | |
227 | # keeps re-executing the faulting instruction. | |
228 | rerun_to_main | |
aacd552b | 229 | gdb_test "handle ${signame} nostop print pass" "" "${name}; pass ${signame}" |
1544280f | 230 | gdb_test "continue" "keeper.*" "${name}; continue to keeper" |
aacd552b | 231 | gdb_test "handle ${signame} stop print nopass" "" "${name}; nopass ${signame}" |
45a83408 AC |
232 | |
233 | # Insert all the breakpoints. To avoid the need to step over | |
234 | # these instructions, this is delayed until after the keeper has | |
235 | # been reached. Always set a breakpoint at the signal trampoline | |
236 | # instruction. | |
237 | set args [concat $args "*[at_segv]"] | |
238 | for {set i 0} {$i < [llength $args]} {incr i} { | |
239 | gdb_test "break [lindex $args $i]" "Breakpoint.*" \ | |
1544280f | 240 | "${name}; set breakpoint $i of [llength $args]" |
45a83408 AC |
241 | } |
242 | ||
243 | # Let the handler return, it should "appear to hit" the breakpoint | |
244 | # inserted at the faulting instruction. Note that the breakpoint | |
245 | # instruction wasn't executed, rather the inferior was SIGTRAPed | |
246 | # with the PC at the breakpoint. | |
2b28d209 | 247 | gdb_test "continue" "Breakpoint.*pc(\r\n| *)=> [at_segv] .*" \ |
1544280f | 248 | "${name}; continue to breakpoint at fault" |
45a83408 AC |
249 | |
250 | # Now single step the faulted instrction at that breakpoint. | |
251 | gdb_test "stepi" \ | |
2b28d209 | 252 | "Program received signal ${signame}.*pc(\r\n| *)=> [at_segv] .*" \ |
1544280f | 253 | "${name}; stepi fault" |
45a83408 AC |
254 | |
255 | # Clear any breakpoints | |
256 | for {set i 0} {$i < [llength $args]} {incr i} { | |
257 | gdb_test "clear [lindex $args $i]" "Deleted .*" \ | |
1544280f | 258 | "${name}; clear breakpoint $i of [llength $args]" |
45a83408 AC |
259 | } |
260 | ||
261 | } | |
262 | ||
263 | ||
264 | ||
265 | # Try to confuse DECR_PC_AFTER_BREAK architectures by scattering | |
266 | # breakpoints around the faulting address. In all cases the inferior | |
267 | # should single-step out of the signal trampoline halting (but not | |
268 | # executing) the fault instruction. | |
269 | ||
270 | stepi_out "stepi" | |
271 | stepi_out "stepi bp before segv" "*[before_segv]" | |
272 | stepi_out "stepi bp at segv" "*[at_segv]" | |
273 | stepi_out "stepi bp before and at segv" "*[at_segv]" "*[before_segv]" | |
274 | ||
275 | ||
276 | # Try to confuse DECR_PC_AFTER_BREAK architectures by scattering | |
277 | # breakpoints around the faulting address. In all cases the inferior | |
278 | # should exit the signal trampoline halting at the breakpoint that | |
279 | # replaced the fault instruction. | |
280 | cont_out "cont" | |
281 | cont_out "cont bp after segv" "*[before_segv]" | |
282 | cont_out "cont bp before and after segv" "*[before_segv]" "*[after_segv]" |