public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Tiezhu Yang <yangtiezhu@loongson.cn>, gdb-patches@sourceware.org
Subject: Re: [PATCH 3/3] gdb: testsuite: enhance gdb_attach to fix jit-elf.exp
Date: Wed, 16 Mar 2022 10:16:19 -0400	[thread overview]
Message-ID: <3b845985-cbd4-4996-145e-14191338b095@polymtl.ca> (raw)
In-Reply-To: <1647424709-23680-4-git-send-email-yangtiezhu@loongson.cn>



On 2022-03-16 05:58, Tiezhu Yang wrote:
> If /proc/sys/kernel/yama/ptrace_scope is 1, when execute the following
> command without superuser:
> 
>   make check-gdb TESTS="gdb.base/jit-elf.exp"
> 
> we can see the following messages in gdb/testsuite/gdb.log:
> 
>   (gdb) attach 1650108
>   Attaching to program: /home/yangtiezhu/build/gdb/testsuite/outputs/gdb.base/jit-elf/jit-elf-main, process 1650108
>   ptrace: Operation not permitted.
>   (gdb) FAIL: gdb.base/jit-elf.exp: attach: one_jit_test-2: break here 1: attach
> 
> handle the above case in gdb_attach, and then use gdb_attach to fix
> the above issue.
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
>  gdb/testsuite/gdb.base/jit-elf.exp | 9 ++-------
>  gdb/testsuite/lib/gdb.exp          | 8 ++++++++
>  2 files changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.base/jit-elf.exp b/gdb/testsuite/gdb.base/jit-elf.exp
> index 8a4c5b7..61a51a2 100644
> --- a/gdb/testsuite/gdb.base/jit-elf.exp
> +++ b/gdb/testsuite/gdb.base/jit-elf.exp
> @@ -40,7 +40,7 @@ set jit_solib_srcfile ${srcdir}/${subdir}/${jit_solib_basename}.c
>  # Detach, restart GDB, and re-attach to the program.
>  proc clean_reattach {} {
>      global decimal gdb_prompt
> -    global main_binfile main_srcfile
> +    global main_binfile
>  
>      # Get PID of test program.
>      set testpid -1
> @@ -57,12 +57,7 @@ proc clean_reattach {} {
>  
>      clean_restart ${main_binfile}
>  
> -    set test "attach"
> -    gdb_test_multiple "attach $testpid" "$test" {
> -	-re "Attaching to program.*.*main.*at .*$main_srcfile:.*$gdb_prompt $" {
> -	    pass "$test"
> -	}
> -    }
> +    gdb_attach $testpid


Ok, to expand on my previous message: in order to allow matching for
some specific output, like this test does (to avoid losing some test
coverage), I propose to let the caller pass an extra pattern that will
be used in the catch-all success clause:

gdb_attach can be:

proc gdb_attach { testpid {options {}} } {
    parse_options {
	{pattern ""}
    }

    gdb_test_multiple "attach $testpid" "attach" {
	-re -wrap "Attaching to.*ptrace: Operation not permitted\\." {
		unsupported "$gdb_test_name (Operation not permitted)"
		return 0
	}

	-re -wrap "$pattern" {
		pass $gdb_test_name
	 	return 1
	}
    }
}

And the caller can do:

gdb_attach $testpid {
    "pattern" "main.*at .*$::main_srcfile:.*"
}

A simpler caller that doesn't care about the output can still do just:

gdb_attach $testpid

Note that you probably want to make the test return if gdb_attach
returns 0 (as you did in the previous test), so that we don't continue
and generate some FAILs.

>  
>      gdb_test_no_output "set var wait_for_gdb = 0"
>  }
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 599e8cc..5751bde 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -5114,6 +5114,14 @@ proc gdb_attach { testpid } {
>  	  unsupported "$gdb_test_name (Operation not permitted)"
>  	  return 0
>  	}
> +	-re -wrap "Attaching to program.*.*main.*at .*:.*" {
> +	  pass $gdb_test_name
> +	  return 1
> +	}
> +	-re -wrap "Attaching to program: .*, process $testpid\r\n.*ptrace: Operation not permitted\\." {
> +	  unsupported "$gdb_test_name (Operation not permitted)"
> +	  return 0
> +	}
>      }
>  }

This way we don't need to add many specific patterns like this.

Simon

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

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-16  9:58 [PATCH 0/3] gdb: add gdb_attach to fix failed testcases Tiezhu Yang
2022-03-16  9:58 ` [PATCH 1/3] gdb: testsuite: leave can_spawn_for_attach alone Tiezhu Yang
2022-03-16 13:24   ` Simon Marchi
2022-03-16  9:58 ` [PATCH 2/3] gdb: testsuite: add new gdb_attach to fix attach-pie-noexec.exp Tiezhu Yang
2022-03-16 14:03   ` Simon Marchi
2022-03-16  9:58 ` [PATCH 3/3] gdb: testsuite: enhance gdb_attach to fix jit-elf.exp Tiezhu Yang
2022-03-16 14:16   ` Simon Marchi [this message]

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=3b845985-cbd4-4996-145e-14191338b095@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --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).