Automatic Copyright Year update after running gdb/copyright.py
[binutils-gdb.git] / gdb / testsuite / gdb.server / stop-reply-no-thread.exp
blob488a5859961189e25801ec784a93e872487a5058
1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2018-2022 Free Software Foundation, Inc.
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.
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.
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/>.
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.
23 load_lib gdbserver-support.exp
25 if { [skip_gdbserver_tests] } {
26     verbose "skipping gdbserver tests"
27     return -1
30 standard_testfile
31 if { [build_executable "failed to prepare" $testfile $srcfile] == -1 } {
32     return -1
35 # Run the tests with different features of GDBserver disabled.
36 proc run_test { disable_feature target_nonstop } {
37     global binfile gdb_prompt decimal GDBFLAGS
39     save_vars { GDBFLAGS } {
40         # If GDB and GDBserver are both running locally, set the sysroot to avoid
41         # reading files via the remote protocol.
42         if { ![is_remote host] && ![is_remote target] } {
43             set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
44         }
46         clean_restart ${binfile}
47     }
49     # Make sure we're disconnected, in case we're testing with an
50     # extended-remote board, therefore already connected.
51     gdb_test "disconnect" ".*"
53     set packet_arg ""
54     if { $disable_feature != "" } {
55         set packet_arg "--disable-packet=${disable_feature}"
56     }
57     set res [gdbserver_start $packet_arg $binfile]
58     set gdbserver_protocol [lindex $res 0]
59     set gdbserver_gdbport [lindex $res 1]
61     # Disable XML-based thread listing, and multi-process extensions.
62     gdb_test_no_output "set remote threads-packet off"
63     gdb_test_no_output "set remote multiprocess-feature-packet off"
65     # Set target-nonstop mode.
66     gdb_test_no_output "maint set target-non-stop ${target_nonstop}"
68     set res [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
69     if ![gdb_assert {$res == 0} "connect"] {
70         return
71     }
73     # There should be only one thread listed.
74     set test "info threads"
75     gdb_test_multiple $test $test {
76         -re "2 Thread.*$gdb_prompt $" {
77             fail $test
78         }
79         -re "has terminated.*$gdb_prompt $" {
80             fail $test
81         }
82         -re "\\\* 1\[\t \]*Thread\[^\r\n\]*\r\n$gdb_prompt $" {
83             pass $test
84         }
85     }
87     gdb_breakpoint "main"
89     # Bad GDB behaved like this:
90     #  (gdb) c
91     #  Cannot execute this command without a live selected thread.
92     #  (gdb)
93     gdb_test "c" "Breakpoint $decimal, main.*" "continue to main"
95     # Continue until exit.  The server sends a 'W' with no PID.
96     # Bad GDB gave an error like below when target is nonstop:
97     #  (gdb) c
98     #  Continuing.
99     #  No process or thread specified in stop reply: W00
100     gdb_continue_to_end "" continue 1
103 # Disable different features within gdbserver:
105 # Tthread: Start GDBserver, with ";thread:NNN" in T stop replies disabled,
106 #          emulating old gdbservers when debugging single-threaded programs.
108 # T: Start GDBserver with the entire 'T' stop reply packet disabled,
109 #    GDBserver will instead send the 'S' stop reply.
110 foreach_with_prefix to_disable { "" Tthread T } {
111     foreach_with_prefix t_nonstop { off on } {
112         run_test $to_disable $t_nonstop
113     }
116 # Regression for PR gdb/26819: Cover the case when GDBserver does not report
117 # any threads (i.e. the remote target has no concept of threads).
119 # Scenario 1: Disable 'T' and 'qfThreadInfo' packets
120 # Scenario 2: Disable all threading packets
121 foreach_with_prefix to_disable { "T,qfThreadInfo" "threads" } {
122     # Non-stop mode not applicable - off.
123     run_test $to_disable off