public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Lancelot SIX <lsix@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] gdb/testsuite: Introduce and use gdb_spawn_attach_cmdline
Date: Wed, 20 Apr 2022 19:51:15 +0000 (GMT)	[thread overview]
Message-ID: <20220420195115.01FC83858D1E@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b750766ac9652def5307925b8fc5c215fbcef8df

commit b750766ac9652def5307925b8fc5c215fbcef8df
Author: Lancelot SIX <lancelot.six@amd.com>
Date:   Thu Apr 14 10:41:48 2022 +0100

    gdb/testsuite: Introduce and use gdb_spawn_attach_cmdline
    
    Following a7e6a19e87f3d719ea23c65b580a6d9bca4ccab3 "gdb: testsuite: add
    new gdb_attach to check "attach" command", this commit proposes to
    introduce the gdb_spawn_attach_cmdline helper and use it in
    gdb.base/attach.exp.
    
    This helper starts GDB and adds the "--pid=$PID" argument.
    
    Also note that both the original and new implementation use
    gdb_spawn_with_cmdline_opts, which in the end uses default_gdb_spawn.
    This makes sure that we use $INTERNAL_GDBFLAGS, which by default already
    contain "-iex \"set height 0\" -iex \"set width 0\"".  To avoid
    repetition of those arguments, gdb_spawn_attach_cmdline does not repeat
    those arguments.
    
    To maintain a behavior similat to what gdb.base/attach.exp used to do,
    gdb_spawn_attach_cmdline keeps the -quiet flag.
    
    Tested on x86_64-gnu-linux
    
    Change-Id: I1fdcdb71c86d9c5d34bb28fc86fac68bcec37358

Diff:
---
 gdb/testsuite/gdb.base/attach.exp | 11 +++-------
 gdb/testsuite/lib/gdb.exp         | 46 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/gdb/testsuite/gdb.base/attach.exp b/gdb/testsuite/gdb.base/attach.exp
index d01060aba53..7b661e99a1c 100644
--- a/gdb/testsuite/gdb.base/attach.exp
+++ b/gdb/testsuite/gdb.base/attach.exp
@@ -467,14 +467,9 @@ proc_with_prefix do_command_attach_tests {} {
 
     gdb_exit
 
-    set res [gdb_spawn_with_cmdline_opts \
-		 "-quiet -iex \"set height 0\" -iex \"set width 0\" --pid=$testpid"]
-    set test "starting with --pid"
-    gdb_test_multiple "" $test {
-	-re "Reading symbols from.*$gdb_prompt $" {
-	    pass "$test"
-	}
-    }
+    # gdb_spawn_attach_cmdline records test results.  No need to explicitly
+    # call pass/fail here.
+    gdb_spawn_attach_cmdline $testpid
 
     # Get rid of the process
     kill_wait_spawned_process $test_spawn_id
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 10f78736629..0c00d599ca5 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5186,6 +5186,52 @@ proc gdb_attach { testpid args } {
     return 0
 }
 
+# Start gdb with "--pid $TESTPID" on the command line and wait for the prompt.
+# Return 1 if GDB managed to start and attach to the process, 0 otherwise.
+
+proc_with_prefix gdb_spawn_attach_cmdline { testpid } {
+    if ![can_spawn_for_attach] {
+	# The caller should have checked can_spawn_for_attach itself
+	# before getting here.
+	error "can't spawn for attach with this target/board"
+    }
+
+    set test "start gdb with --pid"
+    set res [gdb_spawn_with_cmdline_opts "-quiet --pid=$testpid"]
+    if { $res != 0 } {
+	fail $test
+	return 0
+    }
+
+    gdb_test_multiple "" "$test" {
+	-re -wrap "ptrace: Operation not permitted\\." {
+	    untested "$gdb_test_name (operation not permitted)"
+	    return 0
+	}
+	-re -wrap "ptrace: No such process\\." {
+	    fail "$gdb_test_name (no such process)"
+	    return 0
+	}
+	-re -wrap "Attaching to process $testpid\r\n.*" {
+	    pass $gdb_test_name
+	}
+    }
+
+    # Check that we actually attached to a process, in case the
+    # error message is not caught by the patterns above.
+    gdb_test_multiple "info thread" "" {
+	-re -wrap "No threads\\." {
+	    fail "$gdb_test_name (no thread)"
+	}
+	-re -wrap "Id.*" {
+	    pass $gdb_test_name
+	    return 1
+	}
+    }
+
+    return 0
+}
+
 # Kill a progress previously started with spawn_wait_for_attach, and
 # reap its wait status.  PROC_SPAWN_ID is the spawn id associated with
 # the process.


                 reply	other threads:[~2022-04-20 19:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220420195115.01FC83858D1E@sourceware.org \
    --to=lsix@sourceware.org \
    --cc=gdb-cvs@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).