From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id RNRyNzrcIWrqzDQAWB0awg (envelope-from ) for ; Thu, 04 Jun 2026 16:12:42 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=0g6Wqnqj; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id D02EA1E024; Thu, 04 Jun 2026 16:12:42 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id E01381E024 for ; Thu, 04 Jun 2026 16:12:40 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4899E4BA2E22 for ; Thu, 4 Jun 2026 20:12:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4899E4BA2E22 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=0g6Wqnqj Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010022.outbound.protection.outlook.com [52.101.85.22]) by sourceware.org (Postfix) with ESMTPS id C7A294BA2E17 for ; Thu, 4 Jun 2026 20:12:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C7A294BA2E17 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=amd.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C7A294BA2E17 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=52.101.85.22 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1780603930; cv=pass; b=e1QtegeLDScjuuUbolH2Kr4qFTtb1WvONQdpUZddLsTI3/TMnjslpSyMQPZOazOX12bAErvqI0UeElcqVcQRqj69D8H5aKrJYPnAzFD18v86ecqj2DcJt0NjOnLww4wO3ilehHCj7rZbkAMAWNqIC4sxBaameheehO4KROqFKWk= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1780603930; c=relaxed/simple; bh=AUdVDGhVBJAVw3cx1hgpbeIF60B9Cet8QuhgXyOry/4=; h=DKIM-Signature:Message-ID:Date:Subject:To:From:MIME-Version; b=prDA+G5OMF5ldnbPSimTiCTyviTKU/VLYSTnEHWeN7ajsFvGNQf3kHxIRUZcA+arwkJXeSo2+FOKqoHrbxFx8eNO8tMeq8cw/IFR7ZO/Ps2LDxJCPcKagoRvEwrQ31pdqBS85W1PLCxX6NrgBsviiP9uU16j5gOfaXyTuDSaphg= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=0g6Wqnqj DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7A294BA2E17 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PxSNCCBErGwg8yUpkggPGjTM1H6vKBdOzfHXC4r1kffPyLQPTondkCTH/pYOTez8rUCUKVcXDTggZhgkbjTHs+/IKjud0+88oEmRqHlc9hnTw4dZDN3QHviKR5jvJJDn/p2ZGCRzzalt46Ei4fj+niR06f8f2qIqOzSpOT6vJpU9Yy8QKKN+OAv4JOGfKyKgsH0DBwmy/CT4RieCAv18rUNhq5RTbG7y2Q04iVPUy/U5e7rhx3CsWEjDiMbSl9L/aZ7gnZst8mcd8OVZion/YVpwQPTGqpefva97ztngK9KEa1zWYkYrnxM0VFKjaWksTOcTp15y/KZSyBVsNtk8TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=ff8F1ONUgPcMYtjMtU5L4ZkT6PyJib5qlwZxMyUcOJw=; b=Q0lM7P9tgbjVTghogxVVaIP7jFs1pCawRD41KHFfFI1wl8ZXrBao+dfOTq4kpS49ZjW1vuekv+0/OP7sA7MyB8ZB6diFAOJDJ0oncHf2oOcOAtlKZEklBSYIWdrduAomLKuDQxs2LT/zVRREv3Ej5MQsRRlayKNEXchIgg3g/TE4ExWlhhYC7k3CLIhrGWvcdaSJiqg+SohpRtDI58uPqHc8wzw7/AqH6KMfDPKn/azHV6FhFCHsjztIwJJCtOb9IKVSNeoWmPnIqZEaxHZ/Ug/A2W2vEA7OMJOTvnwl3KgISIG9QDprwil11k350LsWi2pnnzjc1WMaUSZIIs5fAg== 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=ff8F1ONUgPcMYtjMtU5L4ZkT6PyJib5qlwZxMyUcOJw=; b=0g6WqnqjtrGeQAk0ZlBPQF9s1d5WV/GyEDTqiJfdc7CR3I+uxYEGstYMizAdRPS7tRAt7X6q4zVZxvrH2NZn27IVRmAL097tcmI8TLliwHKP1eEUAOz+i2fhESBqPs8N5GiaosXsidlzzlaWPkk33WjPstSA55GrsXNYiXBLuNg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from CH3PR12MB9079.namprd12.prod.outlook.com (2603:10b6:610:1a1::9) by DM4PR12MB6280.namprd12.prod.outlook.com (2603:10b6:8:a2::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.92.8; Thu, 4 Jun 2026 20:12:02 +0000 Received: from CH3PR12MB9079.namprd12.prod.outlook.com ([fe80::5a7a:2adf:1862:35c3]) by CH3PR12MB9079.namprd12.prod.outlook.com ([fe80::5a7a:2adf:1862:35c3%5]) with mapi id 15.21.0092.007; Thu, 4 Jun 2026 20:12:02 +0000 Message-ID: Date: Thu, 4 Jun 2026 21:11:58 +0100 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb/python: fix 'exited' event when GDB exits from core file debugging To: Andrew Burgess , gdb-patches@sourceware.org References: Content-Language: en-US From: Lancelot SIX In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: FR0P281CA0095.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a9::12) To CH3PR12MB9079.namprd12.prod.outlook.com (2603:10b6:610:1a1::9) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB9079:EE_|DM4PR12MB6280:EE_ X-MS-Office365-Filtering-Correlation-Id: 4ca618cc-1256-4f64-1d52-08dec2758a6c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|376014|1800799024|22082099003|18002099003|13003099007|6133799003|56012099006|5023799004|11063799006|3023799007; X-Microsoft-Antispam-Message-Info: Yj0qbIxN3S1hpuGAQIyaPO2AJ1Lqf5wFuFkCg04OQxPhNG2uUhk10YzuZRvIiM1XKBXOk53VQZd1PyvW9LyTFF3t0wPZ0EMDpY2Gm1c+SX+335/6GySl+0oikFEo07O8pXHpXrXin4LvG+XYl/33tFlr6YPA6AtvKX1h/RUgKiUrW16KVimATq/IOJv1qLf6QmYtKopxSI57evKbW4gnUGcZtyIcUj5XzAjIzmEk0i/1Ru1IMJDLjgB2ya/UxMcP3LxNA4eUXbp/7ucNN7xlb0jZ3iBqtyq1lCpM9XoFYSj4+lY7SsedR574yfvhHzc3S+e9eLwzUY5vcCdfw0qFG4LP9m5uP1NEz7d4CbnBvmsX8+6jQh6IYm9JZSIajfV+++D/SMSTzfLaWNsdkV2JouXaj3jqEKCVi1MJZT0/qx0aoQZiD8ClHBoGAWaaatu2Ao5A/uTZ1TsV9K91oxukycKdNKA0tRhWTmtPwdOp+BNbVgUppmBYRMFXPzUydkHnnyIR6Kh0vD9ydr5fc+E/At4hbf5jkyk4B89HoJFWgQcL0e8dFsD2h885XF59SuVT8T4a3KK+e5+2rmhnPBS3G5T6BNnzQHPtY9uw4T6PiR10Joc5iOfp0OsTd73L9kuz8YYEmkWL3IiC5Z9QYuH/ILZLy8iG04q5yhOwAqMTTNU0ye7aTXVk0t+jHaiJ6qwxMuHFVCVmugjbtWdbeQ0SiA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH3PR12MB9079.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024)(22082099003)(18002099003)(13003099007)(6133799003)(56012099006)(5023799004)(11063799006)(3023799007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?L2gzOG0zL2V2TmtURHRtQVllb0tmRnl4eWovYzNkL1VpalBMRkp4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MjF4RXdpZ0lZUGZoQi9OdkdWM2dhbHVYc2ptN0dk?= =?utf-8?B?aTlFSkVaNkQrYTVXYWdJM21QeDFnb3J5eTdCWmI3YkVNZDByQ0k1NnZtVlhK?= =?utf-8?B?WG8yL0FZMEEwcUxkVzN1TUtWdWFkVkhxTm9QT0JLeUhDRkhSbkNLZHJ5RW5u?= =?utf-8?B?RTZndzZjRHJvcS9LRlJkdzY2VzZGRFpqTUd2R2h4TThmeElUeDNkU1J3MzZT?= =?utf-8?B?Y2krbEo4aXk5ZEx6dW4yMmExYk5EUHVncnc5Rlg5Sk8yb0J0ckJLWit0NFBj?= =?utf-8?B?YzdvakI2OGVhUUYzQlhsY0E4b1FBbllIVjNTOTVxWVFNRHFieU12YllHREpP?= =?utf-8?B?U3BJWnBJR0F1VmZyWUZRcEFrejJFQ250Q0lnbE8zYmEzZ0FrRTZnMGFDenMy?= =?utf-8?B?N1R0Y0pSbmFLWGFrcktmU1hNaFUzVEdFTjdlUi9LeG9IRGJONVNVQzFLWEtW?= =?utf-8?Q?EU0vGdF3RiBqOAuNNy?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4ca618cc-1256-4f64-1d52-08dec2758a6c X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB9079.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jun 2026 20:12:02.3989 (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: oYdQPbybgngUuL7J4GbHUU/erWSUNC10Lv+CyDnkol1YvFHBqwVYUQn0hNXapJ2JuxpYOklekynbDmYopf7/sA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6280 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Hi Andrew, Thanks for the quick turnaround! FYI, when applying the patch, git reports: ``` Applying: gdb/python: fix 'exited' event when GDB exits from core file debugging .git/rebase-apply/patch:127: indent with spaces. "python print(str(gdb.selected_inferior()))" ""] .git/rebase-apply/patch:133: indent with spaces. set inferior_string $expect_out(1,string) .git/rebase-apply/patch:134: indent with spaces. incr event_count .git/rebase-apply/patch:135: indent with spaces. exp_continue .git/rebase-apply/patch:139: indent with spaces. verbose -log "GDB has now exited" warning: squelched 7 whitespace errors warning: 12 lines add whitespace errors. ``` I have tested the patch on top of our downstream ROCgdb, and this fixes the issue. I have one minor comment below, but otherwise the patch itself looks good to me. On 04/06/2026 17:47, Andrew Burgess wrote: > Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding. > > > This fixes an issue that was reported here: > > https://inbox.sourceware.org/gdb-patches/v3x4md2dg6rflq35ymzwrmmqf5uaem5exrnlbsp5dmhph2vihy@lq22ncu774yu > > After commit: > > commit 3780b9993c973a2b68b496b80eddb820c0932cc0 > Date: Fri Mar 27 11:29:07 2026 +0000 > > gdb: refactor core_target ::close and ::detach functions > > it was observed that the Python 'exited' event was no longer being > emitted when debugging a core file, and then exiting GDB. > > The problem is that, when GDB is exiting we eventually end up in > quit_force (in top.c), which calls kill_or_detach for every inferior. > > In kill_or_detach we call either target_detach or target_kill, but > only for non-core file targets. For core file targets, neither of > these is called and kill_or_detach does nothing of interest. > > After the call to kill_or_detach, we call inferior::pop_all_targets, > which calls inferior::pop_all_targets_above the dummy_stratum target, > which means popping all targets. > > In inferior::pop_all_targets_above (in inferior.c), we call > switch_to_inferior_no_thread, which ensures the correct inferior is > selected, but makes it so that no thread is selected. Switching to no > thread sets inferior_ptid to null_ptid. > > Now popping the core_target calls core_target::close, and within > core_target::close we currently check inferior_ptid in order to > determine if exit_core_file_inferior has already been called or not. > We only call exit_core_file_inferior if inferior_ptid is not > null_ptid, so in this case we will not call exit_core_file_inferior. > > The only other place that exit_core_file_inferior can be called from > is core_target::detach, but remember we specifically avoided calling > target_detach earlier in kill_or_detach. This means that > exit_core_file_inferior ends up never being called. > > It is exit_core_file_inferior that calls exit_inferior, and it is from > here that the Python 'exited' event is emitted. > > I don't see any reason why kill_or_detach couldn't call target_detach > for a core file target, but I don't propose making that change in this > commit. > > The check against inferior_ptid in core_target::close is clearly > incorrect, checking this requires that a suitable thread within the > inferior be selected, and that is not really a requirement for closing > a core_target. Instead, we can just check the inferior::pid field. > When we open a core_target we always set inferior::pid, even if we > just assign a fake CORELOW_PID value, so checking inferior::pid > against zero will tell us if the inferior has already been exited. > Fixing this check is enough to resolve the reported bug and ensure > that the 'exited' event is always emitted, which is why I don't > propose changing kill_or_detach in this commit. > > An assert in core_target::exit_core_file_inferior has to go too for > the same reason, the assert is checking that a thread is currently > selected, and as discussed above, this is not always the case. > > There's a new test which checks that the 'exited' event is emitted for > both a core file debug session, and a live inferior debug session. > Only the core file case was broken before this commit, but more > testing is always a good thing. > --- > gdb/corelow.c | 13 +-- > .../gdb.python/py-inf-exited-at-exit.c | 32 +++++ > .../gdb.python/py-inf-exited-at-exit.exp | 110 ++++++++++++++++++ > .../gdb.python/py-inf-exited-at-exit.py | 20 ++++ > 4 files changed, 167 insertions(+), 8 deletions(-) > create mode 100644 gdb/testsuite/gdb.python/py-inf-exited-at-exit.c > create mode 100644 gdb/testsuite/gdb.python/py-inf-exited-at-exit.exp > create mode 100644 gdb/testsuite/gdb.python/py-inf-exited-at-exit.py > > diff --git a/gdb/corelow.c b/gdb/corelow.c > index 819e7cae6f9..185b8da90de 100644 > --- a/gdb/corelow.c > +++ b/gdb/corelow.c > @@ -629,10 +629,6 @@ core_target::build_file_mappings () > void > core_target::exit_core_file_inferior () > { > - /* Opening a core file ensures that some thread, even if it's just a > - "fake" thread, will have been selected. */ > - gdb_assert (inferior_ptid != null_ptid); > - > /* Avoid confusion from thread stuff. */ > switch_to_no_thread (); > > @@ -665,10 +661,11 @@ core_target::close () > mostly harmless except it causes two 'exited' events to be emitted in > the Python API, which isn't ideal. > > - As opening a core_target always ensures that some thread is selected, > - then we can tell if exit_core_file_inferior has already been called by > - checking if no thread is now selected. */ > - if (inferior_ptid != null_ptid) > + As opening a core_target always ensures that a pid is assigned to the > + core file inferior, even if it is the fake CORELOW_PID, then we can > + tell if exit_core_file_inferior has already been called by checking if > + the inferior has a non-zero pid or not. */ > + if (current_inferior ()->pid != 0) > exit_core_file_inferior (); > > /* Core targets are heap-allocated (see core_target_open), so here > diff --git a/gdb/testsuite/gdb.python/py-inf-exited-at-exit.c b/gdb/testsuite/gdb.python/py-inf-exited-at-exit.c > new file mode 100644 > index 00000000000..708e3eb98ea > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-inf-exited-at-exit.c > @@ -0,0 +1,32 @@ > +/* Copyright 2026 Free Software Foundation, Inc. > + > + This file is part of GDB. > + > + 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 > + > +void > +foo (void) > +{ > + /* With correct ulimit, etc. this should cause a core dump. */ > + abort (); > +} > + > +int > +main (void) > +{ > + foo (); > + return 0; > +} > diff --git a/gdb/testsuite/gdb.python/py-inf-exited-at-exit.exp b/gdb/testsuite/gdb.python/py-inf-exited-at-exit.exp > new file mode 100644 > index 00000000000..ab415b2c496 > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-inf-exited-at-exit.exp > @@ -0,0 +1,110 @@ > +# Copyright (C) 2026 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 the 'exited' event triggers when GDB exits. Test for > +# both live inferiors, and for core files. > + > +require allow_python_tests > + > +load_lib gdb-python.exp > + > +standard_testfile > + > +if {[build_executable "build executable" $testfile $srcfile] == -1} { > + return > +} > + > +set remote_python_file \ > + [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py] > + > +# Load the Python script for this test. Record the string > +# representation of the current inferior. Then exit GDB. Ensure that > +# during the exit we see a single Python 'exited' event associated > +# with the expected inferior. > +proc source_py_script_and_exit_checking_event {} { > + gdb_test_no_output "source $::remote_python_file" \ > + "load python script" > + > + set expected_inferior_string \ > + [capture_command_output \ > + "python print(str(gdb.selected_inferior()))" ""] > + > + set inferior_string "" > + set event_count 0 > + gdb_test_multiple "with confirm off -- exit" "exit gdb" { > + -re "^EVENT: inferior exited event\\. Inferior is (\[^\r\n\]+)\r\n" { > + set inferior_string $expect_out(1,string) > + incr event_count > + exp_continue > + } > + > + eof { > + verbose -log "GDB has now exited" > + gdb_assert { $expected_inferior_string eq $inferior_string \ > + && $event_count == 1 } $gdb_test_name > + } > + > + -re "^\[^\r\n\]*\r\n" { > + exp_continue > + } > + } > +} > + > +# Create a core file. Start GDB and load the core file. Exit GDB. > +# Check that we see an 'exited' event, and that it is associated with > +# the correct gdb.Inferior. > +proc_with_prefix check_with_corefile {} { > + set corefile [core_find $::binfile] > + if {$corefile eq ""} { > + unsupported "couldn't create or find corefile" > + return > + } I expect you could have GDB create the coredump instead of relying on the kernel for this. This allows this test to run on systems where kernel.core_pattern is not set in a way supported by the testsuite: ---- diff --git a/gdb/testsuite/gdb.python/py-inf-exited-at-exit.c b/gdb/testsuite/gdb.python/py-inf-exited-at-exit.c index 708e3eb98ea..f999fdbbf00 100644 --- a/gdb/testsuite/gdb.python/py-inf-exited-at-exit.c +++ b/gdb/testsuite/gdb.python/py-inf-exited-at-exit.c @@ -20,8 +20,6 @@ void foo (void) { - /* With correct ulimit, etc. this should cause a core dump. */ - abort (); } int diff --git a/gdb/testsuite/gdb.python/py-inf-exited-at-exit.exp b/gdb/testsuite/gdb.python/py-inf-exited-at-exit.exp index f90974dc894..80543bc6f7c 100644 --- a/gdb/testsuite/gdb.python/py-inf-exited-at-exit.exp +++ b/gdb/testsuite/gdb.python/py-inf-exited-at-exit.exp @@ -66,20 +66,27 @@ proc source_py_script_and_exit_checking_event {} { # Check that we see an 'exited' event, and that it is associated with # the correct gdb.Inferior. proc_with_prefix check_with_corefile {} { - set corefile [core_find $::binfile] - if {$corefile eq ""} { - unsupported "couldn't create or find corefile" + clean_restart $::testfile + + if {![runto_main]} { return } + gdb_breakpoint "foo" + gdb_continue_to_breakpoint "stop in foo" + + set corefile "$::binfile.core" + gdb_test "generate-core $corefile" "Saved corefile $corefile" \ + "generate-core" + clean_restart $::testfile gdb_core_cmd $corefile "load corefile" gdb_test "bt" \ [multi_line \ - "#$::decimal (?:$::hex in )?foo \\(\\) at \[^\r\n\]+" \ - "#$::decimal (?:$::hex in )?main \\(\\) at \[^\r\n\]+"] \ + "#0 (?:$::hex in )?foo \\(\\) at \[^\r\n\]+" \ + "#1 (?:$::hex in )?main \\(\\) at \[^\r\n\]+"] \ "backtrace after loading corefile" source_py_script_and_exit_checking_event ---- Best, Lancelot. > + > + clean_restart $::testfile > + > + gdb_core_cmd $corefile "load corefile" > + > + gdb_test "bt" \ > + [multi_line \ > + "#$::decimal (?:$::hex in )?foo \\(\\) at \[^\r\n\]+" \ > + "#$::decimal (?:$::hex in )?main \\(\\) at \[^\r\n\]+"] \ > + "backtrace after loading corefile" > + > + source_py_script_and_exit_checking_event > +} > + > +# Start a running inferior. Exit GDB. Check that we see an 'exited' > +# event, and that it is associated with the correct gdb.Inferior. > +proc_with_prefix check_with_live {} { > + clean_restart $::testfile > + > + if {![runto_main]} { > + return > + } > + > + gdb_breakpoint "foo" > + gdb_continue_to_breakpoint "stop in foo" > + > + gdb_test "bt" \ > + [multi_line \ > + "#0 (?:$::hex in )?foo \\(\\) at \[^\r\n\]+" \ > + "#1 (?:$::hex in )?main \\(\\) at \[^\r\n\]+"] \ > + "backtrace at breakpoint" > + > + source_py_script_and_exit_checking_event > +} > + > +check_with_live > +check_with_corefile > diff --git a/gdb/testsuite/gdb.python/py-inf-exited-at-exit.py b/gdb/testsuite/gdb.python/py-inf-exited-at-exit.py > new file mode 100644 > index 00000000000..b6fe39e4061 > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-inf-exited-at-exit.py > @@ -0,0 +1,20 @@ > +# Copyright (C) 2026 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 . > + > +def exit_event_handler(event): > + inf = event.inferior > + print("EVENT: inferior exited event. Inferior is " + str(inf)) > + > +gdb.events.exited.connect(exit_event_handler) > > base-commit: bd64797371d27c766d551d0bf115d9090f1d0594 > -- > 2.25.4 >