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