aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2023-03-09 10:45:03 +0100
committerTom de Vries <tdevries@suse.de>2023-03-09 10:45:03 +0100
commited32754a8c7919feffc6ddb66ff1c532e4a4d1cd (patch)
tree295f6255e8f1b5227507f3f8f886a800041c2e39
parent079f190d4cfc6aa9c934b00a9134bc0fcc172d53 (diff)
downloadbinutils-ed32754a8c7919feffc6ddb66ff1c532e4a4d1cd.zip
binutils-ed32754a8c7919feffc6ddb66ff1c532e4a4d1cd.tar.gz
binutils-ed32754a8c7919feffc6ddb66ff1c532e4a4d1cd.tar.bz2
[gdb/testsuite] Fix gdb.server/multi-ui-errors.exp for remote target
Test-case gdb.server/multi-ui-errors.exp fails for target board remote-gdbserver-on-localhost with REMOTE_TARGET_USERNAME=remote-target: ... (gdb) PASS: gdb.server/multi-ui-errors.exp: interact with GDB's main UI Executing on target: kill -9 6447 (timeout = 300) builtin_spawn [open ...]^M XYZ1ZYX sh: line 0: kill: (6447) - Operation not permitted ... The problem is that the kill command: ... remote_exec target "kill -9 $gdbserver_pid" ... intended to kill gdbserver instead tries to kill the ssh client session in which the gdbserver runs, and fails because it's trying as the remote target user (remote-target on localhost) to kill a pid owned by the the build user ($USER on localhost). Fix this by getting the gdbserver pid using the ppid trick from server-kill.exp. Likewise in gdb.server/server-kill-python.exp. Tested on x86_64-linux.
-rw-r--r--gdb/testsuite/gdb.server/multi-ui-errors.c5
-rw-r--r--gdb/testsuite/gdb.server/multi-ui-errors.exp29
-rw-r--r--gdb/testsuite/gdb.server/server-kill-python.exp23
3 files changed, 56 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.server/multi-ui-errors.c b/gdb/testsuite/gdb.server/multi-ui-errors.c
index 0973919..afa1815 100644
--- a/gdb/testsuite/gdb.server/multi-ui-errors.c
+++ b/gdb/testsuite/gdb.server/multi-ui-errors.c
@@ -17,12 +17,17 @@
#include <stdio.h>
#include <unistd.h>
+#include <sys/types.h>
+
+pid_t server_pid;
int
main (void)
{
int i;
+ server_pid = getppid ();
+
printf ("@@XX@@ Inferior Starting @@XX@@\n");
for (i = 0; i < 120; ++i)
diff --git a/gdb/testsuite/gdb.server/multi-ui-errors.exp b/gdb/testsuite/gdb.server/multi-ui-errors.exp
index 9cc5239..266207a 100644
--- a/gdb/testsuite/gdb.server/multi-ui-errors.exp
+++ b/gdb/testsuite/gdb.server/multi-ui-errors.exp
@@ -100,6 +100,35 @@ with_spawn_id $gdb_main_spawn_id {
gdb_test "echo hello\\n" "hello" "interact with GDB's main UI"
}
+# Get the gdbserver PID.
+set gdbserver_pid 0
+with_spawn_id $gdb_main_spawn_id {
+ gdb_test "interrupt"
+
+ gdb_test_multiple "" "interrupt arrived" {
+ -re "Program received signal SIGINT, Interrupt\\.\r\n" {
+ pass $gdb_test_name
+ }
+ }
+
+ gdb_test_multiple "p server_pid" "" {
+ -re -wrap " = ($decimal)" {
+ set gdbserver_pid $expect_out(1,string)
+ pass $gdb_test_name
+ }
+ }
+
+ gdb_test_multiple continue "" {
+ -re "Continuing\\.\r\n" {
+ pass $gdb_test_name
+ }
+ }
+}
+
+if { $gdbserver_pid == 0 } {
+ return
+}
+
# Now kill the gdbserver.
remote_exec target "kill -9 $gdbserver_pid"
diff --git a/gdb/testsuite/gdb.server/server-kill-python.exp b/gdb/testsuite/gdb.server/server-kill-python.exp
index 7b8f29b..f6b3730 100644
--- a/gdb/testsuite/gdb.server/server-kill-python.exp
+++ b/gdb/testsuite/gdb.server/server-kill-python.exp
@@ -30,12 +30,16 @@ if {[build_executable "failed to prepare" ${testfile} \
return -1
}
+set target_binfile [gdb_remote_download target $binfile]
+
# Start gdbserver.
-set res [gdbserver_spawn "${binfile}"]
+set res [gdbserver_spawn "${target_binfile}"]
set gdbserver_protocol [lindex $res 0]
set gdbserver_gdbport [lindex $res 1]
set gdbserver_pid [exp_pid -i $server_spawn_id]
+set break_linenr [gdb_get_line_number "@@XX@@ Inferior Starting @@XX@@"]
+
# Generate a python script we will later source.
set file1 [standard_output_file file1.py]
set fd [open "$file1" w]
@@ -44,6 +48,9 @@ puts $fd \
def do_gdb_stuff ():
gdb.execute ('target $gdbserver_protocol $gdbserver_gdbport')
+ gdb.execute ('break $srcfile:$break_linenr')
+ gdb.execute ('continue')
+ gdb.execute ('p server_pid')
gdb.execute ('continue')
do_gdb_stuff()"
@@ -57,8 +64,22 @@ if {[gdb_spawn_with_cmdline_opts \
return
}
+# Get the gdbserver PID.
+set gdbserver_pid 0
+
# Wait for the inferior to start up.
with_spawn_id $server_spawn_id {
+ gdb_test_multiple "" "get gdbserver PID" {
+ -re " = ($decimal)\r\n" {
+ set gdbserver_pid $expect_out(1,string)
+ pass $gdb_test_name
+ }
+ }
+
+ if { $gdbserver_pid == 0 } {
+ return
+ }
+
gdb_test_multiple "" "ensure inferior is running" {
-re "@@XX@@ Inferior Starting @@XX@@" {
pass $gdb_test_name