public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v4 0/2] Modify can_spawn_for_attach
@ 2022-02-22 12:42 Tiezhu Yang
  2022-02-22 12:42 ` [PATCH v4 1/2] gdb: testsuite: print explicit test result in can_spawn_for_attach() Tiezhu Yang
  2022-02-22 12:42 ` [PATCH v4 2/2] gdb: testsuite: fix wrong expected result in attach-pie-noexec.exp Tiezhu Yang
  0 siblings, 2 replies; 4+ messages in thread
From: Tiezhu Yang @ 2022-02-22 12:42 UTC (permalink / raw)
  To: gdb-patches

v4:
  -- Add patch #1 to print explicit test result for some test.
  -- Modify patch #2 suggested by Simon Marchi, thank you.

Tiezhu Yang (2):
  gdb: testsuite: print explicit test result in can_spawn_for_attach()
  gdb: testsuite: fix wrong expected result in attach-pie-noexec.exp

 gdb/testsuite/lib/gdb.exp | 46 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 7 deletions(-)

-- 
2.1.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v4 1/2] gdb: testsuite: print explicit test result in can_spawn_for_attach()
  2022-02-22 12:42 [PATCH v4 0/2] Modify can_spawn_for_attach Tiezhu Yang
@ 2022-02-22 12:42 ` Tiezhu Yang
  2022-02-22 14:42   ` Simon Marchi
  2022-02-22 12:42 ` [PATCH v4 2/2] gdb: testsuite: fix wrong expected result in attach-pie-noexec.exp Tiezhu Yang
  1 sibling, 1 reply; 4+ messages in thread
From: Tiezhu Yang @ 2022-02-22 12:42 UTC (permalink / raw)
  To: gdb-patches

In the current code, there is no test result when execute the following
commands:

  $ make check-gdb TESTS="gdb.base/attach-pie-noexec.exp" RUNTESTFLAGS="--target_board=remote-gdbserver-on-localhost"
  $ make check-gdb TESTS="gdb.base/attach-pie-noexec.exp" RUNTESTFLAGS="--target_board=native-gdbserver"

It is better to print explicit test result in can_spawn_for_attach().

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 gdb/testsuite/lib/gdb.exp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index a3717a4..d15ab90 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5063,6 +5063,7 @@ proc can_spawn_for_attach { } {
     # 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 {
+	untested "skipping tests due to is_remote target"
 	return 0
     }
 
@@ -5070,6 +5071,7 @@ proc can_spawn_for_attach { } {
     # stub-like, where GDB finds the program already started on
     # initial connection.
     if {[target_info exists use_gdb_stub]} {
+	untested "skipping tests due to use_gdb_stub"
 	return 0
     }
 
-- 
2.1.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v4 2/2] gdb: testsuite: fix wrong expected result in attach-pie-noexec.exp
  2022-02-22 12:42 [PATCH v4 0/2] Modify can_spawn_for_attach Tiezhu Yang
  2022-02-22 12:42 ` [PATCH v4 1/2] gdb: testsuite: print explicit test result in can_spawn_for_attach() Tiezhu Yang
@ 2022-02-22 12:42 ` Tiezhu Yang
  1 sibling, 0 replies; 4+ messages in thread
From: Tiezhu Yang @ 2022-02-22 12:42 UTC (permalink / raw)
  To: gdb-patches

If /proc/sys/kernel/yama/ptrace_scope is 1, when execute the test case
gdb.base/attach-pie-noexec.exp without superuser, the gdb.log shows the
following info:

  (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.

It is better to make can_spawn_for_attach to return false for this case.
It would have to setup a small test program, compile it to exec, spawn it
and try to attach to it.

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"

Additionally, handle the other cases when test with RUNTESTFLAGS=
"--target_board=native-extended-gdbserver".

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 gdb/testsuite/lib/gdb.exp | 44 +++++++++++++++++++++++++++++++++++++-------
 1 file changed, 37 insertions(+), 7 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index d15ab90..b9e5596 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5058,7 +5058,7 @@ proc gdb_exit { } {
 # Return true if we can spawn a program on the target and attach to
 # it.
 
-proc can_spawn_for_attach { } {
+gdb_caching_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.
@@ -5075,6 +5075,42 @@ proc can_spawn_for_attach { } {
 	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
+        }
+    }
+
+    kill_wait_spawned_process $test_spawn_id
+
     # Assume yes.
     return 1
 }
@@ -5124,12 +5160,6 @@ 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] 4+ messages in thread

* Re: [PATCH v4 1/2] gdb: testsuite: print explicit test result in can_spawn_for_attach()
  2022-02-22 12:42 ` [PATCH v4 1/2] gdb: testsuite: print explicit test result in can_spawn_for_attach() Tiezhu Yang
@ 2022-02-22 14:42   ` Simon Marchi
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Marchi @ 2022-02-22 14:42 UTC (permalink / raw)
  To: Tiezhu Yang, gdb-patches

On 2022-02-22 07:42, Tiezhu Yang wrote:
> In the current code, there is no test result when execute the following
> commands:
> 
>   $ make check-gdb TESTS="gdb.base/attach-pie-noexec.exp" RUNTESTFLAGS="--target_board=remote-gdbserver-on-localhost"
>   $ make check-gdb TESTS="gdb.base/attach-pie-noexec.exp" RUNTESTFLAGS="--target_board=native-gdbserver"
> 
> It is better to print explicit test result in can_spawn_for_attach().
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

It could be that some test uses this procedure not to skip some tests,
but to choose between two alternatives.  In that case, we wouldn't want
to show an "UNTESTED".  On the other hand, if you can confirm that all
current uses of can_spawn_for_attach are for simply skipping tests, then
it's probably fine.

To make it non-ambiguous, we could rename can_spawn_for_attach to
skip_attach_tests, very similar to the skip_python_tests procedure.
Then it would be clear what it is for (skipping attach tests if attach
is not supported by the target).  And skip_python_tests does show an
"UNSUPPORTED" if Python support is disabled, so it would makes sense to
do the same for attach.

I think that "unsupported" is more accurate than "untested" in this
case:

https://www.gnu.org/software/dejagnu/manual/untested-procedure.html
https://www.gnu.org/software/dejagnu/manual/unsupported-procedure.html

> ---
>  gdb/testsuite/lib/gdb.exp | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index a3717a4..d15ab90 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -5063,6 +5063,7 @@ proc can_spawn_for_attach { } {
>      # 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 {
> +	untested "skipping tests due to is_remote target"
>  	return 0
>      }
>  
> @@ -5070,6 +5071,7 @@ proc can_spawn_for_attach { } {
>      # stub-like, where GDB finds the program already started on
>      # initial connection.
>      if {[target_info exists use_gdb_stub]} {
> +	untested "skipping tests due to use_gdb_stub"
>  	return 0
>      }

So I would suggest using:

  unsupported "skip attach tests (target is remote)"
  unsupported "skip attach tests (target is stub)"

That makes "skipping attach tests" the name of the test (identical in
both cases), and the part in parenthesis is additional details.  See:

  https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Do_not_use_.22tail_parentheses.22_on_test_messages

Simon

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-22 14:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-22 12:42 [PATCH v4 0/2] Modify can_spawn_for_attach Tiezhu Yang
2022-02-22 12:42 ` [PATCH v4 1/2] gdb: testsuite: print explicit test result in can_spawn_for_attach() Tiezhu Yang
2022-02-22 14:42   ` Simon Marchi
2022-02-22 12:42 ` [PATCH v4 2/2] gdb: testsuite: fix wrong expected result in attach-pie-noexec.exp 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).