* [PATCH v4 0/4] gdb: add gdb_attach to fix failed testcases
@ 2022-03-19 2:11 Tiezhu Yang
2022-03-19 2:11 ` [PATCH v4 1/4] gdb: testsuite: remove attach test from can_spawn_for_attach Tiezhu Yang
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Tiezhu Yang @ 2022-03-19 2:11 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Pedro Alves
Hi,
Please review this v4 patchset, thank you.
The following suggestion is very good, it needs us to do more work.
I think we can do it later after this patchset is merged into master.
https://sourceware.org/pipermail/gdb-patches/2022-March/186795.html
Tiezhu Yang (4):
gdb: testsuite: remove attach test from can_spawn_for_attach
gdb: testsuite: add new gdb_attach to check "attach" command
gdb: testsuite: use gdb_attach to fix attach-pie-noexec.exp
gdb: testsuite: use gdb_attach to fix jit-elf.exp
gdb/testsuite/gdb.base/attach-pie-noexec.exp | 5 +-
gdb/testsuite/gdb.base/jit-elf.exp | 24 ++++++----
gdb/testsuite/lib/gdb.exp | 70 ++++++++++++----------------
3 files changed, 50 insertions(+), 49 deletions(-)
--
2.1.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 1/4] gdb: testsuite: remove attach test from can_spawn_for_attach
2022-03-19 2:11 [PATCH v4 0/4] gdb: add gdb_attach to fix failed testcases Tiezhu Yang
@ 2022-03-19 2:11 ` Tiezhu Yang
2022-03-19 2:11 ` [PATCH v4 2/4] gdb: testsuite: add new gdb_attach to check "attach" command Tiezhu Yang
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Tiezhu Yang @ 2022-03-19 2:11 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Pedro Alves
As Pedro Alves said, caching procs should not issue pass/fail [1],
this commit removes attach test from can_spawn_for_attach, at the
same time, use "verbose -log" instead of "unsupported" to get a
trace about why a test run doesn't support spawning for attach.
[1] https://sourceware.org/pipermail/gdb-patches/2022-March/186311.html
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
gdb/testsuite/lib/gdb.exp | 52 ++++++++---------------------------------------
1 file changed, 9 insertions(+), 43 deletions(-)
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 08726f7..89dcd0a 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5090,12 +5090,12 @@ proc gdb_exit { } {
# Return true if we can spawn a program on the target and attach to
# it.
-gdb_caching_proc can_spawn_for_attach {
+proc can_spawn_for_attach { } {
# We use exp_pid to get the inferior's pid, assuming that gives
# back the pid of the program. On remote boards, that would give
# us instead the PID of e.g., the ssh client, etc.
if [is_remote target] then {
- unsupported "skip attach tests (target is remote)"
+ verbose -log "can't spawn for attach (target is remote)"
return 0
}
@@ -5103,50 +5103,10 @@ gdb_caching_proc can_spawn_for_attach {
# stub-like, where GDB finds the program already started on
# initial connection.
if {[target_info exists use_gdb_stub]} {
- unsupported "skip attach tests (target is stub)"
+ verbose -log "can't spawn for attach (target is stub)"
return 0
}
- set me "can_spawn_for_attach"
- set src { int main (void) { sleep (600); return 0; } }
- if {![gdb_simple_compile $me $src executable]} {
- return 0
- }
-
- set test_spawn_id [spawn_wait_for_attach $obj]
- set test_pid [spawn_id_get_pid $test_spawn_id]
-
- gdb_start
- file delete $obj
- gdb_test_multiple "attach $test_pid" "can spawn for attach" {
- -re -wrap "Attaching to process $test_pid\r\n.*No executable file now.*" {
- pass $gdb_test_name
- kill_wait_spawned_process $test_spawn_id
- return 1
- }
- -re -wrap "Attaching to process $test_pid\r\n.*ptrace: Operation not permitted\\." {
- unsupported "$gdb_test_name (Operation not permitted)"
- kill_wait_spawned_process $test_spawn_id
- return 0
- }
- -re -wrap "Attaching to process $test_pid\r\n.*Attaching to process $test_pid failed" {
- unsupported "$gdb_test_name (Attaching to process failed)"
- kill_wait_spawned_process $test_spawn_id
- return 0
- }
- -re -wrap "Attaching to process $test_pid\r\n.*XML support was disabled at compile time.*" {
- pass $gdb_test_name
- kill_wait_spawned_process $test_spawn_id
- return 1
- }
- -re "A program is being debugged already. Kill it. .y or n. " {
- send_gdb "y\n"
- exp_continue
- }
- }
-
- kill_wait_spawned_process $test_spawn_id
-
# Assume yes.
return 1
}
@@ -5196,6 +5156,12 @@ proc spawn_id_get_pid { spawn_id } {
proc spawn_wait_for_attach { executable_list } {
set spawn_id_list {}
+ 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"
+ }
+
foreach {executable} $executable_list {
# Note we use Expect's spawn, not Tcl's exec, because with
# spawn we control when to wait for/reap the process. That
--
2.1.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 2/4] gdb: testsuite: add new gdb_attach to check "attach" command
2022-03-19 2:11 [PATCH v4 0/4] gdb: add gdb_attach to fix failed testcases Tiezhu Yang
2022-03-19 2:11 ` [PATCH v4 1/4] gdb: testsuite: remove attach test from can_spawn_for_attach Tiezhu Yang
@ 2022-03-19 2:11 ` Tiezhu Yang
2022-03-21 15:00 ` Simon Marchi
2022-03-19 2:11 ` [PATCH v4 3/4] gdb: testsuite: use gdb_attach to fix attach-pie-noexec.exp Tiezhu Yang
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Tiezhu Yang @ 2022-03-19 2:11 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Pedro Alves
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 | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 89dcd0a..149a1c3 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5111,6 +5111,30 @@ 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 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)"
+ return 0
+ }
+ -re -wrap "$pattern" {
+ pass $gdb_test_name
+ return 1
+ }
+ }
+}
+
# 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.
--
2.1.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 3/4] gdb: testsuite: use gdb_attach to fix attach-pie-noexec.exp
2022-03-19 2:11 [PATCH v4 0/4] gdb: add gdb_attach to fix failed testcases Tiezhu Yang
2022-03-19 2:11 ` [PATCH v4 1/4] gdb: testsuite: remove attach test from can_spawn_for_attach Tiezhu Yang
2022-03-19 2:11 ` [PATCH v4 2/4] gdb: testsuite: add new gdb_attach to check "attach" command Tiezhu Yang
@ 2022-03-19 2:11 ` Tiezhu Yang
2022-03-19 2:11 ` [PATCH v4 4/4] gdb: testsuite: use gdb_attach to fix jit-elf.exp Tiezhu Yang
2022-03-21 23:04 ` [PATCH v4 0/4] gdb: add gdb_attach to fix failed testcases Kevin Buettner
4 siblings, 0 replies; 9+ messages in thread
From: Tiezhu Yang @ 2022-03-19 2:11 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Pedro Alves
If /proc/sys/kernel/yama/ptrace_scope is 1, when execute the following
command without superuser:
make check-gdb TESTS="gdb.base/attach-pie-noexec.exp"
we can see the following messages in gdb/testsuite/gdb.log:
(gdb) attach 6500
Attaching to process 6500
ptrace: Operation not permitted.
(gdb) PASS: gdb.base/attach-pie-noexec.exp: attach
It is obviously wrong, the expected result should be UNSUPPORTED in such
a case.
With this patch, we can see "Operation not permitted" in the log info,
and then we can do the following processes to test:
(1) set ptrace_scope as 0
$ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
$ make check-gdb TESTS="gdb.base/attach-pie-noexec.exp"
(2) use sudo
$ sudo make check-gdb TESTS="gdb.base/attach-pie-noexec.exp"
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
gdb/testsuite/gdb.base/attach-pie-noexec.exp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.base/attach-pie-noexec.exp b/gdb/testsuite/gdb.base/attach-pie-noexec.exp
index 4712824..33238db 100644
--- a/gdb/testsuite/gdb.base/attach-pie-noexec.exp
+++ b/gdb/testsuite/gdb.base/attach-pie-noexec.exp
@@ -59,7 +59,10 @@ set testpid [spawn_id_get_pid $test_spawn_id]
gdb_start
file delete -- $binfile
-gdb_test "attach $testpid" "Attaching to process $testpid\r\n.*" "attach"
+if { ![gdb_attach $testpid] } {
+ kill_wait_spawned_process $test_spawn_id
+ return
+}
gdb_test "set architecture $arch" "The target architecture is set to \"$arch\"\\."
gdb_test "info shared" "From\[ \t\]+To\[ \t\]+Syms Read\[ \t\]+Shared Object Library\r\n0x.*"
--
2.1.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 4/4] gdb: testsuite: use gdb_attach to fix jit-elf.exp
2022-03-19 2:11 [PATCH v4 0/4] gdb: add gdb_attach to fix failed testcases Tiezhu Yang
` (2 preceding siblings ...)
2022-03-19 2:11 ` [PATCH v4 3/4] gdb: testsuite: use gdb_attach to fix attach-pie-noexec.exp Tiezhu Yang
@ 2022-03-19 2:11 ` Tiezhu Yang
2022-03-21 23:04 ` [PATCH v4 0/4] gdb: add gdb_attach to fix failed testcases Kevin Buettner
4 siblings, 0 replies; 9+ messages in thread
From: Tiezhu Yang @ 2022-03-19 2:11 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Pedro Alves
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
use gdb_attach to fix the above issue, at the same time, the clean_reattach
proc should return a value to indicate whether it worked, and the callers
should return early as well on failure.
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
gdb/testsuite/gdb.base/jit-elf.exp | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/gdb/testsuite/gdb.base/jit-elf.exp b/gdb/testsuite/gdb.base/jit-elf.exp
index 8a4c5b7..4b75188 100644
--- a/gdb/testsuite/gdb.base/jit-elf.exp
+++ b/gdb/testsuite/gdb.base/jit-elf.exp
@@ -38,6 +38,7 @@ set jit_solib_basename jit-elf-solib
set jit_solib_srcfile ${srcdir}/${subdir}/${jit_solib_basename}.c
# Detach, restart GDB, and re-attach to the program.
+# Return 0 if attach failed, otherwise return 1.
proc clean_reattach {} {
global decimal gdb_prompt
global main_binfile main_srcfile
@@ -57,18 +58,18 @@ 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"
- }
+ if { ![gdb_attach $testpid \
+ -pattern "main.*at .*$::main_srcfile:.*"] } {
+ return 0
}
gdb_test_no_output "set var wait_for_gdb = 0"
+ return 1
}
# Continue to LOCATION in the program. If REATTACH, detach and
# re-attach to the program from scratch.
+# Return 0 if clean_reattach failed, otherwise return 1.
proc continue_to_test_location {location reattach} {
global main_srcfile
@@ -76,9 +77,12 @@ proc continue_to_test_location {location reattach} {
gdb_continue_to_breakpoint $location
if {$reattach} {
with_test_prefix "$location" {
- clean_reattach
+ if { ![clean_reattach] } {
+ return 0
+ }
}
}
+ return 1
}
proc one_jit_test {jit_solibs_target match_str reattach} {
@@ -114,7 +118,9 @@ proc one_jit_test {jit_solibs_target match_str reattach} {
gdb_continue_to_breakpoint "break here 0"
- continue_to_test_location "break here 1" $reattach
+ if { ![continue_to_test_location "break here 1" $reattach] } {
+ return
+ }
gdb_test "info function ^jit_function" "$match_str"
@@ -124,7 +130,9 @@ proc one_jit_test {jit_solibs_target match_str reattach} {
gdb_test "maintenance info break"
}
- continue_to_test_location "break here 2" $reattach
+ if { ![continue_to_test_location "break here 2" $reattach] } {
+ return
+ }
# All jit librares must have been unregistered
gdb_test "info function jit_function" \
--
2.1.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 2/4] gdb: testsuite: add new gdb_attach to check "attach" command
2022-03-19 2:11 ` [PATCH v4 2/4] gdb: testsuite: add new gdb_attach to check "attach" command Tiezhu Yang
@ 2022-03-21 15:00 ` Simon Marchi
2022-03-22 3:27 ` Tiezhu Yang
0 siblings, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2022-03-21 15:00 UTC (permalink / raw)
To: Tiezhu Yang, gdb-patches; +Cc: Pedro Alves
On 2022-03-18 22:11, 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 | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 89dcd0a..149a1c3 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -5111,6 +5111,30 @@ 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 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)"
> + return 0
> + }
> + -re -wrap "$pattern" {
> + pass $gdb_test_name
> + return 1
> + }
> + }
> +}
I guess we need a "return 0" at the end of the function, in case the test does fail?
Simon
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 0/4] gdb: add gdb_attach to fix failed testcases
2022-03-19 2:11 [PATCH v4 0/4] gdb: add gdb_attach to fix failed testcases Tiezhu Yang
` (3 preceding siblings ...)
2022-03-19 2:11 ` [PATCH v4 4/4] gdb: testsuite: use gdb_attach to fix jit-elf.exp Tiezhu Yang
@ 2022-03-21 23:04 ` Kevin Buettner
2022-03-22 3:30 ` Tiezhu Yang
4 siblings, 1 reply; 9+ messages in thread
From: Kevin Buettner @ 2022-03-21 23:04 UTC (permalink / raw)
To: Tiezhu Yang; +Cc: gdb-patches, Pedro Alves
On Sat, 19 Mar 2022 10:11:23 +0800
Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
> Please review this v4 patchset, thank you.
FWIW, my testing shows that this series fixes problems introduced
by commit 1dbf27133db.
It eliminates the new failure in gdb.base/run-after-attach.exp and
three failures in a new test that I'm working on.
Kevin
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 2/4] gdb: testsuite: add new gdb_attach to check "attach" command
2022-03-21 15:00 ` Simon Marchi
@ 2022-03-22 3:27 ` Tiezhu Yang
0 siblings, 0 replies; 9+ messages in thread
From: Tiezhu Yang @ 2022-03-22 3:27 UTC (permalink / raw)
To: Simon Marchi, gdb-patches; +Cc: Pedro Alves
On 03/21/2022 11:00 PM, Simon Marchi wrote:
> On 2022-03-18 22:11, 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 | 24 ++++++++++++++++++++++++
>> 1 file changed, 24 insertions(+)
>>
>> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
>> index 89dcd0a..149a1c3 100644
>> --- a/gdb/testsuite/lib/gdb.exp
>> +++ b/gdb/testsuite/lib/gdb.exp
>> @@ -5111,6 +5111,30 @@ 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 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)"
>> + return 0
>> + }
>> + -re -wrap "$pattern" {
>> + pass $gdb_test_name
>> + return 1
>> + }
>> + }
>> +}
>
> I guess we need a "return 0" at the end of the function, in case the test does fail?
>
> Simon
>
OK, let me do it and then I will send v5 soon.
Thanks,
Tiezhu
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 0/4] gdb: add gdb_attach to fix failed testcases
2022-03-21 23:04 ` [PATCH v4 0/4] gdb: add gdb_attach to fix failed testcases Kevin Buettner
@ 2022-03-22 3:30 ` Tiezhu Yang
0 siblings, 0 replies; 9+ messages in thread
From: Tiezhu Yang @ 2022-03-22 3:30 UTC (permalink / raw)
To: Kevin Buettner; +Cc: gdb-patches, Pedro Alves
On 03/22/2022 07:04 AM, Kevin Buettner wrote:
> On Sat, 19 Mar 2022 10:11:23 +0800
> Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>
>> Please review this v4 patchset, thank you.
>
> FWIW, my testing shows that this series fixes problems introduced
> by commit 1dbf27133db.
>
> It eliminates the new failure in gdb.base/run-after-attach.exp and
> three failures in a new test that I'm working on.
>
> Kevin
>
Thank you for your test and feedback.
I will do a small change of patch #2 suggested by Simon,
and then I will send v5 soon.
Thanks,
Tiezhu
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-03-22 3:30 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-19 2:11 [PATCH v4 0/4] gdb: add gdb_attach to fix failed testcases Tiezhu Yang
2022-03-19 2:11 ` [PATCH v4 1/4] gdb: testsuite: remove attach test from can_spawn_for_attach Tiezhu Yang
2022-03-19 2:11 ` [PATCH v4 2/4] gdb: testsuite: add new gdb_attach to check "attach" command Tiezhu Yang
2022-03-21 15:00 ` Simon Marchi
2022-03-22 3:27 ` Tiezhu Yang
2022-03-19 2:11 ` [PATCH v4 3/4] gdb: testsuite: use gdb_attach to fix attach-pie-noexec.exp Tiezhu Yang
2022-03-19 2:11 ` [PATCH v4 4/4] gdb: testsuite: use gdb_attach to fix jit-elf.exp Tiezhu Yang
2022-03-21 23:04 ` [PATCH v4 0/4] gdb: add gdb_attach to fix failed testcases Kevin Buettner
2022-03-22 3:30 ` Tiezhu Yang
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).