]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/exitsignal.exp
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / exitsignal.exp
1 # Copyright 2013-2024 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 # This test checks both $_exitcode and $_exitsignal variables. The
17 # purpose of this checking is to ensure that the variables are
18 # mutually exclusive, i.e., that when $_exitsignal is set, $_exitcode
19 # is not, and vice-versa. This mutual exclusion happens because if an
20 # inferior exited (either successfully or not), it certainly was not
21 # killed by a signal. However, if it was killed by an uncaught
22 # signal, then there is no way for it to have exited.
23
24 require {!target_info exists gdb,nosignals}
25
26 standard_testfile segv.c
27
28 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
29 return -1
30 }
31
32 # Run to main. But, before, change cwd to get the core into the
33 # output directory.
34 set_inferior_cwd_to_output_dir
35
36 if { ![runto_main] } {
37 return -1
38 }
39
40 # Get the inferior's PID for later.
41 set pid [get_inferior_pid]
42
43 # Print $_exitsignal. It should be void now, because nothing
44 # happened.
45 gdb_test "print \$_exitsignal" " = void" \
46 "\$_exitsignal is void before running"
47
48 # Just to guarantee, making sure that $_exitcode is also void.
49 gdb_test "print \$_exitcode" " = void" \
50 "\$_exitcode is void before running"
51
52 # Trigger SIGSEGV.
53 gdb_test "continue" "Program received signal SIGSEGV.*" "trigger SIGSEGV"
54
55 # Continue until the end.
56 gdb_test "continue" "Program terminated with signal SIGSEGV.*" \
57 "program terminated with SIGSEGV"
58
59 # We don't need the core file, remove it.
60 remove_core $pid
61
62 # Now, print $_exitsignal again. It should be 11 (SIGSEGV).
63 gdb_test "print \$_exitsignal" " = 11" \
64 "\$_exitsignal is 11 (SIGSEGV) after SIGSEGV."
65
66 # And $_exitcode should still be void, since the inferior died because
67 # of a signal, and did not return.
68 gdb_test "print \$_exitcode" " = void" \
69 "\$_exitcode is still void after SIGSEGV"
70
71 # Re-run to main, i.e., restart the executable.
72 rerun_to_main
73
74 # Print the $_exitsignal again. Even in this normal scenario, it
75 # should still contain the signal triggered in the other run.
76 gdb_test "print \$_exitsignal" " = 11" \
77 "\$_exitsignal is 11 (SIGSEGV) after restarting the inferior"
78
79 # And, again, print $_exitcode.
80 gdb_test "print \$_exitcode" " = void" \
81 "\$_exitcode is still void after restarting the inferior"
82
83 # Now we test the behaviour of $_exit{code,signal} during a normal
84 # inferior execution.
85 standard_testfile normal.c
86
87 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
88 return -1
89 }
90
91 # Checking $_exitsignal and $_exitcode, both should be void before the
92 # inferior is executed.
93 gdb_test "print \$_exitsignal" " = void" \
94 "\$_exitsignal is void before normal inferior is executed"
95 gdb_test "print \$_exitcode" " = void" \
96 "\$_exitcode is void before normal inferior is executed"
97
98 # Run the inferior until the end.
99 if { ![runto_main] } {
100 return -1
101 }
102
103 gdb_continue_to_end
104
105 # Checking $_exitcode. It should be 0.
106 gdb_test "print \$_exitcode" " = 0" \
107 "\$_exitcode is zero after normal inferior is executed"
108
109 # Checking $_exitsignal. It should still be void, since the inferior
110 # has not received any signal.
111 gdb_test "print \$_exitsignal" " = void" \
112 "\$_exitsignal is still void after normal inferior is executed"