public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tiezhu Yang <yangtiezhu@loongson.cn>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/3] gdb: testsuite: add new gdb_attach to fix attach-pie-noexec.exp
Date: Wed, 16 Mar 2022 17:58:28 +0800	[thread overview]
Message-ID: <1647424709-23680-3-git-send-email-yangtiezhu@loongson.cn> (raw)
In-Reply-To: <1647424709-23680-1-git-send-email-yangtiezhu@loongson.cn>

This commit adds gdb_attach to check various output of "attach" command,
and then use gdb_attach to fix the following issue.

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 |  4 +++-
 gdb/testsuite/lib/gdb.exp                    | 15 +++++++++++++++
 2 files changed, 18 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..9a1bafe 100644
--- a/gdb/testsuite/gdb.base/attach-pie-noexec.exp
+++ b/gdb/testsuite/gdb.base/attach-pie-noexec.exp
@@ -59,7 +59,9 @@ 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]} {
+    return 0
+}
 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.*"
 
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 8fafcc0..599e8cc 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5102,6 +5102,21 @@ proc can_spawn_for_attach { } {
     return 1
 }
 
+# Check various output of "attach" command.
+
+proc gdb_attach { testpid } {
+    gdb_test_multiple "attach $testpid" "gdb attach" {
+	-re -wrap "Attaching to process $testpid\r\n.*No executable file now.*" {
+	  pass $gdb_test_name
+	  return 1
+	}
+	-re -wrap "Attaching to process $testpid\r\n.*ptrace: Operation not permitted\\." {
+	  unsupported "$gdb_test_name (Operation not permitted)"
+	  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


  parent reply	other threads:[~2022-03-16  9:58 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 ` Tiezhu Yang [this message]
2022-03-16 14:03   ` [PATCH 2/3] gdb: testsuite: add new gdb_attach to fix attach-pie-noexec.exp 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

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=1647424709-23680-3-git-send-email-yangtiezhu@loongson.cn \
    --to=yangtiezhu@loongson.cn \
    --cc=gdb-patches@sourceware.org \
    /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).