Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mohamed Bouhaouel <mohamed.bouhaouel@intel.com>
To: gdb-patches@sourceware.org
Cc: markus.t.metzger@intel.com, stephan.rohr@intel.com, eliz@gnu.org,
	aburgess@redhat.com, pedro@palves.net
Subject: [PATCH v4 09/11] gdb, testsuite: update attach-deleted-exec.exp to handle async messages
Date: Tue, 14 Jul 2026 11:21:26 +0200	[thread overview]
Message-ID: <20260714092128.12941-10-mohamed.bouhaouel@intel.com> (raw)
In-Reply-To: <20260714092128.12941-1-mohamed.bouhaouel@intel.com>

From: "Bouhaouel, Mohamed" <mohamed.bouhaouel@intel.com>

With non-stop targets, async thread notifications can appear between
output lines during attach.  Also, multiple "Reading symbols from"
messages are printed, so we need to specifically match the /proc/
path to capture the correct filename.

Output example on a non-stop remote target:

  (gdb) attach 33604
  Attaching to process 33604
  [New Thread 33604.33604 (id 1)]
  Reading symbols from /proc/33604/exe...
  Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...
  Reading symbols from /usr/lib/debug/.build-id/8e/9fd827446c24067541ac5390e6f527fb5947bb.debug...
  Reading symbols from /lib64/ld-linux-x86-64.so.2...
  Reading symbols from /usr/lib/debug/.build-id/da/07864eb4c1b06504b8688d25d7e84759fe708d.debug...
  [Switching to Thread 33604.33604]
  0x00007c9166eeca7a in __GI___clock_nanosleep ...

Reproducible when running gdb.base/attach-deleted-exec.exp, on
native-extended-gdbserver with target-non-stop enabled.

export GDBFLAGS="-iex \"maint set target-non-stop on\""
make check TESTS="gdb.base/attach-deleted-exec.exp" \
    RUNTESTFLAGS="--target_board=native-extended-gdbserver GDBFLAGS='$GDBFLAGS'"
---
 .../gdb.base/attach-deleted-exec.exp          | 59 +++++++++++--------
 1 file changed, 34 insertions(+), 25 deletions(-)

diff --git a/gdb/testsuite/gdb.base/attach-deleted-exec.exp b/gdb/testsuite/gdb.base/attach-deleted-exec.exp
index 5d3f43eff00..69233ddaffd 100644
--- a/gdb/testsuite/gdb.base/attach-deleted-exec.exp
+++ b/gdb/testsuite/gdb.base/attach-deleted-exec.exp
@@ -45,26 +45,29 @@ clean_restart
 
 # Attach.  GDB should spot that the executable is gone and fallback to
 # use /proc/PID/exe.
