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 multiple types of connection
(IPv4
, IPv6
, TCP
, UDP
) and make
19 # sure both gdbserver and GDB work.
21 load_lib gdbserver
-support.exp
23 standard_testfile
normal.c
25 if {[skip_gdbserver_tests
]} {
29 # We want to have control over where we start gdbserver.
30 if { [is_remote target
] } {
34 if { [prepare_for_testing
"failed to prepare" $testfile $srcfile debug] } {
38 # Make sure we
're disconnected, in case we're testing with an
39 # extended
-remote board
, therefore already connected.
40 gdb_test
"disconnect" ".*"
42 set target_exec
[gdbserver_download_current_prog
]
44 # An array containing the test instructions
for each scenario. The
45 # description of each field is as follows
:
47 #
- The connection specification to be used when starting
48 # gdbserver
/GDB. This string will be used to
set the
49 # GDB_TEST_SOCKETHOST when calling gdbserver_start.
51 #
- A flag indicating whether gdbserver should fail when we attempt to
52 # start it. Useful when testing erroneous connection specs such as
55 #
- The prefix that should be prepended to the test messages.
58 { "tcp4:127.0.0.1" 0 "tcp4" } \
59 { "tcp6:::1" 0 "tcp6" } \
60 { "tcp6:[::1]" 0 "tcp6-with-brackets" } \
61 { "tcp:localhost" 0 "tcp" } \
62 { "udp4:127.0.0.1" 0 "udp4" } \
63 { "udp6:::1" 0 "udp6" } \
64 { "udp6:[::1]" 0 "udp6-with-brackets" } \
65 { "tcp8:123" 1 "tcp8" } \
66 { "udp123:::" 1 "udp123" } \
67 { "garbage:1234" 1 "garbage:1234" } \
70 # The best way to test different types of connections is to
set the
71 # GDB_TEST_SOCKETHOST
variable accordingly.
72 save_vars
{ GDB_TEST_SOCKETHOST
} {
73 foreach line $test_params
{
74 set sockhost
[lindex $line
0]
75 set gdbserver_should_fail
[lindex $line
1]
76 set prefix
[lindex $line
2]
78 with_test_prefix $prefix
{
79 set GDB_TEST_SOCKETHOST $sockhost
80 set test
"start gdbserver"
82 # Try to start gdbserver.
83 set catchres
[catch
{set res
[gdbserver_start
"" $target_exec]} errmsg]
85 if { $catchres
!= 0 } {
86 if { $gdbserver_should_fail
} {
87 pass
"$test: gdbserver failed as expected"
93 if { $gdbserver_should_fail
} {
94 fail
"$test: gdbserver should fail but did not"
100 set gdbserver_protocol
[lindex $res
0]
101 set gdbserver_gdbport
[lindex $res
1]
102 set test
"connect to gdbserver using $sockhost"
104 set res
[gdb_target_cmd_ext $gdbserver_protocol $gdbserver_gdbport
]
107 } elseif
{ $res
== 1 } {