[PATCH] gdb: testsuite: fix wrong expected result in attach-pie-noexec.exp
Tom de Vries
tdevries@suse.de
Tue Nov 23 08:25:16 GMT 2021
On 11/23/21 4:39 AM, Tiezhu Yang wrote:
> If /proc/sys/kernel/yama/ptrace_scope is 1, when execute 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 FAIL in such a case.
>
Agreed, PASS is incorrect, I suppose though that UNTESTED or UNSUPPORTED
would be better than FAIL.
Anyway, looking earlier in the test-case I see:
...
if {![can_spawn_for_attach]} {
return 0
}
...
and in gdb/testsuite/lib/gdb.exp I see:
...
# Return true if we can spawn a program on the target and attach to
# it.
proc can_spawn_for_attach { } {
...
So, is it not a more complete fix to make can_spawn_for_attach to return
false for this case? It would have to setup a small test-case, compile
it to exec, spawn it and try to attach to it. This is much more work
than it's currently doing, so it would have to become a
gdb_caching_proc. For an example, look for instance at
target_supports_scheduler_locking .
Thanks,
- Tom
> With this patch:
>
> (gdb) attach 6600
> Attaching to process 6600
> ptrace: Operation not permitted.
> (gdb) FAIL: gdb.base/attach-pie-noexec.exp: attach (please check privileges and try again)
> > When check this log info if failed, 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 to test
> $ 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 | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/testsuite/gdb.base/attach-pie-noexec.exp b/gdb/testsuite/gdb.base/attach-pie-noexec.exp
> index 85161fa..c029003 100644
> --- a/gdb/testsuite/gdb.base/attach-pie-noexec.exp
> +++ b/gdb/testsuite/gdb.base/attach-pie-noexec.exp
> @@ -59,7 +59,15 @@ 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"
> +set test "attach"
> +gdb_test_multiple "attach $testpid" $test {
> + -re "Attaching to process $testpid\r\n.*No executable file now.*\r\n$gdb_prompt $" {
> + pass $test
> + }
> + -re "Attaching to process $testpid\r\n.*ptrace: Operation not permitted\\.\r\n$gdb_prompt $" {
> + fail "$test (please check privileges and try again)"
> + }
> +}
> 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.*"
>
>
More information about the Gdb-patches
mailing list