* [PATCH v5 0/4] gdb: add gdb_attach to fix failed testcases
@ 2022-03-22 6:41 Tiezhu Yang
2022-03-22 6:41 ` [PATCH v5 1/4] gdb: testsuite: remove attach test from can_spawn_for_attach Tiezhu Yang
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Tiezhu Yang @ 2022-03-22 6:41 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Pedro Alves, Kevin
Please review this v5 patchset, thank you.
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 | 72 +++++++++++++---------------
3 files changed, 52 insertions(+), 49 deletions(-)
--
2.1.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v5 1/4] gdb: testsuite: remove attach test from can_spawn_for_attach
2022-03-22 6:41 [PATCH v5 0/4] gdb: add gdb_attach to fix failed testcases Tiezhu Yang
@ 2022-03-22 6:41 ` Tiezhu Yang
2022-03-22 6:41 ` [PATCH v5 2/4] gdb: testsuite: add new gdb_attach to check "attach" command Tiezhu Yang
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Tiezhu Yang @ 2022-03-22 6:41 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Pedro Alves, Kevin
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 729bded..892bf07 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5122,12 +5122,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
}
@@ -5135,50 +5135,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
}
@@ -5228,6 +5188,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] 6+ messages in thread
* [PATCH v5 2/4] gdb: testsuite: add new gdb_attach to check "attach" command
2022-03-22 6:41 [PATCH v5 0/4] gdb: add gdb_attach to fix failed testcases Tiezhu Yang
2022-03-22 6:41 ` [PATCH v5 1/4] gdb: testsuite: remove attach test from can_spawn_for_attach Tiezhu Yang
@ 2022-03-22 6:41 ` Tiezhu Yang
2022-03-22 6:41 ` [PATCH v5 3/4] gdb: testsuite: use gdb_attach to fix attach-pie-noexec.exp Tiezhu Yang
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Tiezhu Yang @ 2022-03-22 6:41 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Pedro Alves, Kevin
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 | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 892bf07..d8015fb 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5143,6 +5143,32 @@ 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
+ }
+ }
+
+ 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.
--
2.1.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v5 3/4] gdb: testsuite: use gdb_attach to fix attach-pie-noexec.exp
2022-03-22 6:41 [PATCH v5 0/4] gdb: add gdb_attach to fix failed testcases Tiezhu Yang
2022-03-22 6:41 ` [PATCH v5 1/4] gdb: testsuite: remove attach test from can_spawn_for_attach Tiezhu Yang
2022-03-22 6:41 ` [PATCH v5 2/4] gdb: testsuite: add new gdb_attach to check "attach" command Tiezhu Yang
@ 2022-03-22 6:41 ` Tiezhu Yang
2022-03-22 6:41 ` [PATCH v5 4/4] gdb: testsuite: use gdb_attach to fix jit-elf.exp Tiezhu Yang
2022-03-22 11:24 ` [PATCH v5 0/4] gdb: add gdb_attach to fix failed testcases Pedro Alves
4 siblings, 0 replies; 6+ messages in thread
From: Tiezhu Yang @ 2022-03-22 6:41 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Pedro Alves, Kevin
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] 6+ messages in thread
* [PATCH v5 4/4] gdb: testsuite: use gdb_attach to fix jit-elf.exp
2022-03-22 6:41 [PATCH v5 0/4] gdb: add gdb_attach to fix failed testcases Tiezhu Yang
` (2 preceding siblings ...)
2022-03-22 6:41 ` [PATCH v5 3/4] gdb: testsuite: use gdb_attach to fix attach-pie-noexec.exp Tiezhu Yang
@ 2022-03-22 6:41 ` Tiezhu Yang
2022-03-22 11:24 ` [PATCH v5 0/4] gdb: add gdb_attach to fix failed testcases Pedro Alves
4 siblings, 0 replies; 6+ messages in thread
From: Tiezhu Yang @ 2022-03-22 6:41 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Pedro Alves, Kevin
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] 6+ messages in thread
* Re: [PATCH v5 0/4] gdb: add gdb_attach to fix failed testcases
2022-03-22 6:41 [PATCH v5 0/4] gdb: add gdb_attach to fix failed testcases Tiezhu Yang
` (3 preceding siblings ...)
2022-03-22 6:41 ` [PATCH v5 4/4] gdb: testsuite: use gdb_attach to fix jit-elf.exp Tiezhu Yang
@ 2022-03-22 11:24 ` Pedro Alves
4 siblings, 0 replies; 6+ messages in thread
From: Pedro Alves @ 2022-03-22 11:24 UTC (permalink / raw)
To: Tiezhu Yang, gdb-patches
On 2022-03-22 06:41, Tiezhu Yang wrote:
> Please review this v5 patchset, thank you.
Looks fine to me.
BTW, I tried setting ptrace_scope=1 and then running gdb.base/attach.exp, as probably the main attach testcase, and it
unsurprisingly FAILs:
$ echo 1 | sudo tee /proc/sys/kernel/yama/ptrace_scope
$ make check TESTS="gdb.base/attach.exp"
...
Running /home/pedro/gdb/build/gdb/testsuite/../../../src/gdb/testsuite/gdb.base/attach.exp ...
FAIL: gdb.base/attach.exp: do_attach_tests: attach1, after setting file
FAIL: gdb.base/attach.exp: do_attach_tests: attach1 detach (the program is no longer running)
FAIL: gdb.base/attach.exp: do_attach_tests: attach2, with no file
FAIL: gdb.base/attach.exp: do_attach_tests: after attach2, set should_exit
FAIL: gdb.base/attach.exp: do_attach_tests: continue to breakpoint: postloop (the program is no longer running)
FAIL: gdb.base/attach.exp: do_attach_tests: continue until exit at after attach2, exit (the program is no longer running)
FAIL: gdb.base/attach.exp: do_attach_tests: attach when process' a.out not in cwd
...
The curious thing is that the first FAIL is already a gdb_test_multiple:
set test "attach1, after setting file"
gdb_test_multiple "attach $testpid" "$test" {
-re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $" {
pass "$test"
}
-re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
# Response expected on Cygwin
pass "$test"
}
}
So I really think we will want to do the idea at
<https://sourceware.org/pipermail/gdb-patches/2022-March/186795.html>. But it can be
done after your patches are in. I'm fine with you merging what you have as is.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-03-22 11:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-22 6:41 [PATCH v5 0/4] gdb: add gdb_attach to fix failed testcases Tiezhu Yang
2022-03-22 6:41 ` [PATCH v5 1/4] gdb: testsuite: remove attach test from can_spawn_for_attach Tiezhu Yang
2022-03-22 6:41 ` [PATCH v5 2/4] gdb: testsuite: add new gdb_attach to check "attach" command Tiezhu Yang
2022-03-22 6:41 ` [PATCH v5 3/4] gdb: testsuite: use gdb_attach to fix attach-pie-noexec.exp Tiezhu Yang
2022-03-22 6:41 ` [PATCH v5 4/4] gdb: testsuite: use gdb_attach to fix jit-elf.exp Tiezhu Yang
2022-03-22 11:24 ` [PATCH v5 0/4] gdb: add gdb_attach to fix failed testcases Pedro Alves
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).