1 # This testcase is part of GDB
, the GNU debugger.
3 # Copyright
2018-2024 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 require allow_gdbserver_tests
28 if { [build_executable "failed to prepare" $testfile $srcfile] == -1 } {
32 set target_binfile [gdb_remote_download target $binfile]
34 # Run the tests with different features of GDBserver disabled.
35 proc run_test { disable_feature target_nonstop } {
36 global binfile gdb_prompt decimal GDBFLAGS
38 save_vars { GDBFLAGS } {
39 # If GDB and GDBserver are both running locally, set the sysroot to avoid
40 # reading files via the remote protocol.
41 if { ![is_remote host] && ![is_remote target] } {
42 set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
45 clean_restart ${binfile}
48 # Make sure we're disconnected
, in case we
're testing with an
49 # extended-remote board, therefore already connected.
50 gdb_test "disconnect" ".*"
53 if { $disable_feature != "" } {
54 set packet_arg "--disable-packet=${disable_feature}"
56 set res [gdbserver_start $packet_arg $::target_binfile]
57 set gdbserver_protocol [lindex $res 0]
58 set gdbserver_gdbport [lindex $res 1]
60 # Disable XML-based thread listing, and multi-process extensions.
62 "set remote threads-packet off" \
63 "Support for the 'qXfer
:threads
:read
' packet on future remote targets is set to \"off\"."
66 "set remote multiprocess-feature-packet off" \
67 "Support for the 'multiprocess
-feature
' packet on future remote targets is set to \"off\"."
69 # Set target-nonstop mode.
70 gdb_test_no_output "maint set target-non-stop ${target_nonstop}"
72 set res [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
73 if ![gdb_assert {$res == 0} "connect"] {
77 # There should be only one thread listed.
78 set test "info threads"
79 gdb_test_multiple $test $test {
80 -re "2 Thread.*$gdb_prompt $" {
83 -re "has terminated.*$gdb_prompt $" {
86 -re "\\\* 1\[\t \]*Thread\[^\r\n\]*\r\n$gdb_prompt $" {
93 # Bad GDB behaved like this:
95 # Cannot execute this command without a live selected thread.
97 gdb_test "c" "Breakpoint $decimal, main.*" "continue to main"
99 # Continue until exit. The server sends a 'W
' with no PID.
100 # Bad GDB gave an error like below when target is nonstop:
103 # No process or thread specified in stop reply: W00
104 gdb_continue_to_end "" continue 1
107 # Disable different features within gdbserver:
109 # Tthread: Start GDBserver, with ";thread:NNN" in T stop replies disabled,
110 # emulating old gdbservers when debugging single-threaded programs.
112 # T: Start GDBserver with the entire 'T
' stop reply packet disabled,
113 # GDBserver will instead send the 'S
' stop reply.
114 foreach_with_prefix to_disable { "" Tthread T } {
115 foreach_with_prefix t_nonstop { off on } {
116 run_test $to_disable $t_nonstop
120 # Regression for PR gdb/26819: Cover the case when GDBserver does not report
121 # any threads (i.e. the remote target has no concept of threads).
123 # Scenario 1: Disable 'T
' and 'qfThreadInfo
' packets
124 # Scenario 2: Disable all threading packets
125 foreach_with_prefix to_disable { "T,qfThreadInfo" "threads" } {
126 # Non-stop mode not applicable - off.
127 run_test $to_disable off