From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/7] [gdb/testsuite] Fix gdb.server/multi-ui-errors.exp for remote target
Date: Thu, 9 Mar 2023 10:45:41 +0100 [thread overview]
Message-ID: <20230309094545.4537-3-tdevries@suse.de> (raw)
In-Reply-To: <20230309094545.4537-1-tdevries@suse.de>
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.
---
gdb/testsuite/gdb.server/multi-ui-errors.c | 5 ++++
gdb/testsuite/gdb.server/multi-ui-errors.exp | 29 +++++++++++++++++++
.../gdb.server/server-kill-python.exp | 23 ++++++++++++++-
3 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.server/multi-ui-errors.c b/gdb/testsuite/gdb.server/multi-ui-errors.c
index 09739198cc1..afa1815fbee 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 9cc5239d888..266207a5f4b 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 7b8f29b2890..f6b373065a8 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
--
2.35.3
next prev parent reply other threads:[~2023-03-09 9:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-09 9:45 [PATCH 1/7] [gdb/testsuite] Fix gdb.server/connect-with-no-symbol-file.exp " Tom de Vries
2023-03-09 9:45 ` [PATCH 2/7] [gdb/testsuite] Fix gdb.server/server-kill.exp " Tom de Vries
2023-03-09 9:45 ` Tom de Vries [this message]
2023-03-09 9:45 ` [PATCH 4/7] [gdb/testsuite] Fix gdb.server/sysroot.exp " Tom de Vries
2023-03-09 13:42 ` Tom de Vries
2023-03-09 9:45 ` [PATCH 5/7] [gdb/testsuite] Fix gdbserver path in remote-stdio-gdbserver.exp Tom de Vries
2023-03-09 9:45 ` [PATCH 6/7] [gdb/testsuite] Fix gdb.server/unittest.exp for remote target Tom de Vries
2023-03-09 9:45 ` [PATCH 7/7] [gdb/testsuite] Fix gdb.server/*.exp " Tom de Vries
2023-03-09 11:30 ` [PATCH 1/7] [gdb/testsuite] Fix gdb.server/connect-with-no-symbol-file.exp " Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230309094545.4537-3-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).