Fix: Null pointer dereference in ldlex.l
[binutils-gdb.git] / gdb / testsuite / gdb.base / call-signal-resume.exp
bloba08ca7e1cc38bba2739aec3b53b62d4cd976073a
1 # Copyright 2008-2023 Free Software Foundation, Inc.
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.
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.
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/>.
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.
23 require {!target_info exists gdb,nosignals}
25 # Some targets can't do function calls, so don't even bother with this
26 # test.
27 require {!target_info exists gdb,cannot_call_functions}
30 standard_testfile call-signals.c
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
33 untested "failed to compile"
34 return -1
37 proc get_dummy_frame_number { } {
38 global gdb_prompt
40 gdb_test_multiple "bt" "backtrace" {
41 -re "#(\[0-9\]*) *<function called from gdb>.*$gdb_prompt $" {
42 return $expect_out(1,string)
45 return ""
48 # Start with a fresh gdb.
50 clean_restart ${binfile}
52 if { ![runto_main] } {
53 return 0
56 gdb_test "break stop_one" "Breakpoint \[0-9\]* at .*"
57 gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, stop_one.*" \
58 "continue to breakpoint at stop_one"
60 # Call function (causing the program to get a signal), and see if gdb handles
61 # it properly.
62 if {[gdb_test "call gen_signal ()" \
63 "\[\r\n\]*The program being debugged was signaled.*" \
64 "inferior function call signaled"] != 0} {
65 return 0
68 set frame_number [get_dummy_frame_number]
69 if { "$frame_number" == "" } {
70 fail "dummy stack frame number"
71 setup_xfail "*-*-*"
72 } else {
73 pass "dummy stack frame number"
76 # Pop the dummy frame.
77 gdb_test "frame $frame_number" ".*"
78 gdb_test_no_output "set confirm off"
79 gdb_test "return" ""
81 # Verify there are no remains of the dummy frame.
82 gdb_test_no_output "maintenance print dummy-frames"
83 set test "maintenance info breakpoints"
84 gdb_test_multiple $test $test {
85 -re " call dummy .*\r\n$gdb_prompt $" {
86 fail $test
88 -re "\r\n$gdb_prompt $" {
89 pass $test
93 # Resume execution, the program should continue without any signal.
95 gdb_test "break stop_two" "Breakpoint \[0-9\]* at .*"
96 gdb_test "continue" "Breakpoint \[0-9\]*, stop_two.*" \
97 "continue to breakpoint at stop_two"
99 # Continue again, we should get a signal.
101 gdb_test "continue" "Program received signal .*" \
102 "continue to receipt of signal"
104 # Hand call another function that prematurely stops,
105 # then manually pop the dummy stack frame.
107 gdb_test "break null_hand_call" "Breakpoint \[0-9\]* at .*"
108 gdb_test "call null_hand_call ()" "Breakpoint \[0-9\]*, null_hand_call.*" \
109 "null_hand_call"
111 set frame_number [get_dummy_frame_number]
112 if { "$frame_number" == "" } {
113 fail "dummy stack frame number, two"
114 setup_xfail "*-*-*"
115 # Need something.
116 set frame_number 0
117 } else {
118 pass "dummy stack frame number, two"
121 # Pop the dummy frame.
122 gdb_test "frame $frame_number" ".*"
123 gdb_test "return" "" "return, two"
125 # Continue again, this time we should get to the signal handler.
127 gdb_test "break handle_signal" "Breakpoint \[0-9\]* at .*"
128 gdb_test "continue" "Breakpoint \[0-9\]*, handle_signal.*" \
129 "continue to breakpoint at handle_signal"
131 # Continue one last time, the program should exit normally.
133 gdb_test "continue" "$inferior_exited_re normally." \
134 "continue to program exit"