]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/bt-on-fatal-signal.exp
gdb/testsuite: remove use of then keyword from gdb.base/*.exp
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / bt-on-fatal-signal.exp
CommitLineData
4a94e368 1# Copyright 2021-2022 Free Software Foundation, Inc.
6aa4f97c
AB
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 the 'maint set backtrace-on-fatal-signal' behaviour. Start up
17# GDB, turn on backtrace-on-fatal-signal, then send fatal signals to
18# GDB and ensure we see the backtrace.
19
20standard_testfile
21
22# The logic for sending signals to GDB might now work when using a
23# remote host (will the signal go to GDB, or the program that
24# established the connection to the remote host?), so just skip this
25# test for remote host setups.
26if {[is_remote host]} {
27 untested $testfile
28 return -1
29}
30
31if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} {
32 return -1
33}
34
35# Check we can run to main. If this works this time then we just
36# assume that it will work later on (when we repeatedly restart GDB).
65a33d75 37if {![runto_main]} {
6aa4f97c
AB
38 return -1
39}
40
41# Check that the backtrace-on-fatal-signal feature is supported. If
42# this target doesn't have the backtrace function available then
43# trying to turn this on will give an error, in which case we just
44# skip this test.
45gdb_test_multiple "maint set backtrace-on-fatal-signal on" "" {
46 -re "support for this feature is not compiled into GDB" {
47 untested $testfile
48 return -1
49 }
50 -re "$gdb_prompt $" {
51 pass $gdb_test_name
52 }
53}
54
55# Now the actual test loop.
d03277b7
AB
56foreach test_data {{SEGV "Segmentation fault"} \
57 {FPE "Floating point exception"} \
58 {BUS "Bus error"} \
59 {ABRT "Aborted"}} {
6aa4f97c
AB
60 set sig [lindex ${test_data} 0]
61 set msg [lindex ${test_data} 1]
62 with_test_prefix ${sig} {
63
64 # Restart GDB.
7a0daa48
TV
65 save_vars { GDB } {
66 set GDB [gdb_no_core]
67 clean_restart $binfile
68 }
6aa4f97c
AB
69
70 # Capture the pid of GDB.
71 set testpid [spawn_id_get_pid $gdb_spawn_id]
72
73 # Start the inferior.
74 runto_main
75
76 # Turn on the backtrace-on-fatal-signal feature.
77 gdb_test_no_output "maint set backtrace-on-fatal-signal on"
78
79 # Flags for various bits of the output we expect to see, we
80 # check for these in the gdb_test_multiple below.
81 set saw_fatal_msg false
82 set saw_bt_start false
83 set saw_bt_end false
84 set internal_error_msg_count 0
85
23948f56
PA
86 # Get the GDB core into the output directory, so that it
87 # doesn't count as unexpected core in gdb.sum.
88 gdb_test "cd [file dirname $binfile]" "Working directory .*" \
89 "cd to test directory"
90
6aa4f97c
AB
91 # Send the fatal signal to GDB.
92 remote_exec host "kill -${sig} ${testpid}"
93
94 # Scan GDB's output for the backtrace. As the output we get
95 # here includes the standard "internal error" message, which
96 # gdb_test_multiple will usually handle, we are forced to make
97 # extensive use of the "-early" flag here so that all our
98 # patterns are applied before gdb_test_multiple can check for
99 # the internal error pattern.
100 gdb_test_multiple "" "scan for backtrace" {
101 -early -re "^\r\n" {
102 exp_continue
103 }
104 -early -re "^Fatal signal: ${msg}\r\n" {
105 set saw_fatal_msg true
106 exp_continue
107 }
108 -early -re "^----- Backtrace -----\r\n" {
109 set saw_bt_start true
110 exp_continue
111 }
112 -early -re ".+\r\n---------------------\r\n" {
113 set saw_bt_end true
114 exp_continue
115 }
116 -early -re "^A fatal error internal to GDB has been detected, further\r\n" {
117 incr internal_error_msg_count
118 exp_continue
119 }
120 -early -re "^debugging is not possible. GDB will now terminate\\.\r\n" {
121 incr internal_error_msg_count
122 exp_continue
123 }
124 eof {
125 # Catch the eof case as this indicates that GDB has
126 # gone away, which in this case, is what we expect to
127 # happen.
128 gdb_assert { $saw_fatal_msg }
129 gdb_assert { $saw_bt_start }
130 gdb_assert { $saw_bt_end }
131 gdb_assert { [expr $internal_error_msg_count == 2] }
132 }
133 -re "$gdb_prompt $" {
134 # GDB should terminate, we should never get back to
135 # the prompt.
136 fail $gdb_test_name
137 }
138 }
139
140 # GDB should be dead and gone by this point, but just to be
141 # sure, force an exit.
142 gdb_exit
143 }
144}