-set test "attach to process with deleted executable"
-set re \
-    [multi_line \
-	 "Attaching to process $decimal" \
-	 "Reading symbols from (\[^\r\n\]+)[string_to_regexp ...]" \
-	 ".*"]
-set filename ""
-gdb_test_multiple "attach $testpid" $test {
-    -re -wrap $re {
-	set filename $expect_out(1,string)
-	pass $gdb_test_name
+set attached_pid "no pid"
+gdb_test_multiple "attach $testpid" "attach to process with deleted executable" {
+    -re "Attaching to process $decimal\r\n" {
+	exp_continue
+    }
+    -re "\\\[New Thread \[^\r\n\]+\\\]\r\n" {
+	# Non-stop targets may emit async thread notifications.
+	exp_continue
+    }
+    -re "Reading symbols from /proc/($decimal)/exe[string_to_regexp ...]" {
+	set attached_pid $expect_out(1,string)
+	exp_continue
+    }
+    -re "Reading symbols from (\[^\r\n\]+[string_to_regexp /.nfs]\[^\r\n\]*)[string_to_regexp ...]" {
+	unsupported $gdb_test_name
+	return
+    }
+    -re "Reading symbols from \[^\r\n\]+[string_to_regexp ...]\r\n" {
+	exp_continue
+    }
+    -re -wrap "" {
+	gdb_assert { $attached_pid == $testpid } $gdb_test_name
     }
-}
-
-set test "filename /proc/PID/exe"
-set re_nfs \[^\r\n\]+[string_to_regexp /.nfs]\[^\r\n\]+
-if { [regexp $re_nfs $filename] } {
-    unsupported $test
-} else {
-    gdb_assert { [string equal $filename /proc/${testpid}/exe] } $test
 }
 
 # Restart GDB.
@@ -97,12 +100,18 @@ if { [target_info gdb_protocol] == "extended-remote" } {
     set filename_re "\[^\r\n\]+/${testfile} \\(deleted\\)"
 }
 
-gdb_test "attach $testpid" \
-    [multi_line \
-	 "Attaching to process $decimal" \
-	 "warning: No executable has been specified, and target executable $filename_re could not be found\\.  Try using the \"file\" command\\." \
-	 ".*"] \
-    "attach to inferior"
+gdb_test_multiple "attach $testpid" "attach to inferior" {
+    -re "Attaching to process $decimal\r\n" {
+	exp_continue
+    }
+    -re "\\\[New Thread \[^\r\n\]+\\\]\r\n" {
+	# Non-stop targets may emit async thread notifications.
+	exp_continue
+    }
+    -re -wrap "warning: No executable has been specified, and target executable $filename_re could not be found\\.  Try using the \"file\" command\\..*" {
+	pass $gdb_test_name
+    }
+}
 
 # Check GDB hasn't managed to load an executable.
 gdb_test "info inferior" \
-- 
2.43.0

Intel Deutschland GmbH

Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 89 991 430, www.intel.de
Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell
Chairperson of the Supervisory Board: Nicole Lau
Registered Seat: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


  parent reply	other threads:[~2026-07-14  9:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14  9:21 [PATCH v4 00/11] Add AlwaysNonStop remote protocol extension Mohamed Bouhaouel
2026-07-14  9:21 ` [PATCH v4 01/11] gdb, record: fix assertion when remote target is set to non-stop Mohamed Bouhaouel
2026-07-14  9:21 ` [PATCH v4 02/11] gdb, remote: fix assertion on reconnect to non-stop target Mohamed Bouhaouel
2026-07-14  9:21 ` [PATCH v4 03/11] gdb, remote: fix async handler " Mohamed Bouhaouel
2026-07-14  9:21 ` [PATCH v4 04/11] gdb, remote: fix "info program" after " Mohamed Bouhaouel
2026-07-14  9:21 ` [PATCH v4 05/11] gdb, remote: fix crash when accessing removed events Mohamed Bouhaouel
2026-07-14  9:21 ` [PATCH v4 06/11] gdb, remote: fix ptid matching for process-wide stop events Mohamed Bouhaouel
2026-07-14  9:21 ` [PATCH v4 07/11] gdb, dap: fix DAP events if no thread is selected Mohamed Bouhaouel
2026-07-14  9:21 ` [PATCH v4 08/11] gdb, testsuite: handle async close in monitor-exit-quit.exp Mohamed Bouhaouel
2026-07-14  9:21 ` Mohamed Bouhaouel [this message]
2026-07-14  9:21 ` [PATCH v4 10/11] gdb, testsuite: add kfails for step-over-process-exit.exp Mohamed Bouhaouel
2026-07-14  9:21 ` [PATCH v4 11/11] gdb, gdbserver: add AlwaysNonStop remote protocol extension Mohamed Bouhaouel
2026-07-14 12:07   ` Eli Zaretskii

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=20260714092128.12941-10-mohamed.bouhaouel@intel.com \
    --to=mohamed.bouhaouel@intel.com \
    --cc=aburgess@redhat.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=markus.t.metzger@intel.com \
    --cc=pedro@palves.net \
    --cc=stephan.rohr@intel.com \
    /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