From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 7BA73385EC57 for ; Wed, 16 Mar 2022 09:58:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7BA73385EC57 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9BxgM_FtDFiiykKAA--.30780S4; Wed, 16 Mar 2022 17:58:30 +0800 (CST) From: Tiezhu Yang 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 Message-Id: <1647424709-23680-3-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1647424709-23680-1-git-send-email-yangtiezhu@loongson.cn> References: <1647424709-23680-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQAAf9BxgM_FtDFiiykKAA--.30780S4 X-Coremail-Antispam: 1UD129KBjvJXoWxCw1UJw4DtFWxtw4xKw17ZFb_yoW5Xr1xpF 42qr1FyF18WFyaqa43A395XFWFk340kry3C3yfJr4avFs5GryUWFy7tw4UAr13JrZ2v3W3 uanrZr43uF43AFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB0b7Iv0xC_KF4lb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI 8067AKxVWUXwA2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF 64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcV CY1x0267AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIE c7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I 8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCF s4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY02Avz4vE14v_GFWl42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1Y6r17MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUIHUDDUUUU X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Mar 2022 09:58:35 -0000 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 --- 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