public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Tiezhu Yang <yangtiezhu@loongson.cn>, gdb-patches@sourceware.org
Subject: Re: [PATCH v3 2/4] gdb: testsuite: add new gdb_attach to check "attach" command
Date: Thu, 17 Mar 2022 16:50:31 +0000	[thread overview]
Message-ID: <0d25ccda-c26d-672f-6321-8a39aec9c1c6@palves.net> (raw)
In-Reply-To: <1647525661-8607-3-git-send-email-yangtiezhu@loongson.cn>

On 2022-03-17 14:00, Tiezhu Yang wrote:
> This commit adds new gdb_attach to centralize the failure checking of
> "attach" command. Return 0 if attach failed, otherwise return 1.
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
>  gdb/testsuite/lib/gdb.exp | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 89dcd0a..abbe79e 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -5111,6 +5111,26 @@ proc can_spawn_for_attach { } {
>      return 1
>  }
>  
> +# Centralize the failure checking of "attach" command.
> +# Return 0 if attach failed, otherwise return 1.
> +
> +proc gdb_attach { testpid {options {}} } {
> +    parse_options {
> +	{pattern ""}
> +    }

I'm surprised to see parse_options used instead of parse_args.

Like, in patch #4:

+    set attach_opts {
+	"pattern" "main.*at .*$::main_srcfile:.*"
+    }
+
+    if { ![gdb_attach $testpid $attach_opts] } {
+	return 0
     }

That looks odd to me -- it's not obvious that "pattern" is the option name.

If we instead use parse_args, the option would be specified with "-pattern" (leading dash),
and we'd use the magic TCL args array, so we wouldn't need to wrap the options in a list.
Like so (on top of the whole series):

From 86aa3249e0d6362fef7f784982949fb6422acf18 Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Thu, 17 Mar 2022 16:35:49 +0000
Subject: [PATCH] parse_args

Change-Id: Ia7234f34efbd6bcdad3aa7e39075df47abfbe24e
---
 gdb/testsuite/gdb.base/jit-elf.exp | 7 ++-----
 gdb/testsuite/lib/gdb.exp          | 8 ++++++--
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/gdb/testsuite/gdb.base/jit-elf.exp b/gdb/testsuite/gdb.base/jit-elf.exp
index e63f0863e99..efa1dc036b3 100644
--- a/gdb/testsuite/gdb.base/jit-elf.exp
+++ b/gdb/testsuite/gdb.base/jit-elf.exp
@@ -58,11 +58,8 @@ proc clean_reattach {} {
 
     clean_restart ${main_binfile}
 
-    set attach_opts {
-	"pattern" "main.*at .*$::main_srcfile:.*"
-    }
-
-    if { ![gdb_attach $testpid $attach_opts] } {
+    if { ![gdb_attach $testpid \
+	       -pattern "main.*at .*$::main_srcfile:.*"] } {
 	return 0
     }
 
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index abbe79e1a88..149a1c31776 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5114,11 +5114,15 @@ proc can_spawn_for_attach { } {
 # Centralize the failure checking of "attach" command.
 # Return 0 if attach failed, otherwise return 1.
 
-proc gdb_attach { testpid {options {}} } {
-    parse_options {
+proc gdb_attach { testpid args } {
+    parse_args {
 	{pattern ""}
     }
 
+    if { [llength $args] != 0 } {
+	error "Unexpected arguments: $args"
+    }
+
     gdb_test_multiple "attach $testpid" "attach" {
 	-re -wrap "Attaching to.*ptrace: Operation not permitted\\." {
 	    unsupported "$gdb_test_name (Operation not permitted)"


  reply	other threads:[~2022-03-17 16:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-17 14:00 [PATCH v3 0/4] gdb: add gdb_attach to fix failed testcases Tiezhu Yang
2022-03-17 14:00 ` [PATCH v3 1/4] gdb: testsuite: remove attach test from can_spawn_for_attach Tiezhu Yang
2022-03-17 14:00 ` [PATCH v3 2/4] gdb: testsuite: add new gdb_attach to check "attach" command Tiezhu Yang
2022-03-17 16:50   ` Pedro Alves [this message]
2022-03-17 17:04     ` Simon Marchi
2022-03-17 17:31       ` Pedro Alves
2022-03-18  1:56         ` Tiezhu Yang
2022-03-18 18:23           ` Simon Marchi
2022-03-17 14:01 ` [PATCH v3 3/4] gdb: testsuite: use gdb_attach to fix attach-pie-noexec.exp Tiezhu Yang
2022-03-17 16:51   ` Pedro Alves
2022-03-17 14:01 ` [PATCH v3 4/4] gdb: testsuite: use gdb_attach to fix jit-elf.exp Tiezhu Yang
2022-03-17 16:55 ` [PATCH v3 0/4] gdb: add gdb_attach to fix failed testcases Pedro Alves
2022-03-18  1:53   ` Tiezhu Yang
2022-03-18 18:33     ` Pedro Alves

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=0d25ccda-c26d-672f-6321-8a39aec9c1c6@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    --cc=yangtiezhu@loongson.cn \
    /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).