public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/2] [gdb/testsuite] Fix gdbserver pid in gdb.server/server-kill-python.exp
Date: Fri, 12 Apr 2024 19:51:01 +0200	[thread overview]
Message-ID: <20240412175101.9154-2-tdevries@suse.de> (raw)
In-Reply-To: <20240412175101.9154-1-tdevries@suse.de>

The commit ed32754a8c7 ("[gdb/testsuite] Fix gdb.server/multi-ui-errors.exp for
remote target") intended to addresss the problem that this command:
...
set gdbserver_pid [exp_pid -i $server_spawn_id]
...
does not return the pid of the gdbserver for remote target, but rather the one
of the ssh client session.

To fix this, it added another way of getting the gdbserver_pid.

For the trivial case of non-remote target, the PID found by either method
should be identical, but if we compare those by adding
"puts [exec ps -p $gdbserver_pid]" we get:
...
  PID TTY          TIME CMD
31711 pts/8    00:00:00 gdbserver
  PID TTY          TIME CMD
31718 pts/8    00:00:00 server-kill-pyt
...

The problem is that while the gdbserver PID is supposed to be read from the
result of "gdb.execute ('p server_pid')" in the python script, instead it's
taken from:
...
Process server-kill-python created; pid = 31718^M
...

Fix this by moving the printing of the gdbserver PID out of the python script.

Also double-check the two methods against each other, in the cases that they
should match.

Tested on x86_64-linux.

PR testsuite/31633
https://sourceware.org/bugzilla/show_bug.cgi?id=31633
---
 .../gdb.server/server-kill-python.exp         | 37 +++++++++++--------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/gdb/testsuite/gdb.server/server-kill-python.exp b/gdb/testsuite/gdb.server/server-kill-python.exp
index 87f9b56bd39..f02c69c502f 100644
--- a/gdb/testsuite/gdb.server/server-kill-python.exp
+++ b/gdb/testsuite/gdb.server/server-kill-python.exp
@@ -37,7 +37,7 @@ set host_binfile [gdb_remote_download host $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 gdbserver_pid_check [exp_pid -i $server_spawn_id]
 
 set break_linenr [gdb_get_line_number "@@XX@@ Inferior Starting @@XX@@"]
 
@@ -48,9 +48,6 @@ puts $fd \
 "import gdb
 
 def do_gdb_stuff ():
-    gdb.execute ('break $srcfile:$break_linenr')
-    gdb.execute ('continue')
-    gdb.execute ('p server_pid')
     gdb.execute ('continue')
 
 do_gdb_stuff()"
@@ -68,24 +65,32 @@ if {[gdb_spawn_with_cmdline_opts \
 
 gdb_load $binfile
 gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport
-send_gdb "source $host_file1\n"
+
+gdb_test "break $srcfile:$break_linenr"
 
 # 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
-	}
+gdb_test "continue"
+gdb_test_multiple "print server_pid" "get gdbserver PID" {
+    -re -wrap " = ($decimal)" {
+	set gdbserver_pid $expect_out(1,string)
+	pass $gdb_test_name
     }
+}
 
-    if { $gdbserver_pid == 0 } {
-	return
-    }
+if { $gdbserver_pid == 0 } {
+    return
+}
+
+if { ![is_remote target] && $gdbserver_pid != $gdbserver_pid_check } {
+    error "Failed to get correct gdbserver pid"
+}
 
+send_gdb "source $host_file1\n"
+
+
+# Wait for the inferior to start up.
+with_spawn_id $server_spawn_id {
     gdb_test_multiple "" "ensure inferior is running" {
 	-re "@@XX@@ Inferior Starting @@XX@@" {
 	    pass $gdb_test_name
-- 
2.35.3


  reply	other threads:[~2024-04-12 17:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-12 17:51 [PATCH 1/2] [gdb/testsuite] Simplify gdb.server/server-kill-python.exp Tom de Vries
2024-04-12 17:51 ` Tom de Vries [this message]
2024-04-16 17:21 ` Tom Tromey
2024-04-17  9:48   ` 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=20240412175101.9154-2-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).