From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2063.outbound.protection.outlook.com [40.107.93.63]) by sourceware.org (Postfix) with ESMTPS id D48583858D1E for ; Wed, 4 Jan 2023 11:15:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D48583858D1E 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=j6T2J+vGLoT9+gh7qy5RF08nYpoTCqhGh1oBVi0f3T5ocC4Btc8XlkqAHW0xhQ5x50OiiswAPBWUMt1Xk6AJN6UymIGW4RO0iQjcuWmBlbpq2jdLhMJAQOS9tMDcaq4hpTYID/Z0K5qyxNRkdP8+HV+rch6vjuzWfidQewPL5Fk0Qc8uJxnbEsWD51mWYPlOnX5jHhXp90rH0fvtp0I0ynp4sTFuyzD9SpEFLnGPwyA3qjlUTApOMfY3h8h8SgOQu0/O0bJnBfCtv5zye0p+E341MqBC4NC1PkdI0q7JcRzP8nW6fGvsVOrn1NIa9siQYINkir9wpCEemopF67m/Lg== 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=WchQZdlMxb23xzXceaxNIEdjPQwpfS7b/HLN6XLJhH8=; b=L7BMFhuS7Yv7V3S/V0FPFF8YSwfunE0ZFt9JN+oaX9pjEnIl3IwwvB3cxpRqeMOHBxeJXUhLhYkA4PO8xDQueRZBMblvk0WFg41eeTrfpflY+y4Ma0KxtYasFEJBaWtmsz6Sqp9kWiVfnEDPtrXWbI+ED1roy6+ivFte/Yb9F0ZSa6z738bbgPEId+lT974TJXe56koralrC8oI3FtkU2VQlnA1Js1QZkAyXH8RkH+Kck872lMxcomhOEvm8Vc20B/Wk3fko7rmQz0KpNcWS1t8fbpeB7hFZnbNgQDqCLeE0XFtl6Z4cUkO6BNU5ANv6Z7RKBsx41ZMZgk75mnEPcw== 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=WchQZdlMxb23xzXceaxNIEdjPQwpfS7b/HLN6XLJhH8=; b=cIKm7Y1UFVdy9k5rOfcXW9UKvG2TPl+ejaDzV7B1/v/8CzavSnPgf3RRwVDYCEHnCLkktq99KOXuGI0ASj9i+GMCMx7CR1HCNBY9uxghj6ogMq4/mHV6M2HzRrBd11sYVIJTrubFv4sIxOCQ533fPx9ZM7LJHt2la0ijnGyCdF0= 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 DS0PR12MB7874.namprd12.prod.outlook.com (2603:10b6:8:141::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Wed, 4 Jan 2023 11:15:54 +0000 Received: from DM4PR12MB5745.namprd12.prod.outlook.com ([fe80::5fc0:b696:455b:8330]) by DM4PR12MB5745.namprd12.prod.outlook.com ([fe80::5fc0:b696:455b:8330%3]) with mapi id 15.20.5944.019; Wed, 4 Jan 2023 11:15:54 +0000 Message-ID: <00f6488c-9289-6241-cb11-a7de1222aec5@amd.com> Date: Wed, 4 Jan 2023 11:15:48 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: [PING] [PATCH v4] gdb/gcore: interrupt all threads before generating the corefile To: gdb-patches@sourceware.org Cc: lsix@lancelotsix.com References: <20221206141248.2485033-1-lancelot.six@amd.com> Content-Language: en-US From: Lancelot SIX In-Reply-To: <20221206141248.2485033-1-lancelot.six@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: FR3P281CA0157.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a2::13) To DM4PR12MB5745.namprd12.prod.outlook.com (2603:10b6:8:5c::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5745:EE_|DS0PR12MB7874:EE_ X-MS-Office365-Filtering-Correlation-Id: 1a5ee9f2-efa4-4cf0-eafa-08daee450b84 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aNUqid+2NKfTzTcxd6cB9y5Ewn60l+Iaq8M8PfxphC84vIpIx1NaSWE3qYMrJA74K+SkuqffqSsdOclrm2CFYkJC+RD4sj9wAcuge9izBKREcgMsApNp0AP13zGNIFhYNr9L8TkoaaqBApAMFEEMQ7EHUZmIv+3Bj6sFONAFhBhdXTc9cBfrynRZRWY9bukB7m819IXYBe9zTX/NhEv5R5I56KyGLkiaQoaO92ccLDrp4LMqBaVF66UP68nuXctCdUW+NkpPNatHMRgQuqYD7FMXJtG8mmgFRDHJSMBQ05+pMCbCGhKcKmkBN0GfrAEi5HOqq2+g/T8ZX9ADlQGhkltDDOSC4kp82nrAbxHV68Cfyn83daKz00KO/2rr1MW7cr2cur9GjNxmK0Tu1ttcwOnunkLU99rfKpHCduJ1Y/0dWo+LczfkZqClDq8KpVu9N+MjGaM7Dams8BqHlwimaZ2S3scJK83Py3/ggKd4y03TPgbeiMWwf6ovWEFKWx/My/vw+jQBJkKHpml6usDpsAm42OG91iHVM4y4/yKisE1kTL7nGY9Hn4ay/JZK3f8js1UEsRl6QRnmjFZuNMs5ASHnppDArdS/4C29FxcARKKfNPwFRR5yNGRH0jRQCnApPzKydKytl+4Asd73qbnALSDrtS/NcCJ/7yBPJHRjdaLBF3q6oGekZsHBFmCAE2v+3uCDhflWRz6/zqtOD5LrrGJ52ZEHK8uejtdHDc8OPyNDMtmw031wb4H7QJXL0lsvfIxrKYQ5c9No/phrbtiu7anAdQM0QVtlX9w7m/Bthidmvi0WSKfgqcT3Xkw0IBE7 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)(346002)(396003)(376002)(136003)(366004)(39860400002)(451199015)(5660300002)(2906002)(30864003)(8936002)(41300700001)(4326008)(478600001)(8676002)(66899015)(316002)(66476007)(66946007)(6916009)(66556008)(6486002)(31686004)(966005)(6512007)(26005)(6506007)(6666004)(83380400001)(186003)(38100700002)(53546011)(2616005)(31696002)(86362001)(36756003)(2004002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?a2lmVGcrb3dzbFdOQjVzQUE2Q0dPMGd3VVJWNC9aV1VGd2ZQNFhSb1hhTndC?= =?utf-8?B?T3p4cWdYL1lwc3RIMU9ma1pLUFVhZDNPSCs3Rndkb3d6TEVDNzBsZTNkalNJ?= =?utf-8?B?UGk5djIxY1RFWTY0aW5FK1VjVllXeG5UQzhvTFRFTGZ0ZHhJQzNxb2hZNlU4?= =?utf-8?B?WnNFOGRzNE94RG5UUHNKWk10UStERDlHMjc3VWpWblM1Ym1vcFJPWDJSNmxF?= =?utf-8?B?OVZvUnRybTdiZXZWanRhQkRzTUdkVWRXdFcyeHN6dWkvL3lEY2tKZytxdTA1?= =?utf-8?B?dDk3SG9ZYWF6Nn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ZVc1OURtK1VmMFh2?= =?utf-8?Q?NX91FpfF19xVQ+4qPS5YK3ZZA?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a5ee9f2-efa4-4cf0-eafa-08daee450b84 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5745.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jan 2023 11:15:54.0854 (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: g1ImIlL1tS63YNoNPpV+79FfztCsVfbBDCdOBf13XNZcWME6BmLwzGMXfrQib0NJobwe++fmne34bdMJSzwg2A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7874 X-Spam-Status: No, score=-11.1 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 06/12/2022 14:12, Lancelot SIX wrote: > Hi, > > Here is a V4 for https://sourceware.org/pipermail/gdb-patches/2022-November/193861.html > > Noticeable changes from V3: > > - Updated NEWS and documentation following Andrew's recommendations. > - Fixed compatibility issues in the testcase. > - Followed Andrew's recommendations on the gcore_command changes. > > All feedbacks are welcome. > > 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. > > When testing this patch against gdbserver, it appears that using > stop_all_threads / restart_threads was not compatible with all-stop > targets. For those targets, we need to call target_stop_and_wait / > target_resume. The gcore_command has code to handle both > configurations. I could not use a RAII-like object to have a cleaner > way to restore the state at the end as the restore procedure could > throw. Instead, the procedure keeps track of which method was used to > interrupt threads so the appropriate method can be used to restore their > state. > > Tested on x86_64 on navite GDB and the native-extended-gdbserver board. > --- > gdb/NEWS | 6 ++ > gdb/doc/gdb.texinfo | 5 ++ > gdb/gcore.c | 30 +++++++++ > gdb/infrun.c | 16 ++--- > gdb/infrun.h | 9 +++ > gdb/testsuite/gdb.base/gcore-nonstop.c | 44 ++++++++++++++ > gdb/testsuite/gdb.base/gcore-nonstop.exp | 77 ++++++++++++++++++++++++ > 7 files changed, 176 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 c4ccfcc9e32..ab9c1dca1c6 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -155,6 +155,12 @@ set style tui-current-position [on|off] > > * Changed commands > > +gcore > +generate-core-file > + 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 5b566669975..afe4e0a2799 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -13654,6 +13654,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 threads > +are running when executing this command, @value{GDBN} stops the threads > +and resumes them 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 672bdf78736..8e17af5ee59 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,28 @@ 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 (inf->pid)); > + > + bool all_stop_was_running = false; > + if (exists_non_stop_target ()) > + stop_all_threads ("generating coredump", inf); > + else > + { > + all_stop_was_running = any_thread_of_inferior (inf)->executing (); > + > + if (all_stop_was_running) > + { > + if (!may_stop) > + error (_("Cannot stop the target to generate the core dump.")); > + > + target_stop_and_wait (ptid_t (inf->pid)); > + } > + } > + > if (args && *args) > corefilename.reset (tilde_expand (args)); > else > @@ -161,6 +184,13 @@ gcore_command (const char *args, int from_tty) > } > > gdb_printf ("Saved corefile %s\n", corefilename.get ()); > + > + if (exists_non_stop_target ()) > + restart_threads (nullptr, inf); > + else if (all_stop_was_running) > + target_resume (ptid_t (inf->pid), 0, GDB_SIGNAL_0); > + > + disable_commit_resume.reset_and_commit (); > } > > static enum bfd_architecture > diff --git a/gdb/infrun.c b/gdb/infrun.c > index c67458b30b6..9a4759d2d3c 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); > @@ -5857,18 +5854,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..690d3289873 > --- /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 *ignored) > +{ > + 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..4a240eb0872 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/gcore-nonstop.exp > @@ -0,0 +1,77 @@ > +# 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} {pthreads debug}] } { > + return > +} > + > +save_vars { GDBFLAGS } { > + append GDBFLAGS " -ex \"set non-stop on\"" > + clean_restart ${binfile} > +} > + > +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: c8ea5e409b02cf7fa848e44af74b2e8246ad03f1