From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2078.outbound.protection.outlook.com [40.107.92.78]) by sourceware.org (Postfix) with ESMTPS id 1C1273858D39 for ; Fri, 2 Dec 2022 20:05:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1C1273858D39 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=PpF69CwKIRnMoMcKCFJ1jgWKIqLpXCQ6XSezjGpLc+QpWjEO7MNS0nGVBhlrlew2mAK3NwgDRx0Ee7GYS65UOQVR7wbG4Y6cppkRi511H1aGecjsVtiPce/2xayx0vdpbhaUG/mVtYiJc2LFn8V7L6gzXhFijlpg1HQALYRS3NkjNyHMRCCtwHkDqv7vKD+/E3nCfcbesUHi28JWPHM49DtbcFrAf+B2XrBoNLFaXmadQqe3aKXVWVPjx72outI66S6ubio40nvGd+JcLjBbEoyW9xZgQ79L2I1UO+R42CcRrHdxNhWMKdBWpW+RGjDHYX4QZfzshKw03EtzosNmIA== 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=KMLFXuQlnNWXlNDC76POdikcjOWBQ8NfiO1flXq9x7U=; b=YYoye8TcNUzCRXZr36GCPZvk7K+0WBZ8zNYjgEQLSX/Q5D8Uk93zBKOh7xIVgEYA6s8wPCZVplX8UxCJ5XE0PhJG19d0VZrmI/IJguc1omGUo2/g1c7vn+gn9sgVavN5mHlyW6Gnq9iVGLwGhF5yNPXhSs3SXpREMwQpNZo3+v+rXiHC5G+Jw2F4Ni9v3RsZKHs5SeZ8XwxnuMFD8/nwLp797H5VoM8WBJwiM6+2N/jRwyjdT26UyW1Gz88CoafqGHRPAd8jU9SebRR6PwlUyhWIqDPIX4eAaLDTfQRcRorfZQ796/Rvv4hjZABSUkrP3LaWqot4CLnONvZjqGzycg== 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=KMLFXuQlnNWXlNDC76POdikcjOWBQ8NfiO1flXq9x7U=; b=SvhusPWsDm7RgcFyf/sQmBAyQALDpH2M2vXQ4WN5AIhkZ0s+ipL466STcX2skAKpsH90SnchtNheJl/gPAm6hTG9q73OkmnIwcXxU+SC6powMU3lMdkP3nrq5u3eItSr1ABOMsPtIYSthDoY0u0l45fSCubtpzxHme1j8QcBdPw= 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 CH2PR12MB4892.namprd12.prod.outlook.com (2603:10b6:610:65::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8; Fri, 2 Dec 2022 20:05:46 +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.5857.023; Fri, 2 Dec 2022 20:05:46 +0000 Message-ID: Date: Fri, 2 Dec 2022 20:05:41 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v3] gdb/gcore: interrupt all threads before generating the corefile To: Andrew Burgess , Lancelot SIX via Gdb-patches Cc: lsix@lancelotsix.com References: <20221116123649.2430701-1-lancelot.six@amd.com> <874juj2jhl.fsf@redhat.com> Content-Language: en-US From: Lancelot SIX In-Reply-To: <874juj2jhl.fsf@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: FR3P281CA0207.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a5::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_|CH2PR12MB4892:EE_ X-MS-Office365-Filtering-Correlation-Id: 22099dad-d36d-4977-133a-08dad4a0999f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gds96Xq4zqwrUOW9wIAJqb8TTGiZGs9BOs1SB15wl+W8aw2Q/7lMHqB5Bhommb/0ohiimlE9iV59gfnB1mXOyUz879AeJUxB27029AnUpYhai3LFpBLWanfC0E02SQjPFWrsdH8DoC3OZmW9o/8ySeH3zma1vb422JCDw5I8r+oJUgmDl0zKv4NND3CM1KcNNLGakfuCcogMfStDJh9hwLs1a0IKzVU5n2BQkvil5if6M8ypmdGmkAtM4JxhKklWunUK4GETrDTQsbgyFevipHu3UET0b+vvOrNJ147sWEdKcXrWafC+5XWbh3IzVfhSC/l9e+98xBmLyNYl0tezdtutFm7s+R20vVfCQKrrpvA/FMPQ7fT5DeoqyhsPm05hORK3rN9XaPuagTbRLHtDLA2ixQoZsOUNROKlfH18MmpAPB58R3t+/gjbVfep4PLfKyewHun/fIQWbnir2LPHWeHC0GWY+x9TISH+Z1xMDpMozz1v1IreyBa2+N6TYOPHcwZpcOX/oAAAaFhjWduruHAfTSikdI/il67M8TIJnxAwfS7NTt98JerIrORNmLhqegCvkkotCMb+jWs6eJi/Cn4yugRBEk5dJXlBYklgZoOgBf/s1pL2RKUUs7dJ7ik+eYECKbNmLtZEWib6O820eH/I9wM/WISsJBXREs4fTvUwkY7H79+3F7QHQvhPT52NtS3EzQEXdek0Ei82mB0TCVTmnE9fhCyTS7CE/V1ex3mgFZwyg8B2cndSUdVtC1yJINNtKKyJY36ClDMZfV9aKSb9HWcpfT26ZhIuJMX8xDUHNNjOMaGV8gWG1qr9Ls3P 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)(396003)(376002)(346002)(366004)(39860400002)(136003)(451199015)(83380400001)(31686004)(66899015)(478600001)(86362001)(110136005)(53546011)(6512007)(6486002)(6506007)(966005)(31696002)(36756003)(38100700002)(2616005)(186003)(30864003)(41300700001)(6666004)(5660300002)(66556008)(66946007)(66476007)(8936002)(4326008)(8676002)(316002)(2906002)(2004002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Z0VhR2tlbHl4RnVOcUV5Q21UWmpDSmNHSXlDYmZSVlRDZ0JzNXJJVVJsa015?= =?utf-8?B?RXlZM2VsOGZCeXNXb083M0RMLzJabUxkVjR2ODk1Q3hBRWJqU21ONVZlQUZZ?= =?utf-8?B?NE5hQVpkb0hvT2N2M2UwajVPdnZqSXNlQU1COEdOZDRsSzY4K2Roam9GSjBw?= =?utf-8?B?ZFVHRVZHT2ljaE4vd2dSc3ltTjBHc3kwbXcvZi9Zc2x1aURHejNVUnZ3NUk4?= =?utf-8?B?Z2JlekpSYWhMdmprRmx6K1VaY2J5bnZMa1UybS9TSWY5d2hXbkwwdlNKVlhH?= =?utf-8?B?RjNROWZkTTdIQWxPVERWTG45RERtT2NVYnlVUzVkWE4yM2FqekJmUmdkdkFE?= =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3Z2g1OVMvdUlTY3Y2M2xzaG1MOS9DUWp4djIv?= =?utf-8?Q?lLFPy0aRQpblnDvSdt+T23o=3D?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22099dad-d36d-4977-133a-08dad4a0999f X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5745.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 20:05:46.5884 (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: bPlHBtnYM8g5zFjWwX9l404KuvFT9g73hnxIp7Tb5OU58nPA98FIiZlfZqAizn6bJizGPL9m5E2JkcaRZuGS5g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4892 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 List-Id: Hi Andrew, Thanks for the review. I have been through your various comments and all seem valid points. I'll try to send a revised patch when possible integrating all of your comments. Best, Lancelot. On 28/11/2022 15:20, Andrew Burgess wrote: > Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding. > > > Lancelot SIX via Gdb-patches writes: > >> Hi, >> >> This is a V3 following >> https://sourceware.org/pipermail/gdb-patches/2022-October/192746.html. >> >> Noticeable changes since V2: >> - The test have been updated following Pedro's comment to be compatible >> with --target_board=native-extended-gdbserver. >> - Running the entire testsuite against gdbserver revealed that the >> original implementation was incompatible with all-stop targets. The >> V3 improves the implementation to support both all-stop and non-stop >> targets. >> >> This patch have been regression tested against gdb and gdbserver >> (native-extended-gdbserver). >> >> 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 | 5 ++ >> gdb/doc/gdb.texinfo | 5 ++ >> gdb/gcore.c | 37 ++++++++++++ >> 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, 182 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 3f31515297c..adc0963aecb 100644 >> --- a/gdb/NEWS >> +++ b/gdb/NEWS >> @@ -128,6 +128,11 @@ set style tui-current-position [on|off] >> >> * Changed commands >> >> +gcore > > I think you should list both gcore and generate-core-file here. > >> + 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 f5f664fd168..ec2eba4b410 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. > > I think the second sentence needs rewording. I would propose: > > 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 ede78534bd8..dda9e7af50b 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,35 @@ 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 ())); > > Through all of the following code you work with INF. I guess you maybe > did this to reduce the line lengths? But it also has the nice effect > that the following code is mostly independent of the global > current_inferior() state. > > However, I found it a little confusing that when building the ptid_t you > still make use of the global inferior_ptid. > > I think I'm correct to say that all of the 'inferior_ptid.pid ()' calls > could be replaced with 'inf->pid', which I think is clearer. > > Certainly, I tried making this change, and the test still passed. Is > there any reason why this wouldn't be a valid change? > >> + bool all_stop_was_running = false; >> + if (exists_non_stop_target ()) >> + stop_all_threads ("generating coredump", inf); >> + else >> + { >> + for (thread_info *t >> + : all_non_exited_threads (inf->process_target (), > > I don't think there's any reason to wrap this line, unwrapped it's still > only 74 characters. > > Though I think you could just use 'inf->non_exited_thread ()' instead. > >> + ptid_t (inferior_ptid.pid ()))) >> + { >> + /* All threads are executing or none is, no need to go through the >> + entire list. */ >> + all_stop_was_running = t->executing (); >> + break; >> + } > > Actually, I think you could replace this whole loop with: > > const thread_info *thr = any_thread_of_inferior (inf); > all_stop_was_running = thr->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 (inferior_ptid.pid ())); >> + } >> + } >> + >> if (args && *args) >> corefilename.reset (tilde_expand (args)); >> else >> @@ -161,6 +191,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 (inferior_ptid.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 6da46b75ac7..c7c8ad5456f 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); >> @@ -5886,18 +5883,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 *) > > For me, gcc 9.3.1, this test doesn't compile due to the missing argument > name here. Changing to > > worker_func (void *ignored) > > works just fine. Could we do that? If you really wanted you could > annotate with '__attribute__ ((unused))' though this doesn't seem to be > widespread in our testsuite, so personally, I'd not bother, but it's up > to you. > >> +{ >> + 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..56fc909b00b >> --- /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} {threads debug}] } { > > I think: s/threads/pthreads/ otherwise, for me, this test doesn't link > with -lpthread, and fails to link. > > Thanks, > Andrew > >> + 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} >> +} >> >> -- >> 2.34.1 >