Fix invoking "[kill|detach] inferiors" on inferiors that are not running
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / call-signal-resume.exp
1 # Copyright 2008-2015 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # Test inferior resumption after discarding a hand-called function.
17 # There are two things to test.
18 # 1) Inferior stops normally. Upon resumption it should continue normally,
19 # regardless of whatever signal the hand-called function got.
20 # 2) Inferior is stopped at a signal. Upon resumption it should continue
21 # with that signal, regardless of whatever the hand-called function did.
22
23 if [target_info exists gdb,nosignals] {
24 verbose "Skipping call-signal-resume.exp because of nosignals."
25 continue
26 }
27
28
29 standard_testfile call-signals.c
30
31 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
32 untested call-signal-resume.exp
33 return -1
34 }
35
36 # Some targets can't do function calls, so don't even bother with this
37 # test.
38 if [target_info exists gdb,cannot_call_functions] {
39 setup_xfail "*-*-*" 2416
40 fail "This target can not call functions"
41 continue
42 }
43
44 proc get_dummy_frame_number { } {
45 global gdb_prompt
46
47 gdb_test_multiple "bt" "backtrace" {
48 -re "#(\[0-9\]*) *<function called from gdb>.*$gdb_prompt $" {
49 return $expect_out(1,string)
50 }
51 }
52 return ""
53 }
54
55 # Start with a fresh gdb.
56
57 clean_restart ${binfile}
58
59 if { ![runto_main] } {
60 fail "Can't run to main"
61 return 0
62 }
63
64 gdb_test "break stop_one" "Breakpoint \[0-9\]* at .*"
65 gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, stop_one.*" \
66 "continue to breakpoint at stop_one"
67
68 # Call function (causing the program to get a signal), and see if gdb handles
69 # it properly.
70 if {[gdb_test "call gen_signal ()" \
71 "\[\r\n\]*The program being debugged was signaled.*" \
72 "inferior function call signaled"] != 0} {
73 return 0
74 }
75
76 set frame_number [get_dummy_frame_number]
77 if { "$frame_number" == "" } {
78 fail "dummy stack frame number"
79 setup_xfail "*-*-*"
80 } else {
81 pass "dummy stack frame number"
82 }
83
84 # Pop the dummy frame.
85 gdb_test "frame $frame_number" ".*"
86 gdb_test_no_output "set confirm off"
87 gdb_test "return" ""
88
89 # Verify there are no remains of the dummy frame.
90 gdb_test_no_output "maintenance print dummy-frames"
91 set test "maintenance info breakpoints"
92 gdb_test_multiple $test $test {
93 -re " call dummy .*\r\n$gdb_prompt $" {
94 fail $test
95 }
96 -re "\r\n$gdb_prompt $" {
97 pass $test
98 }
99 }
100
101 # Resume execution, the program should continue without any signal.
102
103 gdb_test "break stop_two" "Breakpoint \[0-9\]* at .*"
104 gdb_test "continue" "Breakpoint \[0-9\]*, stop_two.*" \
105 "continue to breakpoint at stop_two"
106
107 # Continue again, we should get a signal.
108
109 gdb_test "continue" "Program received signal .*" \
110 "continue to receipt of signal"
111
112 # Hand call another function that prematurely stops,
113 # then manually pop the dummy stack frame.
114
115 gdb_test "break null_hand_call" "Breakpoint \[0-9\]* at .*"
116 gdb_test "call null_hand_call ()" "Breakpoint \[0-9\]*, null_hand_call.*" \
117 "null_hand_call"
118
119 set frame_number [get_dummy_frame_number]
120 if { "$frame_number" == "" } {
121 fail "dummy stack frame number"
122 setup_xfail "*-*-*"
123 # Need something.
124 set frame_number 0
125 } else {
126 pass "dummy stack frame number"
127 }
128
129 # Pop the dummy frame.
130 gdb_test "frame $frame_number" ".*"
131 gdb_test_no_output "set confirm off"
132 gdb_test "return" ""
133
134 # Continue again, this time we should get to the signal handler.
135
136 gdb_test "break handle_signal" "Breakpoint \[0-9\]* at .*"
137 gdb_test "continue" "Breakpoint \[0-9\]*, handle_signal.*" \
138 "continue to breakpoint at handle_signal"
139
140 # Continue one last time, the program should exit normally.
141
142 gdb_test "continue" "$inferior_exited_re normally." \
143 "continue to program exit"
144
145 return 0
This page took 0.034492 seconds and 4 git commands to generate.