From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2043.outbound.protection.outlook.com [40.107.101.43]) by sourceware.org (Postfix) with ESMTPS id 609013858D38 for ; Wed, 12 Oct 2022 17:12:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 609013858D38 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GVPs0JwXGYhaoMG0UOf658fBEMccvMzJIhwGhKCUtQ8uYg0zrKBVJ8srodwg9Yh30D7xuvjAav/53jxgjimbO2ewl1fZKIecuLWc+aQ87Wsd2paBXY74yGJLpCc0yixrluZ8LEGqVEre2FbhSrjZMuUj5/r5iWonY6wYFD9ntSvoO7WsPZFQfyMwsf9QIJUjjoClOCuLK0bZtADyBxuPfJr9TrNw03btdm8ckHCJjWqi6IAta6jMd6itLgM9x/HN9mmi+tFa83qUglhELgYRSwVUZEUBMIBpo08FN65t82IC7VkHOW17Hb0SnJAz5xFFHhTdIPEU/e4NhHOEqs9BBg== 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=kvZFr990b8pnOiCADK/+8D8wC8q+JWFN1Rgu7S7mqQ8=; b=Njkq/Xn4MX7l9IUm/j7JlHhY56AXo+Jb9GoN4sSMYpTb4KnBJ4jUDyTFLEopVkZXcxV+OGikRj2Yynw07UOW8uGx47o6fk6gSi1OHWOZpax5LY7FLKyUjrIi6WW+MDs+UEmPEGG0isfEWdO0qRfs8xnNckWRt6gkPKM4He/GRUdPZZGY4VYuv+AgvBq/z2GLhB4C53W1VNzq9UAzXKqE517bwSmBt/4ycobL69k3+/plgRSM2XzBk4l4Hbr5IFlyI/JEH19jHPNaVQJizJDIdjCdXGQCkaSZV5q0VW8Z/aLNSd6Q2FDnzxyEyTNHPRuHdIUchOv+UnngvQ5LBGZAYg== 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 Received: from DM4PR12MB5745.namprd12.prod.outlook.com (2603:10b6:8:5c::7) by SA1PR12MB5640.namprd12.prod.outlook.com (2603:10b6:806:238::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.22; Wed, 12 Oct 2022 17:12:37 +0000 Received: from DM4PR12MB5745.namprd12.prod.outlook.com ([fe80::5dd:2ee8:ac9a:d13d]) by DM4PR12MB5745.namprd12.prod.outlook.com ([fe80::5dd:2ee8:ac9a:d13d%4]) with mapi id 15.20.5676.040; Wed, 12 Oct 2022 17:12:37 +0000 Message-ID: <8b8ba97d-0103-98de-3b96-40c3969caaca@amd.com> Date: Wed, 12 Oct 2022 18:12:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH] gdb/gcore: interrupt all threads before generating the corefile Content-Language: en-US To: Pedro Alves , gdb-patches@sourceware.org Cc: lsix@lancelotsix.com References: <20221006095035.2857747-1-lancelot.six@amd.com> <556673bd-79ea-2216-bc94-a41e862b888b@palves.net> From: Lancelot SIX In-Reply-To: <556673bd-79ea-2216-bc94-a41e862b888b@palves.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AS9PR06CA0624.eurprd06.prod.outlook.com (2603:10a6:20b:46e::27) To DM4PR12MB5745.namprd12.prod.outlook.com (2603:10b6:8:5c::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5745:EE_|SA1PR12MB5640:EE_ X-MS-Office365-Filtering-Correlation-Id: 442fe2f8-94e8-4041-282b-08daac74f639 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: myqgReNQnldNtOamHEgQQ9b8glhfScXKhVvJNKX6xC1s/O1qYdoGGGTS/l8ly3cIdMGkfw2f3GPcSDT3tVRRhvL+NFh/LIbM3JZy8NF36/NCb8VJu8oOYNt003e7KFy5n/uwB0QOCOvaGtX+aMaTzgojKvanP/ndJjRNrJ9clh5sSMbYAYBGHBvVHdXbFrQ0OAXFcLR5MkUPfWwltBl6lBuePPS99sLCsCyqNGByGwsJGSvnNKl5degdwcbeeK2qyAXMevuI+DHOByBTvUdDt9XjkwwJpWI6tue4qaN0QT8t/oNEx9gNajAlVIfC9PZoCACm7ue8M+ibhNeuwDSl9geM9f83T7tvG/V7eUybmZa+KcbUaZpbU7nGipa3/6gyChqv73f2UI32bevgsNzW1qMHVk+bmZGg4Jt+QHyUFF+6u5DpKU9Uar5afxnEU+Yxk5RRkHwr85PF8dI/wNw/hhltFfxoLsjmcq1FKb6AGcItKq2piXhJAnh8w0bXktzihHF9ktIRNszrccWw5459cMmIFBuP6t+DzyHYNoMFFqJ465sB8fvI017eNnVN7DxCG/pqSLP8g1jY3y3RBYO+yG5fWcMS18NGHStQ8bNxcReOrFp6mhpa+/AbF6xtHym78ulUOeJ7LGV8Lk5mH0+5BHEe2YSqgfvzajD28OdLPca3Gn1yLzTkNPOvmw0mBVsrFL32So4xZz+jg4Kj7j6XwPunHsGmdD+5geX1a9lA+bsLPJriQECd3T18QP5Oufya7U5VMKHTyIxC5xOouUUyOAjNEg9VBZiRhDwd9A6ObB1dVpgjmCfW5/r7mM7BkamUEOnEG0S1TzZluoJZCtNnVQ== 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)(136003)(39860400002)(396003)(366004)(376002)(346002)(451199015)(31696002)(86362001)(36756003)(38100700002)(316002)(8676002)(4326008)(66556008)(66946007)(66476007)(45080400002)(2906002)(8936002)(41300700001)(30864003)(5660300002)(186003)(83380400001)(6666004)(6486002)(478600001)(6512007)(2616005)(6506007)(53546011)(31686004)(2004002)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?RzhjeDF4R0t5SWpadThReGdXY1lPZ3h3ellkZTVMOHFqYldEcFlORzYwbmJk?= =?utf-8?B?b0JySWpwK0dzRWY3b0NpbFArNlRKcy84amU1WGRmenNnaE94Q3Z3UjBzQWdC?= =?utf-8?B?Ynh0UGVPbGwyMWpqbEwzdlZKd1lxajcxSS9JOHh4dW5MSXBUT09yWktFTWhB?= =?utf-8?B?cDVZUkNmT0ZtNXorVkZVSDhKUml5NldtUzcxZCtSVGV1YXh5MzB0eHhzcnFt?= =?utf-8?B?VDJGSlVEeW42dGE2NW1aeWJwSjNZb0o0bzAzVGRwWjNqQnhXU2FVdnRWWE1t?= =?utf-8?B?MXpiR2swd1NTdGFDVURkOHIya2ZkaWFCZ0JhMDA5U3d4MUZzRW5qMzkwRitC?= =?utf-8?B?WDZDTk9vV01VaE1vbGY1emZZSmg3OXE3WkdnUjBxY2lkVzhOSStjZ0haMEpW?= =?utf-8?B?cVBpRFl3MDV1V2pCWTJaZkVBY2tiVDQySmFXby9OeTdrOThXRCtzRC80bUhD?= =?utf-8?B?SlRjK2lkTFJNMEQwSmJBNTRmdXowTHhhTVlDdmxuOWZ3VzlYOVptY1dMSElS?= =?utf-8?B?QVNYMFRGS21TUmlGYVZmOEVHeXYwS0RONklQbloxNWlTSTYwWXhHVi8zdTRy?= =?utf-8?B?by9GeUdMYlFUU1J1dUhreFRBTTlUVUxORHA5OUx6ZUxxZjlrY2o4UWIxRGov?= =?utf-8?B?UkNMdnVsaE15a01JMDI5dUdGQTVFdDhTOVhocW44d2xUWlN5UzlWK1JHNU9m?= =?utf-8?B?M3ZwYzlNengzMEdBWnVaajUvS253SmpxbFJWL2F6VGtqankvTDNZRCtJSlE3?= =?utf-8?B?SUJJak1ZWTVqVFlNZFZZaURVQ21GM2pjVUVpTzQ2Z0pOTWJBMm55UWpDa21Q?= =?utf-8?B?cnhqR0xzUzcrTGxVbVM4OGNHNmhRc2VyVWhWUldwN25NV1RtWm1LYjQyTXVS?= =?utf-8?B?eFhpOTcyc3NHalZ4UWpmR1BIUWVaNlBVbGI4bjJ0UmMxeVlYLzRwMk9obkV3?= =?utf-8?B?bWVRdGp2ZmQxRGZPWitDUnpRU0pGMFB1czVpQXlqMTBLMk11b0U4enNUWWlz?= =?utf-8?B?ZGhZN0gycWt4SUMwenExbTVrTHlEVGVDS3BtdXZYV3ZYdW9hS3hOZUpySVpx?= =?utf-8?B?aTIxSDJzR3lwZTdlMXJLbzZ3UnllcWMzdDlWVHFKZGptcDVBbzhURUhPQ1RM?= =?utf-8?B?VVE0bHlDUGwwSXFqZ21NS2xvSTJaN0E2aUpRamh1SkVESnpCckxXY2Vsekc3?= =?utf-8?B?RlJkTzBmRmowWTNmWEY1TVFGUGtSK3lweW5UVVhhcTBLNUtabk5NRm1Ibkho?= =?utf-8?B?emhtZ2hQRWc0cWtrdWxIaDV1UzNPSmdQbjM5aTVYb3B5MUJueVFTTGEwQWxZ?= =?utf-8?B?YnozcWtUeXJpVDZJdW14NWZCMCtpcUhtbk9LZmxKWUFtL0t4VURZUTl2QUhi?= =?utf-8?B?N1AxUWZFSG4zZFNvYlhXVFFHc2xrVnc2eGorbVhBaVJHdmxUbktMM3BRcHlD?= =?utf-8?B?SUQvSG81MWxwVjZMTEJ3OTZLN0pQRkpLc0xIZTVQYWtPUlY5bEFQYUNZRVNp?= =?utf-8?B?T3BOaFNLbDI0Rms1OW1ZNldEclNsWi82bnRrenY2VklUazUydC9uMEs4c3h2?= =?utf-8?B?emJUR3JOVlFIQXhEL0s5THNhOTc2L3grdUdBcmczY2RibGp1cStjYU5hM1Nh?= =?utf-8?B?WGJIbWtpcktNNlVwUWtVVFp0V2FRNFFLNVUxNFp2ODFBOEE0b21KM1NicWdM?= =?utf-8?B?NUJkNk9lSFg4Q1BwWmZoYjRrZjFpOEFDTlBxZHFOd2pFcW54WFVzYnhqZEpj?= =?utf-8?B?M0FPOFN1SXRGa0h5dTBVaHNiUkZDQjRsb20za0N1cWxFcC9sSkZnMjRja0hI?= =?utf-8?B?TTJBQXF6MlF4WUduSkc2RGNaRnNSNnczY005N0FDdVN4ZTZrSytCOUpXQnZm?= =?utf-8?B?UUtEUUNERSt1TW42eEN3S2lpNEk1cDhsbXdVdHg3OG5ZZ2JpbFFiUE1IM1Bp?= =?utf-8?B?Q1NiY2NpSmVGNjJ6Qy8xRjUyVG9ZRVpuNFd0NHpjcG1aN0twdzNKR0ZCQXBE?= =?utf-8?B?cmV3TmN5WDNTUEljOW9zRjlLV2F0SVdaWGJVU0FuN1QwYmlhakVRYjc4WkRR?= =?utf-8?B?dklLeTJDamF2bGM1aUROcXpoODFGb3lLODVoU2hkSmFLLzZOaHpBQzBBTHR6?= =?utf-8?B?aVlhTUFpeStaNG9Cb0hhSVU3TWV4eXRxRGxvMUNuNWlEdWMyUnEzRkhYbnRP?= =?utf-8?Q?SE8Pzr9XWlY5YzyMmJSl0NCLxcv6ue+v/xZjl5Nv9sCr?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 442fe2f8-94e8-4041-282b-08daac74f639 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5745.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2022 17:12:37.5206 (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: qqxiycanEEdZ3CkKjj7i0he55IAdfnV6Mhe9azA8Qea0iZI2A2TeI1ntzTMKOYaH9PUO+lIr5gBliPHleo7hWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB5640 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, 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 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: Wed, 12 Oct 2022 17:12:45 -0000 Hi, Thanks for the review! On 11/10/2022 19:44, Pedro Alves wrote: > Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding. > > > On 2022-10-06 10:50 a.m., Lancelot SIX via Gdb-patches wrote: >> 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 > > Weird " * " after "main ()". My bad. I fixed this locally. > >> 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 before generating the corefile, and then >> resumes them in their previous state. >> >> The patch proposes to stop all threads across all the inferiors (not >> just the current one) just in case the memory space is shared between >> inferiors. > > The memory space may be shared with processes we're not debugging, too, though. This is true. > > Seems odd to stop threads running on other targets, if we can easily help it. > E.g., you have 10 inferiors loaded, all running on different remote targets. > Stopping all inferiors means we stop the inferiors running on all those different > remote targets. > I have updated my patch to only stop threads for the current inferior. Considering that some part of the address space might be shared with process outside of GDB's control, it does seem to me that this the best we can do. >> >> 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/gcore.c | 8 +++ >> gdb/infrun.c | 16 ++---- >> gdb/infrun.h | 9 ++++ >> gdb/testsuite/gdb.base/gcore-nonstop.c | 44 +++++++++++++++++ >> gdb/testsuite/gdb.base/gcore-nonstop.exp | 62 ++++++++++++++++++++++++ >> 5 files changed, 128 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/gcore.c b/gdb/gcore.c >> index 519007714e5..664318b4161 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,10 @@ 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"); >> + stop_all_threads ("generating coredump"); >> + >> if (args && *args) >> corefilename.reset (tilde_expand (args)); >> else >> @@ -161,6 +166,9 @@ gcore_command (const char *args, int from_tty) >> } >> >> gdb_printf ("Saved corefile %s\n", corefilename.get ()); > > So if something goes wrong dumping core, and we throw an error, we end > up with all threads internally stopped, while "info threads" will show > all threads as "running". That could be fixed with a scoped_finish_thread_state. > Thanks for catching that! I am now using a scoped_finish_thread_state in my local patch. > (Alternatively we could instead just error out if a thread is running.) > > If we go with the auto-stop, then this should be documented in the manual, and > get a NEWS entry, IMHO. > I think that if I can get an acceptable auto-stop implementation, I would prefer that. >> + >> + restart_threads (nullptr, nullptr); >> + disable_commit_resume.reset_and_commit (); >> } >> >> static enum bfd_architecture >> diff --git a/gdb/infrun.c b/gdb/infrun.c >> index 1957e8020dd..34fcb2f92dd 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 0c7c55eabec..81d00f6da7e 100644 >> --- a/gdb/infrun.h >> +++ b/gdb/infrun.h >> @@ -173,6 +173,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..6c9ed4ad342 >> --- /dev/null >> +++ b/gdb/testsuite/gdb.base/gcore-nonstop.exp >> @@ -0,0 +1,62 @@ >> +# 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 > > Please add missing end period. Done locally. > >> +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 corefile [standard_output_file "corefile"] >> +if {![gdb_gcore_cmd $corefile "generate corefile"]} { >> + # gdb_gcore_cmd did would generate a unsupported. > > "did would" does not parse. > >> + return >> +} >> + >> +# After the corefile is generated, thread 2 should be back running >> +# and thread 1 should still be selectd > > selectd -> selected > > Also, missing period. Done. > >> +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} > > Might be good to also check that thread 1 is still stopped, and stopped > where it was stopped before. > >> +} >> + >> +clean_restart $binfile >> +gdb_test "core-file $corefile" "Core was generated by.*" "load corefile" >> + >> +# The corefile has the 2 threads > > Missing period. > >> +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: a13886e2198beb78b81c59839043b021ce6df78a >> > I'll prepare a V2 to send later. Thanks, Lancelot.