From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id AfmxN94kXmYOnSUAWB0awg (envelope-from ) for ; Mon, 03 Jun 2024 16:17:34 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=ovbUKfXZ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CE5661E0C0; Mon, 3 Jun 2024 16:17:34 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 731E51E030 for ; Mon, 3 Jun 2024 16:17:32 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD9973954C55 for ; Mon, 3 Jun 2024 20:17:31 +0000 (GMT) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2087.outbound.protection.outlook.com [40.107.94.87]) by sourceware.org (Postfix) with ESMTPS id 422833857C4F for ; Mon, 3 Jun 2024 20:17:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 422833857C4F Authentication-Results: sourceware.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=amd.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 422833857C4F Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.94.87 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1717445830; cv=pass; b=vtye0CjpoUU1FItYOMXu09+RrwNucaH41kGL3W8+YOg7TWButT8gOw3GyqLnv3SRGKeismnU+pjQjXZWJXxwDw7yMj5ID6ituVqNleDLf6mKxdQ4AWGGS7a2O47aKxwrnUDiPg08GOqJkNZuJ7KFpo4wjbLygqdlveFBCoPcJnw= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1717445830; c=relaxed/simple; bh=gUgpWFfyAlVam5LKKrYYIYlM9jgBFVxpE0QcLYboJbs=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=CX94+oV2oEHTKxhds7TrUzTAZ36PRdT7PZlIGb51ZfttQ8XuwOG8JZaktyxNjckgeWLvIqAAzb7eMzGYiVe+KDkIjY9VwTxOQqbm3iAdnPa+nfR+QC1Triw2WhCvYN+9QXjVRdMVs5uW4AnU5BL3ojkx5n4N315N3+gAdzHCsn8= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hx9G5KXlLtc6491C2s+idEh3nN4vTweP3uwiFAMETyWPgLWTvOle7w8HKDPoNT5HUHqnN2TjPmUjBU8/1smmortUm+K7RjfUMUgs0F8EogsYoccIoMJ+/xJyr9wg8NX9N6nRtbBGreN2ikjTwIq1KRqONxXOXYFRxMhJBK4cmtfd+s2s9K3KkIG0YA6NmnMli7g0IxYgY2hlOSeynjv1/bYHCrO9w5WqMn8oG4Q0J1GFbCEcbPQWH8uZqwXDSJUu58/KlO6VjbSS88TB/GYAkKZ99zTxkcjy8E9HJZ/DMaoc7WjSe+HAFxFGna7QjWPD7nmn7uoAA6TY8LqdZcXqDQ== 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=/VW6kwAHYQ+vOp1cVAoFZoAvKpHX6Qc6aXewGDSX8kM=; b=cKKdFlHGWqQ5DL5LlbJMSB1KDiTOWm259LBq6+ZhwWvyjp/B/iGiNhOAILQci302boYbcxQ70gG/kOB88BA9aihTb1bGKsxJkRb+Tf1siHqpF5RQ3q+EJzmorokTCDztSiOu8laqwwzX2UfX4ktJpH9ntMH/jDraWUzCoVthGc6R+ugpe3zG9KwslMLBokMDa2gj9/oFYOmfWZsy0++A9rGApd1AQGNGPWeJqeZDNohofaProd9x5lwULlo7NWLBOnXRCGKSbHo81r6AsKrpbmx3XNKNQapPSgJGlXpKqoZiX5KvLwCZhfIotFR+cXiLZsweAKpjSC5TDPNZTG5AaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=khirnov.net 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 (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/VW6kwAHYQ+vOp1cVAoFZoAvKpHX6Qc6aXewGDSX8kM=; b=ovbUKfXZefMP+KirPRH9ok7RYIHAqnhPRVbmA3dOYGPZQDDnohWA9K5dZmCePydY5hg/h+KS3UbKZEFsp8N/m9v+7xc5hCqON/nrK2wGA9oazIbHtG7bojlfMcprzWxCskEx3phIGg8x1ZlM+3bEwvXdaDNeKcdMrOro0f6KeAA= Received: from CH0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:ef::9) by LV3PR12MB9258.namprd12.prod.outlook.com (2603:10b6:408:1bb::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22; Mon, 3 Jun 2024 20:17:02 +0000 Received: from CH1PEPF0000A346.namprd04.prod.outlook.com (2603:10b6:610:ef:cafe::39) by CH0P220CA0013.outlook.office365.com (2603:10b6:610:ef::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55 via Frontend Transport; Mon, 3 Jun 2024 20:17:02 +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; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CH1PEPF0000A346.mail.protection.outlook.com (10.167.244.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Mon, 3 Jun 2024 20:17:02 +0000 Received: from khazad-dum (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.2507.35; Mon, 3 Jun 2024 15:16:59 -0500 Date: Mon, 3 Jun 2024 21:16:52 +0100 From: Lancelot SIX To: Alexandra =?utf-8?B?SMOhamtvdsOh?= CC: , , Jan Kratochvil Subject: Re: [PATCH v6] Add a test for the gcore script Message-ID: <20240603201541.g5ly35xlknqamnvq@khazad-dum> References: <20240602155100.533195-1-ahajkova@khirnov.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240602155100.533195-1-ahajkova@khirnov.net> X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000A346:EE_|LV3PR12MB9258:EE_ X-MS-Office365-Filtering-Correlation-Id: c723ed25-1036-44e1-9441-08dc840a2139 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL: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bGVUVzd1WldVa0d4cDZH?= =?utf-8?B?ZHJBNDdVU3pLNHg0OXROc0RuSTVWQktLamhLb01DUGpZUXpmVnJUZE43TkMy?= =?utf-8?B?bTA4UjZRb3dNZG05MEt0dz09?= 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:(13230031)(36860700004)(1800799015)(376005)(82310400017); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2024 20:17:02.1259 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c723ed25-1036-44e1-9441-08dc840a2139 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: CH1PEPF0000A346.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9258 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org On Sun, Jun 02, 2024 at 05:50:59PM +0200, Alexandra Hájková wrote: > From: Alexandra Hájková > > It also tests the gcore script being run without its accessible > terminal. > > This test was written by Jan Kratochvil a long time ago. I modernized > the test making it use various procs from lib/gdb.exp, reorganizing it > and added some comments. > > Modify the gcore script to make it possible to pass the --data-directory to > it. This prevents a lot of these warnings: > > Python Exception : module 'gdb' has no attribute > '_handle_missing_debuginfo' > > Tested by using make check-all-boards. > > Co-Authored-By: Jan Kratochvil Hi Alexandra, If I run this testcase with `sysctl kernel.yama.ptrace_scope=1`, I have: Running ..../gdb/testsuite/gdb.base/gcorebg.exp ... FAIL: gdb.base/gcorebg.exp: detached = standard: Spawned gcore finished FAIL: gdb.base/gcorebg.exp: detached = standard: Core file generated by gcore FAIL: gdb.base/gcorebg.exp: detached = detached: Spawned gcore finished FAIL: gdb.base/gcorebg.exp: detached = detached: Core file generated by gcore The log is: PASS: gdb.base/gcorebg.exp: detached = standard: Spawned gcore ptrace: Operation not permitted. You can't do that without a process to debug. The program is not being run. gcore: failed to create ..../gdb/testsuite/outputs/gdb.base/gcorebg/gcorebg.core.275084 FAIL: gdb.base/gcorebg.exp: detached = standard: Spawned gcore finished FAIL: gdb.base/gcorebg.exp: detached = standard: Core file generated by gcore I think you can avoid this by using require can_spawn_for_attach I do have minor remarks inlined in the patch as well. > --- > v6: > - fixed typos > - used Jan Kratochvil's old invalid email for the record > - improved the "usage" message > - fixed has_gcore_script proc > > gdb/doc/gdb.texinfo | 2 +- > gdb/gcore.in | 12 +++- > gdb/testsuite/gdb.base/gcorebg.c | 86 +++++++++++++++++++++++++++++ > gdb/testsuite/gdb.base/gcorebg.exp | 88 ++++++++++++++++++++++++++++++ > gdb/testsuite/lib/gdb.exp | 18 ++++++ > 5 files changed, 202 insertions(+), 4 deletions(-) > create mode 100644 gdb/testsuite/gdb.base/gcorebg.c > create mode 100644 gdb/testsuite/gdb.base/gcorebg.exp > > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo > index 750f368f980..67edfdaf800 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -50984,7 +50984,7 @@ Richard M. Stallman and Roland H. Pesch, July 1991. > > @format > @c man begin SYNOPSIS gcore > -gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}] > +gcore [-a] [-o @var{prefix}] [-d @var{path}] @var{pid1} [@var{pid2}...@var{pidN}] > @c man end > @end format > > diff --git a/gdb/gcore.in b/gdb/gcore.in > index 982c854eb70..0c40e5a54cd 100644 > --- a/gdb/gcore.in > +++ b/gdb/gcore.in > @@ -27,7 +27,9 @@ prefix=core > # to ensure gdb dumps all mappings (OS dependent). > dump_all_cmds=() > > -while getopts :ao: opt; do > +data_directory_opt=() > + > +while getopts :ao:d: opt; do > case "$opt" in > a) > case "$OSTYPE" in > @@ -40,8 +42,11 @@ while getopts :ao: opt; do > o) > prefix=$OPTARG > ;; > + d) > + data_directory_opt=("--data-directory" "$OPTARG") > + ;; > *) > - echo "usage: @GCORE_TRANSFORM_NAME@ [-a] [-o prefix] pid1 [pid2...pidN]" > + echo "usage: @GCORE_TRANSFORM_NAME@ [-a] [-o prefix] [-d data-directory] pid1 [pid2...pidN]" > exit 2 > ;; > esac > @@ -51,7 +56,7 @@ shift $((OPTIND-1)) > > if [ "$#" -eq "0" ] > then > - echo "usage: @GCORE_TRANSFORM_NAME@ [-a] [-o prefix] pid1 [pid2...pidN]" > + echo "usage: @GCORE_TRANSFORM_NAME@ [-a] [-o prefix] [-d data-directory] pid1 [pid2...pidN]" > exit 2 > fi > > @@ -98,6 +103,7 @@ do > # ` # available but not accessible as GDB would get stopped on SIGTTIN. > "$binary_path/@GDB_TRANSFORM_NAME@" + "${data_directory_opt[@]}" \ > --nx --batch --readnever -iex 'set debuginfod enabled off' \ > -ex "set pagination off" -ex "set height 0" -ex "set width 0" \ > "${dump_all_cmds[@]}" \ > diff --git a/gdb/testsuite/gdb.base/gcorebg.c b/gdb/testsuite/gdb.base/gcorebg.c > new file mode 100644 > index 00000000000..1e9ddbd8649 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/gcorebg.c > @@ -0,0 +1,86 @@ > +/* Copyright 2007-2024 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +/* Expects 4 arguments: > + > + 1. Either 'standard' or 'detached', where 'standard' tests > + a general gcore script spawn with its controlling terminal available > + and 'detached' tests gcore script spawn without its controlling > + terminal available. > + 2. Path to the gcore script. > + 3. Path to the data-directory to pass to the gcore script. > + 4. The core file output name. */ > + > +int > +main (int argc, char **argv) > +{ > + pid_t pid = 0; > + pid_t ppid; > + char buf[1024*2 + 500]; > + int gotint, res; > + int fd[2]; > + > + assert (argc == 5); > + > + if (pipe(fd) == -1) > + { > + perror ("pipe err\n"); > + exit (1); > + } > + pid = fork (); > + > + switch (pid) > + { > + case 0: > + close (fd[0]); > + if (strcmp (argv[1], "detached") == 0) > + setpgrp (); > + ppid = getppid (); > + gotint = snprintf (buf, sizeof (buf), "%s -d %s -o %s %d", > + argv[2], argv[3], argv[4], (int) ppid); > + assert (gotint < sizeof (buf)); > + res = system (buf); > + assert (res != -1); > + close(fd[1]); > + break; > + > + case -1: > + close (fd[0]); > + close (fd[1]); > + perror ("fork err\n"); > + exit (1); > + break; > + > + default: > + close (fd[1]); > + /* Wait here until the child is done with gcore-ing us. When the > + child has finished it will close its end of the pipe and this read > + call will return. */ > + res = read (fd[0], buf, 1); I guess in theory read could return -1 and errno be EINTR. I was wondering if there is a reason to prefer creating a pipe rather than using waitpid to wait for the child finish? > + assert (res == 0); > + close (fd[0]); > + break; > + } > + > + return 0; > +} > diff --git a/gdb/testsuite/gdb.base/gcorebg.exp b/gdb/testsuite/gdb.base/gcorebg.exp > new file mode 100644 > index 00000000000..5bcb547b9e1 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/gcorebg.exp > @@ -0,0 +1,88 @@ > +# Copyright 2007-2024 Free Software Foundation, Inc. > +# > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > + > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > +# > +# This is a test for the gcore script (not the gcore command from > +# inside GDB). It also tests the gcore script being run without its > +# accessible terminal. > + > +standard_testfile > +require {!is_remote host} > +require {!is_remote target} > +require has_gcore_script As mentioned above, I think you also need: require can_spawn_for_attach > + > +set corefile [standard_output_file ${testfile}.core] > + > +if {[build_executable "failed to build" $testfile ${srcfile}] == -1 } { > + return -1 > +} > + > +# Cleanup. > + > +proc core_clean {} { > + global corefile > + > + foreach file [glob -nocomplain [join [list $corefile *] ""]] { > + verbose "Delete file $file" 1 > + remote_file target delete $file > + } > +} > +core_clean > + > +# Generate the core file. > +proc test_body { detached } { > + global binfile > + global GCORE > + global corefile > + global GDB_DATA_DIRECTORY > + > + with_test_prefix "detached = $detached" { See below, I gues you could use foreach_with_prefix outside of this function which would be more "usual". > + # We can't use gdb_test_multiple here because GDB is not started. > + set res [remote_spawn target "$binfile $detached $GCORE $GDB_DATA_DIRECTORY $corefile"] > + if { $res < 0 || $res == "" } { > + fail "Spawning gcore" > + return 1 > + } > + pass "Spawned gcore" > + > + set saw_corefile_created false > + set testname "Spawned gcore finished" > + remote_expect target 20 { > + timeout { > + fail "$testname (timeout)" > + remote_exec target "kill -9 -[exp_pid -i $res]" > + return > + } > + -re "Saved corefile \[^\r\n\]+\r\n" { > + set saw_corefile_created true > + exp_continue > + } > + eof { > + gdb_assert { $saw_corefile_created } $testname > + } > + } > + > + gdb_assert {1 == [llength [glob -nocomplain [join [list $corefile *] ""]]]} "Core file generated by gcore" > + core_clean > + } > +} > + > +# First a general gcore script spawn with its controlling terminal available. > + > +test_body standard > + > +# And now gcore script spawn without its controlling terminal available. > +# It is spawned through `gcorebg.c' using setpgrp (). > + > +test_body detached Could be foreach_with_prefix detached { detached standard } { test_body $detached } > diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp > index cdc3721a1cd..25a9cec5c34 100644 > --- a/gdb/testsuite/lib/gdb.exp > +++ b/gdb/testsuite/lib/gdb.exp > @@ -158,6 +158,24 @@ load_lib gdb-utils.exp > load_lib memory.exp > load_lib check-test-names.exp > > +# The path to the GCORE script to test. > +global GCORE > +if {![info exists GCORE]} { > + set GCORE [findfile $base_dir/../../gdb/gcore] > +} else { > + set GCORE "" > +} > +verbose "using GCORE = $GCORE" 2 > + > +proc has_gcore_script {} { > + global GCORE > + if {$GCORE == ""} { > + return 0 > + } else { > + return 1 > + } > +} > + > # The path to the GDB binary to test. > global GDB > > > -- > 2.45.0 > Best, Lancelot.