]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/exitsignal.exp
5e0ff1b1fe31b6228eae3be78d8dd1f472b1d655
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / exitsignal.exp
1 # Copyright 2013-2014 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 successfuly 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 if { [target_info exists gdb,nosignals] } {
25 verbose "Skipping exitsignal.exp because of nosignals."
26 continue
27 }
28
29 standard_testfile segv.c
30
31 if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
32 return -1
33 }
34
35 # Run to main
36 if { ![runto_main] } {
37 return -1
38 }
39
40 # Print $_exitsignal. It should be void now, because nothing
41 # happened.
42 gdb_test "print \$_exitsignal" " = void" \
43 "\$_exitsignal is void before running"
44
45 # Just to guarantee, making sure that $_exitcode is also void.
46 gdb_test "print \$_exitcode" " = void" \
47 "\$_exitcode is void before running"
48
49 # Trigger SIGSEGV.
50 gdb_test "continue" "Program received signal SIGSEGV.*" "trigger SIGSEGV"
51
52 # Continue until the end.
53 gdb_test "continue" "Program terminated with signal SIGSEGV.*" \
54 "program terminated with SIGSEGV"
55
56 # Now, print $_exitsignal again. It should be 11 (SIGSEGV).
57 gdb_test "print \$_exitsignal" " = 11" \
58 "\$_exitsignal is 11 (SIGSEGV) after SIGSEGV."
59
60 # And $_exitcode should still be void, since the inferior died because
61 # of a signal, and did not return.
62 gdb_test "print \$_exitcode" " = void" \
63 "\$_exitcode is still void after SIGSEGV"
64
65 # Re-run to main, i.e., restart the executable.
66 rerun_to_main
67
68 # Print the $_exitsignal again. Even in this normal scenario, it
69 # should still contain the signal triggered in the other run.
70 gdb_test "print \$_exitsignal" " = 11" \
71 "\$_exitsignal is 11 (SIGSEGV) after restarting the inferior"
72
73 # And, again, print $_exitcode.
74 gdb_test "print \$_exitcode" " = void" \
75 "\$_exitcode is still void after restarting the inferior"
76
77 # Now we test the behaviour of $_exit{code,signal} during a normal
78 # inferior execution.
79 standard_testfile normal.c
80
81 if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
82 return -1
83 }
84
85 # Checking $_exitsignal and $_exitcode, both should be void before the
86 # inferior is executed.
87 gdb_test "print \$_exitsignal" " = void" \
88 "\$_exitsignal is void before normal inferior is executed"
89 gdb_test "print \$_exitcode" " = void" \
90 "\$_exitcode is void before normal inferior is executed"
91
92 # Run the inferior until the end.
93 if { ![runto_main] } {
94 return -1
95 }
96
97 gdb_continue_to_end
98
99 # Checking $_exitcode. It should be 0.
100 gdb_test "print \$_exitcode" " = 0" \
101 "\$_exitcode is zero after normal inferior is executed"
102
103 # Checking $_exitsignal. It should still be void, since the inferior
104 # has not received any signal.
105 gdb_test "print \$_exitsignal" " = void" \
106 "\$_exitsignal is still void after normal inferior is executed"