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 5A5573857412 for ; Wed, 23 Feb 2022 02:45:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5A5573857412 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 AQAAf9DxCMq9nxVimUwFAA--.9808S4; Wed, 23 Feb 2022 10:45:17 +0800 (CST) From: Tiezhu Yang To: gdb-patches@sourceware.org Subject: [PATCH v5 2/2] gdb: testsuite: fix wrong expected result in attach-pie-noexec.exp Date: Wed, 23 Feb 2022 10:45:16 +0800 Message-Id: <1645584316-5375-3-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1645584316-5375-1-git-send-email-yangtiezhu@loongson.cn> References: <1645584316-5375-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQAAf9DxCMq9nxVimUwFAA--.9808S4 X-Coremail-Antispam: 1UD129KBjvJXoWxZr18AF47Xr4UKFyxCrW5GFg_yoW5Kr4kpF 4xtryFyF18Xa4aqa9xZ3y8XryFyry09345G3s7Jr1rZw4DGry8Kry3Kry5ZFnxJrWv93y3 ZwnFvr43CF1jyFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBYb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI 8067AKxVWUXwA2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF 64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcV CY1x0267AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv 6xkF7I0E14v26F4UJVW0owAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzV Aqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S 6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkIecxEwVAFwVW8JwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU5CYLPUUUUU== X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Spam-Status: No, score=-12.0 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, 23 Feb 2022 02:45:22 -0000 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 --- 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 7e064e2..7087162 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -5062,7 +5062,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. @@ -5079,6 +5079,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 } @@ -5128,12 +5164,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