aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.server/server-kill-python.exp
blob: 4ef70daaf90306a22324f4e71416ed4f4c4eb5aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# This testcase is part of GDB, the GNU debugger.
#
# Copyright 2019-2023 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This test script exposes a bug where, if gdbserver dies while GDB is
# sourcing a python command like 'gdb.execute ("continue")', then GDB
# will deadlock.

load_lib gdbserver-support.exp

standard_testfile multi-ui-errors.c

require !skip_gdbserver_tests !skip_python_tests

if {[build_executable "failed to prepare" ${testfile} \
	 ${srcfile}] == -1} {
    return -1
}

# Start gdbserver.
set res [gdbserver_spawn "${binfile}"]
set gdbserver_protocol [lindex $res 0]
set gdbserver_gdbport [lindex $res 1]
set gdbserver_pid [exp_pid -i $server_spawn_id]

# Generate a python script we will later source.
set file1 [standard_output_file file1.py]
set fd [open "$file1" w]
puts $fd \
"import gdb

def do_gdb_stuff ():
    gdb.execute ('target $gdbserver_protocol $gdbserver_gdbport')
    gdb.execute ('continue')

do_gdb_stuff()"
close $fd

# Now start GDB, sourcing the python command file we generated above.
# Set the height and width so we don't end up at a paging prompt.
if {[gdb_spawn_with_cmdline_opts \
	 "-quiet -iex \"set height 0\" -iex \"set width 0\" -ex \"source $file1\""] != 0} {
    fail "spawn"
    return
}

# Wait for the inferior to start up.
with_spawn_id $server_spawn_id {
    gdb_test_multiple "" "ensure inferior is running" {
	-re "@@XX@@ Inferior Starting @@XX@@" {
	    pass $gdb_test_name
	}
	timeout {
	    fail $gdb_test_name
	}
    }
}

# Now kill the gdbserver.
remote_exec target "kill -9 $gdbserver_pid"

# Wait for GDB to return to a prompt.
gdb_test_multiple "" "landed at prompt after gdbserver dies" {
    -re "$gdb_prompt $" {
	pass $gdb_test_name
    }
    timeout {
	fail "$gdb_test_name (timeout)"
    }
}

# Run a simple command to ensure we can interact with GDB.
gdb_test "echo hello\\n" "hello" "can we interact with gdb"