From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2070.outbound.protection.outlook.com [40.107.237.70]) by sourceware.org (Postfix) with ESMTPS id E1D303858C5E for ; Tue, 1 Nov 2022 14:44:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E1D303858C5E 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-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bv2pNfmM1GIz+0Wb3bQANa1FsTPbhp5rPik0C7LF1bxx5b0EvL38G4gb99i22u7eySfs/Hr/Czv40a2efG8uV7HW8hDo65t7tGY7aoj9ZG5RFGesfpsGI1LoBznm3Mdd+S0JGKYNrONM2VF3HjywJm+etY0QFKQmD39/Foi3N8yx7y2vjHfKdlf7/kNsV8O7SxyO4r6PAqnAT+EUHH5h+LAWmCL4PrY+MCg0fpF5/fJk8M/eHq/Dmm9Aot62FHECZvnpUMz6pAjn8encug3+ktHKe9BgTFYBQEOm81Vi5r0vO84+uonMQPqZD64I4l/jTxgAN1rpqz5+CiEFz/pnBw== 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=4ptvvUWZ+rNPvIfdcptIf/LjeQtcVD1aaNB3WfVex4c=; b=j01x8f8MXv3X4vZ3K8XNzHjw8H+D8CHKjoPbDK26yI0gUnJlr0w9KmDwGFigEpl80IUUuq6UhGQD90HkBciotmuz4fNykTyeETQtnh90Wl2EtrC3G6BAsh6W0y49OxwbhyBswpgxqkW1lz0bNaow4pqEj+9/N9n5Tg/IgqL6tsnA7vQYdib6iEk+I6+3Gfpra2orIwFrU07WrO0GH7/CiWywMTu3UC/brSFF7WtIxy5J6vANpku8PwGGxu38TaeB2gf4o+KbInBVJgS3gO2LxWapZdmbIquTtYmMr6PFU1HJzSODvqPp/AzzG1DKWpE2wPSDLooTlboP0WcroE/SBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none 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=4ptvvUWZ+rNPvIfdcptIf/LjeQtcVD1aaNB3WfVex4c=; b=vl7xTz5VuK08lEjT/Rr0OYgckrdZQZrkivQZVQ6cpguTnFp5hS95fZFP4xaImKQwEexb3ZSUPppGbQJDajvpw8OcpHukhTTDjyr/yzkNSitGCsbz9GVt3/ZkL0le5lwrwOdpbMX/DCcN+Xeq+3RvB/Iqv3Iuu4D7HstJCRrerSA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM4PR12MB5745.namprd12.prod.outlook.com (2603:10b6:8:5c::7) by DM6PR12MB4402.namprd12.prod.outlook.com (2603:10b6:5:2a5::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.18; Tue, 1 Nov 2022 14:44:43 +0000 Received: from DM4PR12MB5745.namprd12.prod.outlook.com ([fe80::15e7:2ef7:ccc0:7f52]) by DM4PR12MB5745.namprd12.prod.outlook.com ([fe80::15e7:2ef7:ccc0:7f52%7]) with mapi id 15.20.5769.015; Tue, 1 Nov 2022 14:44:43 +0000 Message-ID: <2078a1b5-0968-578b-d700-717e4ab0d1b8@amd.com> Date: Tue, 1 Nov 2022 14:44:37 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: [PING][PATCH v2] gdb/gcore: interrupt all threads before generating the corefile To: gdb-patches@sourceware.org Cc: lsix@lancelotsix.com References: <20221017134335.385594-1-lancelot.six@amd.com> Content-Language: en-US From: Lancelot SIX In-Reply-To: <20221017134335.385594-1-lancelot.six@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: FR0P281CA0043.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:48::8) To DM4PR12MB5745.namprd12.prod.outlook.com (2603:10b6:8:5c::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5745:EE_|DM6PR12MB4402:EE_ X-MS-Office365-Filtering-Correlation-Id: 4f0f3226-daa1-41c9-cb57-08dabc179d12 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PfZWeM2VQ9EFThY903Unla9t19LW1gbpGAUJZ5dV0G38/2tTmMsoztx5G4plDh3Na0JOD+J5g5WORwy4LPx9N9ukCVZ9Qoz82tow1RSBzo4R1cJunKWrK64is47RyMeoFn8bnUmmdLQQRFo4qN8T9RqE/9Q64/t9hYknvfRLQklugWlja72dLdFjCxXTF4ED3TDwLkBuqmd8hjMJtpqQ7jFSSQOy61+UeT3mz0ewVD/tuYMjnZaaUqNx214Lp1x3P1GFuCNyOpzl7YmIGiKb0N5mECI/q8xZFxTixWB73dRQaryB9FECZ2DcbaxlOHekMW63tsh09h/NcgJYsMZSsheh+8v8L1nGbc87Cm+txX8mqhwRNo8/my1i/eeyK9ZmPBdFB4jZVkGDddXCR3i6ePTwd9KCIWiCVTz0Ahdzfsig5gIt7CyDmolJFqNBgowSyV91PRXgj1zjhb1GNPnqA0Nps+SpvRln5LlORU9zaBTDRRrCUj8kLyNQm9HUYa+mpV3t2iTe4v0lpgbidcEqkv7ClP7Z27DRbNXkOSJAhF6gP1Kec3w64fkXHkBosxcqtj9XCtxJuJvy+F41I1UpUuZPFdAreSX5nMUCq1LWWCuGDE7rrNPoBQi+OAUEqfeW4Jiyrc3jmCGotIV5KzaPG4XCpj9JFB7oyw4HE51iM3lcCHC6Ews3s4Wpekei+DMRTmI9rV8rujnn+nFr8CIKshp8KVGWdn8c/Vk/KN3Wh5sulRHWiBc4CEKfOWe/6St08zvARtIyRSoLwZZ1v+M7kBuVCg925bZ6LSYpIYK6ejWBYKd01ikgyZNK8ZK2lhG+N/OLauefJugSMEo+rmuVzydaeDFVaGw5nefmoxN98jI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR12MB5745.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(136003)(346002)(39860400002)(366004)(451199015)(478600001)(6666004)(6486002)(31686004)(966005)(6916009)(316002)(31696002)(86362001)(6506007)(66946007)(8676002)(4326008)(66476007)(53546011)(66556008)(2906002)(186003)(2616005)(6512007)(41300700001)(5660300002)(30864003)(38100700002)(36756003)(83380400001)(8936002)(2004002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?d0pmOXIxNDkvOVF5VjVyRjVrZVk3dmhhNUdKU3NjL01RaHFNVVJGdEx4MXZZ?= =?utf-8?B?RWRWOVAvUUROMVV4YUUzajNRSFJqa1liZGVUc2t1c0p1K2tDWUZvWEdGVTJO?= =?utf-8?B?OFh5RlFzcVRBdGIyUVhndWFtSUdvNFltNCszb2trL0dBNHJqV1Y3MmtsV0lD?= =?utf-8?B?NzBZUjU1cmFjcEtZTFcxenZkNDlIaWZQOUxjZUNVQWUwdkx6TnFzU2pPVkdM?= =?utf-8?B?c3lwMGZOODVRS1hYVlNkeThiMmZCbGlnd1A5d3V1bXpQcWZoRHNZbkcvMm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DWnFZOGg1c0pXQzdmNHFxN3hqVFJB?= =?utf-8?B?NjZTUkdsNldpMlkrdVlDVlRpa3p4Vm9HZFRRUDMyTjNKTlpTWWV0M04yY2k4?= =?utf-8?Q?FWeJOHQVDPyU6jKAO4YJXuBOlo855zbKRs775HCybeQH?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4f0f3226-daa1-41c9-cb57-08dabc179d12 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5745.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2022 14:44:43.3901 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fyIhXXPGzKaJj7+BrkdwvfIQfNpb11vN3fimic3+jx3AUfgvuOBuSOzNBgv73DzVUUb2bIKfEq2T1CjvjnEP9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4402 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Kindly pinging. Best, Lancelot. On 17/10/2022 14:43, Lancelot SIX wrote: > Hi, > > Here is a V2 for https://sourceware.org/pipermail/gdb-patches/2022-October/192420.html > > Changes since V1: > > - Fixed typos reported by Pedro. > - Used scoped_finish_thread_state in gcore_command to avoid leaving > threads in an inconsistent user-visible state in case of error. > - Added a NEWS entry and updated the documentation to reflect the > new behaviour. > - Improved the testcase to check that the thread which was stopped > before calling `gcore` remains stopped at the same spot after the > gcore command is finished. > > Best, > Lancelot. > > In non-stop mode, if the user tries to generate a core dump (using the > gcore command) while some threads are running, a non-helpful error > message is shown. > > Lets consider the following session as an example (debugging the test > program included in this patch): > > (gdb) set non-stop on > (gdb) b 37 > (gdb) r > Thread 1 "gcore-nonstop" hit Breakpoint 1, main () at gcore-nonstop.c:39 > (gdb) info thread > Id Target Id Frame > * 1 Thread 0x7ffff7d7a740 (LWP 431838) "gcore-nonstop" main () at gcore-nonstop.c:39 > 2 Thread 0x7ffff7d79640 (LWP 431841) "gcore-nonstop" (running) > (gdb) gcore > Couldn't get registers: No such process. > > The reported error ("No such process") does not help the user understand > what happens. This is due to the fact that we cannot access the > registers of a running thread. Even if we ignore this error, generating > a core dump while any thread might update memory would most likely > result in a core file with an inconsistent view of the process' memory. > > To solve this, this patch proposes to change the gcore command so it > first stops all running threads (from the current inferior) before > generating the corefile, and then resumes them in their previous state. > > To achieve this, this patch exposes the restart_threads function in infrun.h > (used to be local to infrun.c). We also allow the first parameter > (event_thread) to be nullptr as it is possible that the gcore command is > called while all threads are running, in which case we want all threads > to be restarted at the end of the procedure. > > Tested on x86_64. > > --- > gdb/NEWS | 5 ++ > gdb/doc/gdb.texinfo | 5 ++ > gdb/gcore.c | 11 ++++ > gdb/infrun.c | 16 ++---- > gdb/infrun.h | 9 +++ > gdb/testsuite/gdb.base/gcore-nonstop.c | 44 ++++++++++++++ > gdb/testsuite/gdb.base/gcore-nonstop.exp | 73 ++++++++++++++++++++++++ > 7 files changed, 152 insertions(+), 11 deletions(-) > create mode 100644 gdb/testsuite/gdb.base/gcore-nonstop.c > create mode 100644 gdb/testsuite/gdb.base/gcore-nonstop.exp > > diff --git a/gdb/NEWS b/gdb/NEWS > index 8b519a648f7..b448d0401a6 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -117,6 +117,11 @@ show debug infcall > > * Changed commands > > +gcore > + GDB now ensures that all threads of the current inferior are stopped > + before generating a core dump. At the end of the command, threads are > + restored to their previous state. > + > document user-defined > It is now possible to document user-defined aliases. > When a user-defined alias is documented, the help and apropos commands > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo > index 3de511a4844..c95d5c9bcf1 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -13570,6 +13570,11 @@ Produce a core dump of the inferior process. The optional argument > specified, the file name defaults to @file{core.@var{pid}}, where > @var{pid} is the inferior process ID. > > +@value{GDBN} ensures that all threads of the current inferior are stopped > +while generating the core dump. If any of the inferior's thread is found > +running when executing this command, @value{GDBN} stops it and resumes it > +when the command is done. > + > Note that this command is implemented only for some systems (as of > this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390). > > diff --git a/gdb/gcore.c b/gdb/gcore.c > index ede78534bd8..d64918fe983 100644 > --- a/gdb/gcore.c > +++ b/gdb/gcore.c > @@ -34,6 +34,7 @@ > #include "regset.h" > #include "gdb_bfd.h" > #include "readline/tilde.h" > +#include "infrun.h" > #include > #include "gdbsupport/gdb_unlinker.h" > #include "gdbsupport/byte-vector.h" > @@ -131,6 +132,13 @@ gcore_command (const char *args, int from_tty) > if (!target_has_execution ()) > noprocess (); > > + scoped_restore_current_thread restore_current_thread; > + scoped_disable_commit_resumed disable_commit_resume ("generating coredump"); > + struct inferior *inf = current_inferior (); > + scoped_finish_thread_state finish_state (inf->process_target (), > + ptid_t (inferior_ptid.pid ())); > + stop_all_threads ("generating coredump", inf); > + > if (args && *args) > corefilename.reset (tilde_expand (args)); > else > @@ -161,6 +169,9 @@ gcore_command (const char *args, int from_tty) > } > > gdb_printf ("Saved corefile %s\n", corefilename.get ()); > + > + restart_threads (nullptr, inf); > + disable_commit_resume.reset_and_commit (); > } > > static enum bfd_architecture > diff --git a/gdb/infrun.c b/gdb/infrun.c > index cdfe02393f5..b5bd6cb1902 100644 > --- a/gdb/infrun.c > +++ b/gdb/infrun.c > @@ -96,9 +96,6 @@ static void resume (gdb_signal sig); > > static void wait_for_inferior (inferior *inf); > > -static void restart_threads (struct thread_info *event_thread, > - inferior *inf = nullptr); > - > static bool start_step_over (void); > > static bool step_over_info_valid_p (void); > @@ -5889,18 +5886,15 @@ handle_inferior_event (struct execution_control_state *ecs) > } > } > > -/* Restart threads back to what they were trying to do back when we > - paused them (because of an in-line step-over or vfork, for example). > - The EVENT_THREAD thread is ignored (not restarted). > - > - If INF is non-nullptr, only resume threads from INF. */ > +/* See infrun.h. */ > > -static void > +void > restart_threads (struct thread_info *event_thread, inferior *inf) > { > INFRUN_SCOPED_DEBUG_START_END ("event_thread=%s, inf=%d", > - event_thread->ptid.to_string ().c_str (), > - inf != nullptr ? inf->num : -1); > + (event_thread != nullptr > + ? event_thread->ptid.to_string ().c_str () > + : "None"), inf != nullptr ? inf->num : -1); > > gdb_assert (!step_over_info_valid_p ()); > > diff --git a/gdb/infrun.h b/gdb/infrun.h > index c711b9b21cc..4cd98ec06c5 100644 > --- a/gdb/infrun.h > +++ b/gdb/infrun.h > @@ -175,6 +175,15 @@ extern void nullify_last_target_wait_ptid (); > all threads of all inferiors. */ > extern void stop_all_threads (const char *reason, inferior *inf = nullptr); > > +/* Restart threads back to what they were trying to do back when we > + paused them (because of an in-line step-over or vfork, for example). > + The EVENT_THREAD thread, if non-nullptr, is ignored (not restarted). > + > + If INF is non-nullptr, only resume threads from INF. */ > + > +extern void restart_threads (struct thread_info *event_thread, > + inferior *inf = nullptr); > + > extern void prepare_for_detach (void); > > extern void fetch_inferior_event (); > diff --git a/gdb/testsuite/gdb.base/gcore-nonstop.c b/gdb/testsuite/gdb.base/gcore-nonstop.c > new file mode 100644 > index 00000000000..191a1a26849 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/gcore-nonstop.c > @@ -0,0 +1,44 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2022 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 > + > +static pthread_barrier_t barrier; > + > +static void * > +worker_func (void *) > +{ > + pthread_barrier_wait (&barrier); > + return NULL; > +} > + > +int > +main (void) > +{ > + pthread_t worker_thread; > + pthread_barrier_init (&barrier, NULL, 2); > + > + pthread_create (&worker_thread, NULL, worker_func, NULL); > + > + /* Break here. */ > + > + pthread_barrier_wait (&barrier); > + pthread_join (worker_thread, NULL); > + pthread_barrier_destroy (&barrier); > + > + return 0; > +} > diff --git a/gdb/testsuite/gdb.base/gcore-nonstop.exp b/gdb/testsuite/gdb.base/gcore-nonstop.exp > new file mode 100644 > index 00000000000..d4cbf6cf3c4 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/gcore-nonstop.exp > @@ -0,0 +1,73 @@ > +# Copyright 2022 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 testcase checks that when in non-stop mode with some threads running > +# the gcore command can interrupt all threads, generate a core dump and > +# restart threads as required. > + > +standard_testfile > + > +if { [prepare_for_testing "failed to prepare" \ > + ${testfile} ${srcfile} {threads debug}] } { > + return > +} > + > +gdb_test_no_output "set non-stop on" > +set lineno [gdb_get_line_number "Break here"] > +if { ![runto $lineno] } { > + return > +} > + > +# We should be stopped in thread 1 while thread 2 is running. > +gdb_test_sequence "info threads" "info threads" { > + {Id\s+Target Id\s+Frame} > + {\*\s+1[^\n]*\n} > + {\s+2\s+[^\n]*\(running\)[^\n]*\n} > +} > + > +set th1_pc "" > +gdb_test_multiple "p/x \$pc" "fetch thread 1 PC" { > + -wrap -re "$::decimal = ($::hex)" { > + set th1_pc $expect_out(1,string) > + pass $gdb_test_name > + } > +} > + > +set corefile [standard_output_file "corefile"] > +if {![gdb_gcore_cmd $corefile "generate corefile"]} { > + # gdb_gcore_cmd issues a "UNSUPPORTED". > + return > +} > + > +# After the core file is generated, thread 2 should be back running > +# and thread 1 should still be selected. > +gdb_test_sequence "info threads" "correct thread selection after gcore" { > + {Id\s+Target Id\s+Frame} > + {\*\s+1[^\n]*\n} > + {\s+2\s+[^\n]*\(running\)[^\n]*\n} > +} > + > +# Thread 1 is at the same stop it was before calling the gcore command. > +gdb_test "p/x \$pc" "\\\$$::decimal = $th1_pc" "thread 1 unchanged" > + > +clean_restart $binfile > +gdb_test "core-file $corefile" "Core was generated by.*" "load corefile" > + > +# The core file has the 2 threads. > +gdb_test_sequence "info threads" "threads in corefile" { > + {Id\s+Target Id\s+Frame} > + {\s+1\s+Thread[^\n]*\n} > + {\s+2\s+Thread[^\n]*\n} > +} > > base-commit: e57f7fa070e16683c0e1ddd0d1307d243fad990d