xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.server/stop-reply-no-thread.exp (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
1# This testcase is part of GDB, the GNU debugger.
2#
3# Copyright 2018-2020 Free Software Foundation, Inc.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18# Test backward compatibility with older GDBservers which did not
19# include ";thread:NNN" in T stop replies when debugging
20# single-threaded programs, even though they'd list the main thread in
21# response to qfThreadInfo/qsThreadInfo.  See PR remote/22597.
22
23load_lib gdbserver-support.exp
24
25if { [skip_gdbserver_tests] } {
26    verbose "skipping gdbserver tests"
27    return -1
28}
29
30standard_testfile
31if [prepare_for_testing "failed to prepare" $testfile $srcfile] {
32    return -1
33}
34
35# Run the tests with different features of GDBserver disabled.
36proc run_test { disable_feature target_nonstop } {
37    global binfile gdb_prompt decimal
38
39    clean_restart ${binfile}
40
41    # Make sure we're disconnected, in case we're testing with an
42    # extended-remote board, therefore already connected.
43    gdb_test "disconnect" ".*"
44
45    set packet_arg ""
46    if { $disable_feature != "" } {
47	set packet_arg "--disable-packet=${disable_feature}"
48    }
49    set res [gdbserver_start $packet_arg $binfile]
50    set gdbserver_protocol [lindex $res 0]
51    set gdbserver_gdbport [lindex $res 1]
52
53    # Disable XML-based thread listing, and multi-process extensions.
54    gdb_test_no_output "set remote threads-packet off"
55    gdb_test_no_output "set remote multiprocess-feature-packet off"
56
57    # Set target-nonstop mode.
58    gdb_test_no_output "maint set target-non-stop ${target_nonstop}"
59
60    set res [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
61    if ![gdb_assert {$res == 0} "connect"] {
62	return
63    }
64
65    # There should be only one thread listed.
66    set test "info threads"
67    gdb_test_multiple $test $test {
68	-re "2 Thread.*$gdb_prompt $" {
69	    fail $test
70	}
71	-re "has terminated.*$gdb_prompt $" {
72	    fail $test
73	}
74	-re "\\\* 1\[\t \]*Thread\[^\r\n\]*\r\n$gdb_prompt $" {
75	    pass $test
76	}
77    }
78
79    gdb_breakpoint "main"
80
81    # Bad GDB behaved like this:
82    #  (gdb) c
83    #  Cannot execute this command without a live selected thread.
84    #  (gdb)
85    gdb_test "c" "Breakpoint $decimal, main.*" "continue to main"
86
87    # Continue until exit.  The server sends a 'W' with no PID.
88    # Bad GDB gave an error like below when target is nonstop:
89    #  (gdb) c
90    #  Continuing.
91    #  No process or thread specified in stop reply: W00
92    gdb_continue_to_end "" continue 1
93}
94
95# Disable different features within gdbserver:
96#
97# Tthread: Start GDBserver, with ";thread:NNN" in T stop replies disabled,
98#          emulating old gdbservers when debugging single-threaded programs.
99#
100# T: Start GDBserver with the entire 'T' stop reply packet disabled,
101#    GDBserver will instead send the 'S' stop reply.
102foreach_with_prefix to_disable { "" Tthread T } {
103    foreach_with_prefix t_nonstop { off on } {
104	run_test $to_disable $t_nonstop
105    }
106}
107