From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2086.outbound.protection.outlook.com [40.107.223.86]) by sourceware.org (Postfix) with ESMTPS id 75C79385B525 for ; Fri, 10 Feb 2023 14:36:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 75C79385B525 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=i77IaaA3iONXWbeRryNtTy+43DrgI8ZnFlrR6BAD97YvWV7tpuMwz6AVApumIJAhZ1wj3tq67mWazFiWH5Ihf1E9pRRxOPpAu7/5IIZFqzOj8CgUlbsa1Fe1ja1lycOBOjvuZ5xBP2Vs3ayEb4lmfLysTibDwOtY8Hy85Lpfr8MIqi4gkAHk+Xpqq9L1WBhj0bWVpusj4rqoxnUyS0b13+U01ZM3Vi8okE4HDsoK9Hq43HI4ZgxKhC+o1a6bycq9JZ4RIu51IyOoaEWwQgfrseOYPy0SNwDwt6hs1fq0ufaYEQGIXBMUlvLMvTvA4zC0nlyHbmH/Bpm9N6tGXeAofg== 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=ztcCDnCXLPmjUUsdVcskjnruKczzAhz/LWPpfBzsMd4=; b=VquppJa5MxxThC3AXKsz7cS59dFaZMs0xG1hUVqddf1tW+JvbvAqY9J+Z5wVtNjZCtEVpJGCTbXnuo3QEyr9K+8MYHysSqLjfLr2jaSMVlUBvYuhBvh15vRCLff2bTt71AcK5NlPA7C5KD1Rmh2XccIqa9+ZT6MpbLSlNSXB74oVXO2jme9alOQM9X3OzuRRNyufhfuzKSPcinl5tL6vh0L1fOftz4Lxsk5iZ8Cvj+AVlB94R/ViSrXE/4RRdSk9MyLOTyzPE8Mk1nIwXz2hvn11fwfe6NNK1adf3ODOR5cg8T+qvEK/Vbc/dnfqpmTpjKNF4YGHlMzPOejs30C3ig== 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=ztcCDnCXLPmjUUsdVcskjnruKczzAhz/LWPpfBzsMd4=; b=gX6J8hl7kf7ns/6K+zoprLTxkqrTxMe0MpiRwD8qftIbwRVrW++suPixtT5UMZAAj1CrQA0SIetAtYnV573YtR9KWWk5cBvER6oan7sDyt8ZPQpnJrBNBV+JQnzGlf/1Y6feNZ5o+ZAeQBExm9UPVB8KB39My+L1QkBXCMINhig= 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 SA1PR12MB6995.namprd12.prod.outlook.com (2603:10b6:806:24e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.19; Fri, 10 Feb 2023 14:36:20 +0000 Received: from DM4PR12MB5745.namprd12.prod.outlook.com ([fe80::cc16:a119:c3cf:5236]) by DM4PR12MB5745.namprd12.prod.outlook.com ([fe80::cc16:a119:c3cf:5236%5]) with mapi id 15.20.6086.017; Fri, 10 Feb 2023 14:36:20 +0000 Message-ID: Date: Fri, 10 Feb 2023 14:36:15 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: [PING] [PATCH v5] gdb/gcore: interrupt all threads before generating the corefile Content-Language: en-US To: gdb-patches@sourceware.org Cc: lsix@lancelotsix.com, simark@simark.ca References: <20230130165110.1440365-1-lancelot.six@amd.com> From: Lancelot SIX In-Reply-To: <20230130165110.1440365-1-lancelot.six@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: FR0P281CA0087.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::12) To DM4PR12MB5745.namprd12.prod.outlook.com (2603:10b6:8:5c::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5745:EE_|SA1PR12MB6995:EE_ X-MS-Office365-Filtering-Correlation-Id: 828629e3-4e2c-4081-7b00-08db0b742d2e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SDBFJ6nVkRontmn7eVsoK8QZheSI1E3jwn+0U310d0K5OQPP1uV8JXqnRao7BogaDqSMXvodXPbWb+4Ldh2Nl1uzP+qByhxmlqpw1DCOV1wiNRk3fiO95YwBNQYaX8ZBDmfqQ7fseYD/FOBD3T5m/5vja0ZedeRiIzDPJr0vZuwnwMyDS9Id7K9eoQoOGMBroSg+/RTfQ3VGcRYDz/pBzLPelBEIcPooWpUjRoKKgXQ4YclgKbvV1DQk8Ihz0kqlg++dM8XOUUBIYW+Ft/xr21DrE6wrkbl2CaMspmr2HJcCDKQcilT5JgC+j+U0yhvhM94+YO7FDGvHgYiNmB+ODGzAoofaDMyWk0nHuEu+xCcKZogC5xlNNHaZGu2rYDHP0ehDyI/0YYHtnUgoh52SgGq2AYIGYc2Vt6tDY3iIqAx/+uJQB8Djdsz1D3j2Tiwl/wFj2qVL7/GcU8MDA1aYx3YK6Z5d9TnImocU06trdLVQgvn7KDgNwuNKMybSKJq3TTUj34S9HdAqkoXaAl6ImPxidrvzLRYx1eUhBl/V9aueHP6RMSAhDp4nA82raJ5+b7l9+Yf5tEg/Npj8X60QULPCpJcKXfDRCxy5XZ9Q4+1qZy3zayKro2ItWSNknsgPPTSS9pmm0ZHOG9ZQ1m8SQZqpkKrtX1k5+h7egHaKLyNjj2Z5xJ9+1PYIztaw/ReNZ6iy9ClHmfT35+4TD1H3Yh/W7XyDY4d+K7s/DaXTtbHwv5JzC6wOUSKjdKV6oFqEKQ+7mzqdOf1prN7ZhphMl/7iPqluOdAwGsSj2+SxP4do1uY8VJ4uqEBshvqQ3iK6 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:(13230025)(4636009)(346002)(366004)(39860400002)(396003)(376002)(136003)(451199018)(53546011)(6916009)(8676002)(6506007)(66476007)(66556008)(66946007)(83380400001)(6486002)(966005)(36756003)(478600001)(31696002)(86362001)(4326008)(316002)(2616005)(6666004)(2906002)(6512007)(186003)(26005)(5660300002)(31686004)(30864003)(8936002)(41300700001)(38100700002)(2004002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?WHp4blN6b3RSQTVKQ2E0dVNpa3BjTmlJL3pHbkZGUGh1aGtYK0RTaWxseGE2?= =?utf-8?B?YXgxaEszMzJmOHRSZGg4RWJnS2IyVW9lVWIvaGJKck9aejRrOWtRV25QcWl4?= =?utf-8?B?WG43Y3phZEx1RGxKell4Qkc0MnRLTm0xUHZhWmNadk9GRFB5N1FTeWVhclhj?= =?utf-8?B?UXBsZ2ZjdEk3Zno1cXpWSm9zSDlMQXhaZitrWlg0bkJPWWE2ZENnVE43ZmtI?= =?utf-8?B?QW9CekQvblQ5bkZ3K1oxNDNrRWdvcDhNY21RRkRmSnplUmRiR0x5RzFzbzdZ?= =?utf-8?B?N3Rqb094TjZ5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1NCMUhQSjhy?= =?utf-8?Q?3ASdOoSqo6ISnBscOxQ7IPIb8?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 828629e3-4e2c-4081-7b00-08db0b742d2e X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5745.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2023 14:36:20.7220 (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: U31J9h1NLBK383/ZhfF9Z/8zIT1wgny+rQZOTvlFJkRlRKjz5nOUlfVwDbLl683yE+SoHrjnzIL9P5WeyvDyMw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6995 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00,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 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: Hi, Kindly pinking. Best, Lancelot. On 30/01/2023 16:51, Lancelot SIX wrote: > Hi, this V5 follows > https://sourceware.org/pipermail/gdb-patches/2022-December/194504.html. > > Changes since V4: > > - Update gdb/NEWS to fall into the "Changes since GDB 13" section. > - Use "build_executable" instead of "prepare_for_testing" in the test > to avoid one useless start of GDB. > - Updated the test's description. > - Updated the copyright year to include 2023. > > 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 | 8 +++ > 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 | 79 ++++++++++++++++++++++++ > 7 files changed, 180 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 445d28efed9..7f78cbc9008 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -38,6 +38,14 @@ maintenance print record-instruction [ N ] > prints how GDB would undo the N-th previous instruction, and if N is > positive, it prints how GDB will redo the N-th following instruction. > > +* 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. > + > * MI changes > > ** mi now reports 'no-history' as a stop reason when hitting the end of the > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo > index 03033c7f9e3..c637d6eb114 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -13693,6 +13693,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 973abadb013..939737d83a1 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 edfb5ab0a91..0e6abc352aa 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 43fd1b44f5a..f6b04934bad 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..a96c011ad14 > --- /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-2023 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..172dd760e73 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/gcore-nonstop.exp > @@ -0,0 +1,79 @@ > +# Copyright 2022-2023 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 . > + > +# Check that in non-stop mode, if some threads are running when the user > +# launches the "gcore" command, GDB suspends all threads, generates the core > +# file and resumes threads which where running before the "gcore" command > +# got issued. If running threads were not stopped, GDB would report errors > +# when trying to capture the thread's state. > + > +standard_testfile > + > +if { [build_executable "failed to build" \ > + ${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 PC 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: 5867ab870b8aa36ae490ec6e4e8e4c55be11ccf1