1 # Copyright 2015-2019 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 that GDB doesn't get badly wedged if the inferior is killed
17 # from outside GDB (with SIGKILL) while the program is stopped.
21 # Get the value of variable VAR in the inferior. MSG is used as the
24 proc get_value {var msg} {
30 gdb_test_multiple "print $var" "$msg" {
31 -re ".*= ($decimal).*\r\n$gdb_prompt $" {
32 set value $expect_out(1,string)
39 # Runs the program until a breakpoint, deletes all breakpoints, and
40 # then kills the inferior from _outside_ GDB, with SIGKILL. Runs CMDS
41 # afterwards, to make sure GDB copes with the inferior disappearing,
44 proc test {cmds_after_kill} {
49 clean_restart ${binfile}
55 # So that "continue" doesn't try a step over, etc.
58 set testpid [get_value "pid" "get pid of inferior"]
59 if { $testpid == -1 } {
63 remote_exec target "kill -9 ${testpid}"
65 # Give it some time to die.
68 uplevel 1 $cmds_after_kill
70 # Make sure we can quit.
72 gdb_test_multiple "quit" $msg {
73 -re "Quit anyway\\? \\(y or n\\) $" {
83 if {[prepare_for_testing "failed to prepare" $testfile $srcfile] == -1} {
87 # The actual output GDB prints in response to commands after the
88 # inferior is gone isn't very well defined, and will depend on target.
89 # What we're trying to make sure is that GDB doesn't internal error or
92 # Try simply continuing.
93 with_test_prefix "continue" {
95 # Try stepping the program. Stepping may need to read/write
96 # registers, unlike continue.
97 gdb_test "continue" ".*"
99 # Try listing threads afterwards. It's probably what the user
100 # will do after an error.
101 gdb_test "info threads" ".*"
105 # Try stepping the program. Stepping may go through diferent code
106 # paths in the target backends.
107 with_test_prefix "stepi" {
110 gdb_test "info threads" ".*"
114 # Try fetching registers explicitly, which should cover the error many
115 # other commands would trigger.
116 with_test_prefix "registers" {
118 gdb_test "flushregs" ".*"
119 gdb_test "info threads" ".*"
123 # Try only listing threads explicitly, first thing, which is another
124 # operation GDB may or not decide to do itself and is likely to be
125 # what a user would try after error too.
126 with_test_prefix "info threads" {
128 gdb_test "info threads" ".*"