From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2061.outbound.protection.outlook.com [40.107.212.61]) by sourceware.org (Postfix) with ESMTPS id 1E7E43858C53 for ; Thu, 14 Apr 2022 11:32:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1E7E43858C53 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gbHrYso49Ja7Mnxx+VMPWkV5PuosRVspXT1Lvonht5WfSb8Ms0U3ZWhnR1vvw4k/8bKsa0HznjauMy0xCWA4Ru9x2cP/AhS5JWaBxGeXV0Ue+IwL8OEcG7ehpzx74G2crdLjAstlP7/wMoxswpGYs7g/9gkgyC0I9NgrK6fEgsP1XvNowjeJDYtwUUxe8TAPXY5BYJ+eGX1HuJFuxKwXOCR0wDvTX3+Ng7pM+uytPTff3wXVmNBfAAgMbuGaVi5yIH4ZNQcv861cdH6BnG3hB+gvMTLitjHbhogC0iQ2rEnz8X13DdcumFqmusZvZ55OPn+StmXXXHyE/Z3VNrzv1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=A1pcCvcwTw2qk99BiQ8ZlO5zFja1lrUI+wZfpnJDams=; b=kFc6O3pEaxdSnRxCkO8W4XKUDRT1vJpYCJiSeM9VgFvVB5lDzyEaoXYmr/ohjX338M3Pz3cqw0c4sd+f+OCHeyS4Hm4TkoDLSb/LGgDGdWStv2HnC1KAO1h731/qXLXPIF4E+GFJFqZbUrey5Z9N2Dh4r3u+063zvPXwJo4k3Aqf8uP5MQLUv8kCQrl3kBJUjkWQghk4H9jAI8FxCxa0Sq2aN56MLyH9Ile3Ra+Aw6YooEWwgfkGGtLz7dbr5Qr/zaDP3Qy+DTwfW2p5TCI47KAcCQVGpcpEiD6cDicQtewqq4DniGAV0AAvIpQNU7Lbrx6zwXx4xK1V4ivMdgdkUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sourceware.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from DS7PR03CA0183.namprd03.prod.outlook.com (2603:10b6:5:3b6::8) by SJ0PR12MB5673.namprd12.prod.outlook.com (2603:10b6:a03:42b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Thu, 14 Apr 2022 11:32:30 +0000 Received: from DM6NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b6:cafe::e1) by DS7PR03CA0183.outlook.office365.com (2603:10b6:5:3b6::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.30 via Frontend Transport; Thu, 14 Apr 2022 11:32:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT031.mail.protection.outlook.com (10.13.172.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5164.19 via Frontend Transport; Thu, 14 Apr 2022 11:32:29 +0000 Received: from khazad-dum.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 14 Apr 2022 06:32:28 -0500 From: Lancelot SIX To: CC: , Lancelot SIX Subject: [PATCH] gdb/testsuite: Introduce and use gdb_spawn_attach Date: Thu, 14 Apr 2022 12:32:10 +0100 Message-ID: <20220414113210.363239-1-lancelot.six@amd.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a39693d4-5ef4-4ac4-6fd4-08da1e0a75b9 X-MS-TrafficTypeDiagnostic: SJ0PR12MB5673:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Unr4yQSNeF6FSQ1VLsstrXrob0WK8F9sn/w6Yk2FeXqkvafy1gswpcIiv7o5fqXHruIHOVGEQ/TaUj4B1rD8opdd083IR+oGFEfUuwNCgx7ZKt7EwG48Amp4A8gJyCVC8t4K2ROrc5kMberh3GyyiVr+d5gbBBDE24NbC8D+JrXRWEIrTysIbRH+OW4RSGcELAZmrzC+bTlp3M9SyWnvEglbutWas4Mmc7qe4gZbTpf/lbjYN8IYyWyIjVCFIs8IJIqcXHjomoYGPVbds+75ESi60X0Xd2tRg0r0j51uGyrGgL1RO8q8nPZbrvd6U3kJZyF+LL6THsu+lcGFLaBVXJhXNR2KwHpZzPUIg7oNWlQzSxuDZ1xMOhpMwi6g82jg9I6C02tnPx4upeSnH5Uk9Rjjg8foA1wnZ7LNloN9g13h4BVHnixVlSGCIDekZUpsIeNktvKJUrNdzvFFqq7CEDDkH3Y8f/5uCM+bv8ej2PwDBoVRscTKuoRTzyd0GYEvQ0Dhn4fOeTk5BM1p4MXvdd1kAOCnBUFI07Mhy07ewkfVPczHavRp8/iOXLWsJ3wiwBkaLdhp8oT+fTtENjMMhaF0emqfacC9QLUfOTQNdRrtV3dv7cDDAJ41YD6zNCrSx2fG6TlH/NvpDJPIC+bEYVlvO4rDMA4FMhmbKze1/EFm08TjQPsH8gmpMlONh6HJfMmAEItmHFUH5Lu7CnGkcnPg97Bm37FvYsnWRX3RWRCCnwxmK/WAGGz+XebVhwMwZfrrNXizpUY1iQR+37SQmRQ2rRizi5BJNxQyQ4zLjUk= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(2906002)(84970400001)(316002)(426003)(54906003)(5660300002)(356005)(70586007)(4326008)(8676002)(16526019)(36756003)(82310400005)(508600001)(36860700001)(336012)(40460700003)(6916009)(2616005)(47076005)(26005)(186003)(81166007)(70206006)(1076003)(8936002)(7696005)(83380400001)(6666004)(86362001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2022 11:32:29.8846 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a39693d4-5ef4-4ac4-6fd4-08da1e0a75b9 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5673 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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: Thu, 14 Apr 2022 11:32:35 -0000 Hi, In a downstream port of GDB, I have tests which run `gdb --pid=$PID`, and have to support ptrace restrictions as it was introduced in a7e6a19e87f3d719ea23c65b580a6d9bca4ccab3 for the attach command. As there is a similar testcase in gdb.base/attach.exp, this patch proposes to add the gdb_spawn_attach helper method to factorize the error handling. All feedbacks welcome, Best, Lancelot. --- Following a7e6a19e87f3d719ea23c65b580a6d9bca4ccab3 "gdb: testsuite: add new gdb_attach to check "attach" command", this commit proposes to introduce the gdb_spawn_attach helper and use it in gdb.base/attach.exp. This helper starts GDB and addr the "--pid=$PID" argument. Tested on x86_64-gnu-linux Change-Id: I1fdcdb71c86d9c5d34bb28fc86fac68bcec37358 --- gdb/testsuite/gdb.base/attach.exp | 8 ++---- gdb/testsuite/lib/gdb.exp | 45 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/gdb/testsuite/gdb.base/attach.exp b/gdb/testsuite/gdb.base/attach.exp index d01060aba53..3869a7b06e8 100644 --- a/gdb/testsuite/gdb.base/attach.exp +++ b/gdb/testsuite/gdb.base/attach.exp @@ -467,13 +467,9 @@ proc_with_prefix do_command_attach_tests {} { gdb_exit - set res [gdb_spawn_with_cmdline_opts \ - "-quiet -iex \"set height 0\" -iex \"set width 0\" --pid=$testpid"] set test "starting with --pid" - gdb_test_multiple "" $test { - -re "Reading symbols from.*$gdb_prompt $" { - pass "$test" - } + if { [gdb_spawn_attach $testpid] } { + pass $test } # Get rid of the process diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 7c35fbb18c4..fbab5a930b5 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -5172,6 +5172,51 @@ proc gdb_attach { testpid args } { return 0 } +# Start gdb with --pid $TESTPID and wait for the prompt. Return 1 if GDB +# managed to start and attach to the process, 0 otherwise. + +proc gdb_spawn_attach { testpid } { + global gdb_prompt + + if { ![isnative] } { + unsupported "spawn with --pid" + return 0 + } + + set res [gdb_spawn_with_cmdline_opts "--pid=$testpid"] + if { $res != 0 } { + return 0 + } + + gdb_test_multiple "" "spawn --pid=\$pid" { + -re "ptrace: Operation not permitted\\." { + untested "$gdb_test_name (operation not permitted)" + return 0 + } + -re "ptrace: No such process\\." { + fail "$gdb_test_name" + return 0 + } + -re "Attaching to process $testpid\r\n.*\r\n$gdb_prompt $" { + pass $gdb_test_name + } + } + + # Check that we actually attached to a process, in case the + # error message is not catched by the patterns above. + gdb_test_multiple "info thread" "" { + -re "No threads\\.\r\n$gdb_prompt $" { + fail $gdb_test_name + } + -re "Id.*$gdb_prompt $" { + pass $gdb_test_name + return 1 + } + } + + 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. base-commit: 75b2a443d515f531299ce1ed942810edd5bf5d84 -- 2.25.1