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