aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.server
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/testsuite/gdb.server')
-rw-r--r--gdb/testsuite/gdb.server/argument-errors.exp81
-rw-r--r--gdb/testsuite/gdb.server/bkpt-other-inferior.exp2
-rw-r--r--gdb/testsuite/gdb.server/connect-stopped-target.exp2
-rw-r--r--gdb/testsuite/gdb.server/connect-with-no-symbol-file.exp2
-rw-r--r--gdb/testsuite/gdb.server/connect-without-multi-process.exp2
-rw-r--r--gdb/testsuite/gdb.server/exit-multiple-threads.exp5
-rw-r--r--gdb/testsuite/gdb.server/ext-attach.exp2
-rw-r--r--gdb/testsuite/gdb.server/ext-run.exp2
-rw-r--r--gdb/testsuite/gdb.server/extended-remote-restart.exp4
-rw-r--r--gdb/testsuite/gdb.server/inferior-args.c27
-rw-r--r--gdb/testsuite/gdb.server/inferior-args.exp156
-rw-r--r--gdb/testsuite/gdb.server/monitor-exit-quit.exp4
-rw-r--r--gdb/testsuite/gdb.server/non-existing-program.exp4
-rw-r--r--gdb/testsuite/gdb.server/reconnect-ctrl-c.exp2
-rw-r--r--gdb/testsuite/gdb.server/server-exec-info.exp2
-rw-r--r--gdb/testsuite/gdb.server/server-kill.exp2
-rw-r--r--gdb/testsuite/gdb.server/server-pipe.exp2
-rw-r--r--gdb/testsuite/gdb.server/server-run.exp2
-rw-r--r--gdb/testsuite/gdb.server/stop-reply-no-thread-multi.exp4
-rw-r--r--gdb/testsuite/gdb.server/stop-reply-no-thread.exp4
20 files changed, 289 insertions, 22 deletions
diff --git a/gdb/testsuite/gdb.server/argument-errors.exp b/gdb/testsuite/gdb.server/argument-errors.exp
new file mode 100644
index 0000000..45037bf
--- /dev/null
+++ b/gdb/testsuite/gdb.server/argument-errors.exp
@@ -0,0 +1,81 @@
+# This testcase is part of GDB, the GNU debugger.
+#
+# Copyright 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test gdbserver prints a suitable message when argument values are
+# missing.
+
+load_lib gdbserver-support.exp
+
+standard_testfile
+
+require allow_gdbserver_tests
+
+set gdbserver [find_gdbserver]
+if { $gdbserver == "" } {
+ unsupported "could not find gdbserver"
+ return
+}
+
+# Start gdbserver using CMD_ARGS and a non-existent program name. We
+# expect to see an error message matching ERROR_RE from gdbserver.
+proc test_argument_error { cmd_args error_re } {
+ # Fire off gdbserver. gdbserver should give an error because
+ # --debug-file is missing its argument.
+ set spawn_id [remote_spawn target "$::gdbserver $cmd_args non-existing-program"]
+
+ set saw_expected_error false
+ set test "check gdbserver error: $cmd_args"
+ expect {
+ -i $spawn_id
+ -re $error_re {
+ set saw_expected_error true
+ exp_continue
+ }
+ eof {
+ gdb_assert $saw_expected_error $test
+ wait
+ }
+ timeout {
+ fail "$test (timeout)"
+ }
+ }
+
+ # expect defaults to spawn_id in many places. Avoid confusing any
+ # following code.
+ unset spawn_id
+}
+
+# Check that an argument that expects a value will not use a port, or
+# another argument, as its value.
+foreach arg { --debug-format --debug-file } {
+ test_argument_error "$arg stdio" \
+ "Missing argument value for: $arg"
+ test_argument_error "$arg :54321" \
+ "Missing argument value for: $arg"
+ test_argument_error "$arg -" \
+ "Missing argument value for: $arg"
+ test_argument_error "$arg --once -" \
+ "Missing argument value for: $arg"
+}
+
+# Test unknown argument handling.
+test_argument_error "--unknown -" \
+ "Unknown argument: --unknown"
+test_argument_error "-unknown -" \
+ "Unknown argument: -unknown"
+test_argument_error "--unknown=blah -" \
+ "Unknown argument: --unknown"
diff --git a/gdb/testsuite/gdb.server/bkpt-other-inferior.exp b/gdb/testsuite/gdb.server/bkpt-other-inferior.exp
index 893bd72..453be14 100644
--- a/gdb/testsuite/gdb.server/bkpt-other-inferior.exp
+++ b/gdb/testsuite/gdb.server/bkpt-other-inferior.exp
@@ -23,7 +23,7 @@ standard_testfile server.c
require allow_gdbserver_tests
-if { [prepare_for_testing "failed to prepare" ${binfile} "${srcfile}" \
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
{debug pthreads}] } {
return
}
diff --git a/gdb/testsuite/gdb.server/connect-stopped-target.exp b/gdb/testsuite/gdb.server/connect-stopped-target.exp
index 021f063..603782c 100644
--- a/gdb/testsuite/gdb.server/connect-stopped-target.exp
+++ b/gdb/testsuite/gdb.server/connect-stopped-target.exp
@@ -34,7 +34,7 @@ proc do_test {nonstop} {
global gdb_prompt
global hex
- clean_restart $binfile
+ clean_restart $::testfile
# Make sure we're disconnected, in case we're testing with an
# extended-remote board, therefore already connected.
diff --git a/gdb/testsuite/gdb.server/connect-with-no-symbol-file.exp b/gdb/testsuite/gdb.server/connect-with-no-symbol-file.exp
index 4e5ee98..01d7e46 100644
--- a/gdb/testsuite/gdb.server/connect-with-no-symbol-file.exp
+++ b/gdb/testsuite/gdb.server/connect-with-no-symbol-file.exp
@@ -69,7 +69,7 @@ proc connect_no_symbol_file { sysroot action } {
} elseif { $action == "permission" } {
remote_exec target "chmod 000 $target_exec"
}
-
+
# Connect to GDBserver.
gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport
}
diff --git a/gdb/testsuite/gdb.server/connect-without-multi-process.exp b/gdb/testsuite/gdb.server/connect-without-multi-process.exp
index 1a7246c..f47e57e 100644
--- a/gdb/testsuite/gdb.server/connect-without-multi-process.exp
+++ b/gdb/testsuite/gdb.server/connect-without-multi-process.exp
@@ -38,7 +38,7 @@ proc do_test {multiprocess} {
set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
}
- clean_restart $binfile
+ clean_restart $::testfile
}
# Make sure we're disconnected, in case we're testing with an
diff --git a/gdb/testsuite/gdb.server/exit-multiple-threads.exp b/gdb/testsuite/gdb.server/exit-multiple-threads.exp
index 73e4c32..be29f9e 100644
--- a/gdb/testsuite/gdb.server/exit-multiple-threads.exp
+++ b/gdb/testsuite/gdb.server/exit-multiple-threads.exp
@@ -45,7 +45,8 @@ proc prepare_for_test { executable target_executable disable_multi_process } {
set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
}
- clean_restart ${executable}
+ clean_restart
+ gdb_load $executable
}
# Make sure we're disconnected, in case we're testing with an
@@ -69,7 +70,7 @@ proc prepare_for_test { executable target_executable disable_multi_process } {
set gdbserver_protocol [lindex $res 0]
set gdbserver_gdbport [lindex $res 1]
set res [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
- if ![gdb_assert {$res == 0} "connect"] {
+ if { ![gdb_assert {$res == 0} "connect"] } {
return
}
diff --git a/gdb/testsuite/gdb.server/ext-attach.exp b/gdb/testsuite/gdb.server/ext-attach.exp
index bda3ae9..6af2ede 100644
--- a/gdb/testsuite/gdb.server/ext-attach.exp
+++ b/gdb/testsuite/gdb.server/ext-attach.exp
@@ -45,7 +45,7 @@ proc run_test { target_async target_non_stop to_disable } {
set ::GDBFLAGS "$::GDBFLAGS -ex \"set sysroot\""
}
- clean_restart $::binfile
+ clean_restart $::testfile
}
# Make sure we're disconnected, in case we're testing with an
diff --git a/gdb/testsuite/gdb.server/ext-run.exp b/gdb/testsuite/gdb.server/ext-run.exp
index 2286454..f4ff546 100644
--- a/gdb/testsuite/gdb.server/ext-run.exp
+++ b/gdb/testsuite/gdb.server/ext-run.exp
@@ -37,7 +37,7 @@ save_vars { GDBFLAGS } {
set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
}
- clean_restart $binfile
+ clean_restart $::testfile
}
# Make sure we're disconnected, in case we're testing with an
diff --git a/gdb/testsuite/gdb.server/extended-remote-restart.exp b/gdb/testsuite/gdb.server/extended-remote-restart.exp
index df722a1..a5ba53c 100644
--- a/gdb/testsuite/gdb.server/extended-remote-restart.exp
+++ b/gdb/testsuite/gdb.server/extended-remote-restart.exp
@@ -58,7 +58,7 @@ proc test_reload { do_kill_p follow_child_p } {
global decimal
global binfile
- clean_restart ${binfile}
+ clean_restart ${::testfile}
if {![runto_main]} {
return 0
@@ -70,7 +70,7 @@ proc test_reload { do_kill_p follow_child_p } {
set live_inf_ptn "process $decimal"
set dead_inf_ptn "<null>"
- if ${follow_child_p} {
+ if { $follow_child_p } {
gdb_test_no_output "set follow-fork child"
set parent_prefix " "
set child_prefix "\\*"
diff --git a/gdb/testsuite/gdb.server/inferior-args.c b/gdb/testsuite/gdb.server/inferior-args.c
new file mode 100644
index 0000000..3bc3ff7
--- /dev/null
+++ b/gdb/testsuite/gdb.server/inferior-args.c
@@ -0,0 +1,27 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2023-2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+
+int
+main (int argc, char **argv)
+{
+ for (int i = 0; i < argc; i++)
+ printf ("[%d] %s\n", i, argv[i]);
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.server/inferior-args.exp b/gdb/testsuite/gdb.server/inferior-args.exp
new file mode 100644
index 0000000..18ac5a3
--- /dev/null
+++ b/gdb/testsuite/gdb.server/inferior-args.exp
@@ -0,0 +1,156 @@
+# Copyright 2023-2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test passing inferior arguments on the gdbserver command line. Tests the
+# flags --no-startup-with-shell and --no-escape-args that change how GDB
+# interprets the arguments being passed.
+
+# This test relies on starting gdbserver using the pipe syntax. Not sure
+# how well this will run if part of this test is being run elsewhere.
+require {!is_remote target} {!is_remote host}
+
+load_lib gdbserver-support.exp
+
+standard_testfile
+
+require allow_gdbserver_tests
+
+set gdbserver [find_gdbserver]
+if { $gdbserver == "" } {
+ unsupported "could not find gdbserver"
+ return
+}
+
+standard_testfile
+if {[build_executable "failed to prepare" $testfile $srcfile]} {
+ return -1
+}
+
+# EXTENDED_P is a boolean, when true gdbserver is started with --multi, and
+# GDB connects using extended-remote protocol. Otherwise, no --multi flag
+# is passed, and GDB connects with the remote protocol.
+#
+# WITH_SHELL_P is a boolean, when true gdbserver starts the inferior using a
+# shell, when false gdbserver is passed the --no-startup-with-shell command
+# line option, and should not start the inferior through a shell.
+#
+# ESCAPE_P is a boolean, when true gdbserver applies escapes to the inferior
+# arguments, when false gdbserver is passed the --no-escape-args command
+# line option, and should not apply escaping to the inferior arguments.
+#
+# ARGLIST is a list of inferior arguments to add to the gdbserver command
+# line.
+#
+# RE_LIST is a list of patterns to match, one for each of ARGLIST. Once the
+# inferior is started we check that each argument matches its corresponding
+# entry in RE_LIST.
+proc do_test_inner { extended_p with_shell_p escape_p arglist re_list } {
+
+ clean_restart ${::testfile}
+
+ gdb_test_no_output "set sysroot"
+
+ # Make sure we're disconnected, in case we're testing with an
+ # extended-remote board, therefore already connected.
+ gdb_test "disconnect" ".*"
+
+ if { $extended_p } {
+ set protocol "extended-remote"
+ } else {
+ set protocol "remote"
+ }
+
+ if { $escape_p } {
+ set esc_opt ""
+ } else {
+ set esc_opt "--no-escape-args"
+ }
+
+ if { $with_shell_p } {
+ set shell_opt ""
+ } else {
+ set shell_opt "--no-startup-with-shell"
+ }
+
+ gdb_test "target ${protocol} | ${::gdbserver} --once ${esc_opt} ${shell_opt} - ${::binfile} ${arglist}" \
+ ".*" \
+ "start gdbserver over stdin"
+
+ gdb_breakpoint main
+ gdb_continue_to_breakpoint main
+
+ set expected_len [expr {1 + [llength $re_list]}]
+ gdb_test "print argc" \
+ "\\\$$::decimal = $expected_len" "check argc"
+
+ set i 1
+ foreach arg $re_list {
+ gdb_test "print argv\[$i\]" \
+ "\\\$$::decimal = $::hex \"$arg\"" \
+ "check argv\[$i\]"
+ incr i
+ }
+}
+
+# Wrapper around do_test_inner. NAME is the name of this test, used to make
+# the test names unique. ARGLIST is the list of inferior arguments to add
+# to the gdbserver command line.
+#
+# The optional RE_ESC_LIST is a list of patterns to match against the
+# inferior arguments once the inferior is started, one pattern for each
+# argument. If RE_ESC_LIST is not given then ARGLIST is reused, which
+# implies the arguments appear unmodified in the test output.
+#
+# The optional RE_NO_ESC_LIST is a list of patterns to match against the
+# inferior arguments when gdbserver is started with --no-escape-args or
+# --no-startup-with-shell. There should be one pattern for each argument.
+# If RE_NO_ESC_LIST is not given then RE_ESC_LIST is reused, which implies
+# there's no difference in how the arguments are printed.
+proc args_test { name arglist {re_esc_list {}} {re_no_esc_list {}} } {
+ if {[llength $re_esc_list] == 0} {
+ set re_esc_list $arglist
+ }
+
+ if {[llength $re_no_esc_list] == 0} {
+ set re_no_esc_list $re_esc_list
+ }
+
+ foreach_with_prefix extended_p { yes no } {
+ foreach_with_prefix startup_with_shell { on off } {
+ foreach_with_prefix escape_p { yes no } {
+ if { $escape_p || !$startup_with_shell } {
+ set re_list $re_esc_list
+ } else {
+ set re_list $re_no_esc_list
+ }
+
+ with_test_prefix "$name" {
+ do_test_inner $extended_p $startup_with_shell \
+ $escape_p $arglist $re_list
+ }
+ }
+ }
+ }
+}
+
+args_test "basic" {a b c}
+args_test "one empty" {1 "" 3}
+args_test "two empty" {1 "" "" 3}
+args_test "one with single quotes" {1 "''" 3}
+args_test "lone double quote" {"1" \" 3} {1 \\\\\" 3}
+save_vars { env(TEST) } {
+ set env(TEST) "ABCD"
+ args_test "shell variable" {\$TEST} {\\$TEST} {ABCD}
+}
diff --git a/gdb/testsuite/gdb.server/monitor-exit-quit.exp b/gdb/testsuite/gdb.server/monitor-exit-quit.exp
index ce63560..74842a0 100644
--- a/gdb/testsuite/gdb.server/monitor-exit-quit.exp
+++ b/gdb/testsuite/gdb.server/monitor-exit-quit.exp
@@ -34,7 +34,7 @@ save_vars { GDBFLAGS } {
set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
}
- clean_restart $binfile
+ clean_restart $::testfile
}
# Make sure we're disconnected, in case we're testing with an
@@ -70,7 +70,7 @@ gdb_test_multiple "quit" "" {
# Cleanup, as in default_gdb_exit.
if { $do_cleanup } {
- if ![is_remote host] {
+ if { ![is_remote host] } {
remote_close host
}
unset gdb_spawn_id
diff --git a/gdb/testsuite/gdb.server/non-existing-program.exp b/gdb/testsuite/gdb.server/non-existing-program.exp
index 7119723..ec9c044 100644
--- a/gdb/testsuite/gdb.server/non-existing-program.exp
+++ b/gdb/testsuite/gdb.server/non-existing-program.exp
@@ -34,6 +34,8 @@ if { $gdbserver == "" } {
# to spawn the program before opening the connection.
set spawn_id [remote_spawn target "$gdbserver stdio non-existing-program"]
+set eol {[\r\n]}
+
set msg "gdbserver exits cleanly"
set saw_exiting 0
expect {
@@ -51,7 +53,7 @@ expect {
exp_continue
}
# This is what we get on Windows.
- -re "Error creating process\r\n\r\nExiting\r\n" {
+ -re "Error creating process.*$eol+Exiting$eol+" {
set saw_exiting 1
exp_continue
}
diff --git a/gdb/testsuite/gdb.server/reconnect-ctrl-c.exp b/gdb/testsuite/gdb.server/reconnect-ctrl-c.exp
index 83869a3..bcab2de 100644
--- a/gdb/testsuite/gdb.server/reconnect-ctrl-c.exp
+++ b/gdb/testsuite/gdb.server/reconnect-ctrl-c.exp
@@ -51,7 +51,7 @@ proc connect_continue_ctrl_c {} {
global gdbserver_protocol gdbserver_gdbport
set res [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
- if ![gdb_assert {$res == 0} "connect"] {
+ if { ![gdb_assert {$res == 0} "connect"] } {
return
}
diff --git a/gdb/testsuite/gdb.server/server-exec-info.exp b/gdb/testsuite/gdb.server/server-exec-info.exp
index fccf075..007290a 100644
--- a/gdb/testsuite/gdb.server/server-exec-info.exp
+++ b/gdb/testsuite/gdb.server/server-exec-info.exp
@@ -21,7 +21,7 @@ load_lib gdbserver-support.exp
require allow_gdbserver_tests allow_shlib_tests
standard_testfile server.c
-if [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] {
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
return -1
}
diff --git a/gdb/testsuite/gdb.server/server-kill.exp b/gdb/testsuite/gdb.server/server-kill.exp
index 0a759ae..a9fcabb 100644
--- a/gdb/testsuite/gdb.server/server-kill.exp
+++ b/gdb/testsuite/gdb.server/server-kill.exp
@@ -43,7 +43,7 @@ proc prepare {} {
set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
}
- clean_restart $binfile
+ clean_restart $::testfile
}
# Make sure we're disconnected, in case we're testing with an
diff --git a/gdb/testsuite/gdb.server/server-pipe.exp b/gdb/testsuite/gdb.server/server-pipe.exp
index d786946..20ca0b0 100644
--- a/gdb/testsuite/gdb.server/server-pipe.exp
+++ b/gdb/testsuite/gdb.server/server-pipe.exp
@@ -50,7 +50,7 @@ if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
# the contents of the gdb.TargetConnection.details string.
proc do_test { target } {
global timeout
- clean_restart ${::binfile}
+ clean_restart ${::testfile}
# Make sure we're disconnected, in case we're testing with an
# extended-remote board, therefore already connected.
diff --git a/gdb/testsuite/gdb.server/server-run.exp b/gdb/testsuite/gdb.server/server-run.exp
index 6c9db98..53b3278 100644
--- a/gdb/testsuite/gdb.server/server-run.exp
+++ b/gdb/testsuite/gdb.server/server-run.exp
@@ -34,7 +34,7 @@ save_vars { GDBFLAGS } {
set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
}
- clean_restart $binfile
+ clean_restart $::testfile
}
# Make sure we're disconnected, in case we're testing with an
diff --git a/gdb/testsuite/gdb.server/stop-reply-no-thread-multi.exp b/gdb/testsuite/gdb.server/stop-reply-no-thread-multi.exp
index 42608c4..f1c68a5 100644
--- a/gdb/testsuite/gdb.server/stop-reply-no-thread-multi.exp
+++ b/gdb/testsuite/gdb.server/stop-reply-no-thread-multi.exp
@@ -54,7 +54,7 @@ proc run_test { target_non_stop disable_feature } {
set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
}
- clean_restart ${binfile}
+ clean_restart ${::testfile}
}
# Make sure we're disconnected, in case we're testing with an
@@ -78,7 +78,7 @@ proc run_test { target_non_stop disable_feature } {
"Support for the 'multiprocess-feature' packet on future remote targets is set to \"off\"."
set res [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
- if ![gdb_assert {$res == 0} "connect"] {
+ if { ![gdb_assert {$res == 0} "connect"] } {
return
}
diff --git a/gdb/testsuite/gdb.server/stop-reply-no-thread.exp b/gdb/testsuite/gdb.server/stop-reply-no-thread.exp
index 38402e8..aa77095 100644
--- a/gdb/testsuite/gdb.server/stop-reply-no-thread.exp
+++ b/gdb/testsuite/gdb.server/stop-reply-no-thread.exp
@@ -42,7 +42,7 @@ proc run_test { disable_feature target_nonstop } {
set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
}
- clean_restart ${binfile}
+ clean_restart ${::testfile}
}
# Make sure we're disconnected, in case we're testing with an
@@ -70,7 +70,7 @@ proc run_test { disable_feature target_nonstop } {
gdb_test_no_output "maint set target-non-stop ${target_nonstop}"
set res [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
- if ![gdb_assert {$res == 0} "connect"] {
+ if { ![gdb_assert {$res == 0} "connect"] } {
return
}