From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id xnmaO68OLGrVQgMAWB0awg (envelope-from ) for ; Fri, 12 Jun 2026 09:50:40 -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=GwUq5Fcp; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E193B1E098; Fri, 12 Jun 2026 09:50:39 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 5662C1E070 for ; Fri, 12 Jun 2026 09:50:38 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 238134BA9001 for ; Fri, 12 Jun 2026 13:50:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 238134BA9001 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=GwUq5Fcp Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazlp170130007.outbound.protection.outlook.com [IPv6:2a01:111:f403:c112::7]) by sourceware.org (Postfix) with ESMTPS id A39324BA23D3 for ; Fri, 12 Jun 2026 13:50:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A39324BA23D3 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 A39324BA23D3 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c112::7 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1781272207; cv=pass; b=SV2LLivhhs/sQJ4/W34Fwxvheea9FhutUOKWN80x3Soraj+c09dWTPdGvjQPQ+IoFUIiAizlP7fUbRagJl61hrz2E7vS6FxoA8GsZ+urGbsAkKdHCev4gSl+H/737GxdscmKfqyIYR2t87z1FmKAU6meE0v+/N0kwHLelghpD14= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1781272207; c=relaxed/simple; bh=9ImuUydz0Xpveirc+mKtsbuQDqhVqoyRNw0IzPlqgj0=; h=DKIM-Signature:Message-ID:Date:Subject:To:From:MIME-Version; b=YnTZX7qcPvO0yYzxhYSDb/c11M5vWmwoyLbGyX+GTVQQMQ7m6+mv3+yQAAdtSMavx0oL4zPxe3Yxdt3sW0wL8xWb3Nudhw9HdhI0xTWY+FVSYQVyYwLZ33f3o8+m8MIVaO9Vx1ue5dTEeZuL+G0fCe1ayyCcsm1TSuhaxtihwSk= 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=GwUq5Fcp DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A39324BA23D3 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rlKqBXkm7mGVUWL5+VRzclma6MM2mUEZgWWiOnC7k49xgHiAlXSnrK1ywLamroaJKdM23l4Njzypf2fH0AYptRHMGGy+uWkMKBi9jgcLvnKQ860LyHZjVae/ev2YHz8pmgzG3H4R0QMTTxS72/CFL0nKRnhFPFxW05ugz0OKnwRTz/AOvupBptDox8E+/Lu7HSj6hsJzy+OpBzzIh/JJEVx+t0CB8uYR8WxsLA6L6xosx9AqBDSuPAeIax+o+S5gV3LvzeNBe1asnIqpId+j3lZaFock4+eiKaJhL/n6nkrdAQAqQ+hOfx24VC/kyjpZ9L2bb1ZHhOelsgWoDE5eIg== 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=DNhfJhtt2B9x9nVogjLuj90bwiWp5O3eifsX1vkPWSE=; b=Ex83KEmDIhF5rbT8/pHJVAZ7d/XE3J1akuatCAhSq0A+ajwrVxIb1b92nJ6eytZCLs0DFASWysWqMQfMTJY3pI/C/cKqii2cOnCh194dBMY9aRJIEQjUTndU4bmpRXbavGzX2SLLacwZJu/Gvl8Fgz/jla11WM7bCAQfqt6qUoTk+RHRynz9leekfQAiadpOdVXMV3kERj1lyNCdtW0DcziMWM1MTPuXl6ZPsunQsFQ9A8lED4C5qg50LjgpvAmB26q71LjuP4EdMwg1jP5E0D6SX3kwyOQRzu3tG41R/oUwXrp8xu5bx6rRnAXPKMMzJkPWcZd197HHMunLFtpffQ== 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=DNhfJhtt2B9x9nVogjLuj90bwiWp5O3eifsX1vkPWSE=; b=GwUq5FcpI2b3S+KICX9rGfokb5/TBWbW8VombU8UxoX56ziviFqbue3jxTTKKJL0gmQem+4ZnnXHDSg3qk3i6VZv8xoeIOlQ7/F39aLlnUEwIocpqa1tgEb06Yeq+BW3Zmv77C/Xkzrv7oLVqlY61UdwKe/1eC+u+RWicYg0+7s= 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 DS7PR12MB6023.namprd12.prod.outlook.com (2603:10b6:8:85::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.14; Fri, 12 Jun 2026 13:49:59 +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.0113.013; Fri, 12 Jun 2026 13:49:58 +0000 Message-ID: <038a1fc7-8627-4030-8fc5-e02cafced42a@amd.com> Date: Fri, 12 Jun 2026 14:49:53 +0100 User-Agent: Mozilla Thunderbird Subject: Re: [PATCHv2] gdb/python: fix 'exited' event when GDB exits from core file debugging To: Andrew Burgess , gdb-patches@sourceware.org References: <7db5bc5d0e3c7189881540ab2c775ea20fc03b5f.1780767159.git.aburgess@redhat.com> Content-Language: en-US From: Lancelot SIX In-Reply-To: <7db5bc5d0e3c7189881540ab2c775ea20fc03b5f.1780767159.git.aburgess@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: FR4P281CA0147.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:b8::7) To CH3PR12MB9079.namprd12.prod.outlook.com (2603:10b6:610:1a1::9) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB9079:EE_|DS7PR12MB6023:EE_ X-MS-Office365-Filtering-Correlation-Id: 09e71fe9-1a40-4be9-4af7-08dec8897e35 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|376014|23010399003|13003099007|22082099003|18002099003|3023799007|11063799006|5023799004|56012099006|4143699003|6133799003; X-Microsoft-Antispam-Message-Info: VqU5RyT3PQ+MmVIpfHwXjgjdqwUyfC72X3iFCgWVD1G8lNk9g1xsdij34bJJlgioGAsu+vPZkRoX2pOgOMDNWPz6iV3VPn5mtePtcGvS3jng0CKt1/s968Bpmf1/VaH0gcl+3V//OxwNqtfxpgn8LDiRRBVB7kdkezfR6OiiXid8+0BZsmiWjxEMBHxl8mfelrFt9uC3iKcgvoe3/PRjv/GQRgIqUvB9nHLuuaHaQyYp9erk356uNkZGEwYvl35m5K6/gkUlpZ5RWNnlN+FKU5uaeKpLXEzoTxfdy1qRJdmta8ORPDCyUVTO+CBcz7RHh26t4O9n2hs2ZXO8H8Yj7Ec2Dm9fuLgwtxXy7wU6Y2y2/cogxRW3fWZhQISBPOqA3Pw5WJy5XKSxBuLWKKzdCKezQIrKznWCd+zFZ26noVfBondUOZxOpbCoEy5qCDqBWcfc2MubIfVGx5LT5BT4eJHQEZDBpeV8Yt764suWPqj/0DJ8iUaLvHAoU7k4B/t3TN5FOHKLZ6POReZ63TknFl2yjf83ChlKO9FaHIzIQDFJOikD8wT8On2wkFnVeNHvDXtNunxfl0yZm2LxQuOiZ71RjqDAe7xMfrFJuvXZwXv+UpjclmPPs2qQnYhuVJxv/EYXQI3zLCrKiSpQ0961yEQPZ2Mv8XosUORORpMGmMb648+6+0XAtg/f4BB6ayblPlgopAdS21PMYVvDeKhgaA== 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)(1800799024)(366016)(376014)(23010399003)(13003099007)(22082099003)(18002099003)(3023799007)(11063799006)(5023799004)(56012099006)(4143699003)(6133799003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1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UvQkYwVW5yaUpRK0V0cVU4OHR6MlpDVHZ4T3ZUaHJqTUhhTm54?= =?utf-8?B?azk0dGdZWU5mMDYvYkhzTmdOZUxwN1pKcWFqa3hIQTZnVGJVWktFOVYrWWla?= =?utf-8?B?SFhoRmJ2SWhQV3NMc0hzZ1BFaTJWV09TM3ZJMU42YVIva1Radm1ZMy9Mcy9X?= =?utf-8?B?VXlydnV6YTRyS09mVHVCRXE4N29zNGh4U0JGd1hzdVQzbUp3REpYSFFLZUpQ?= =?utf-8?B?L2EwMTVXK1ZyYmxab1kzaXp2VnM0eU9tQXFJUjRSRlpDTFc2NmVrZXB0RlIw?= =?utf-8?B?TTFKMGdsQ3R0MnZNWnRMMjdlcm5pQXV6T1RTVkl6NXNhalluQmN4V1J1V1lG?= =?utf-8?B?YXIvU3M3d0h1ZEZ6VEloN3dyZWt3RHRlZVR5ZVhIZkRFNlFTVHU0UnhEcis3?= =?utf-8?B?RU41VUZCUzRCOGF0SWZOaTAzdUdPQ1ljZFZRSW1sMHlrM3dvU0NtUUE4dmV4?= =?utf-8?B?OU83SUdScmxXbkJITFFkWVY4MjFhcUpYdmhJczJaRVFaR1FNVGtGQUVYRFFl?= =?utf-8?Q?js3bV7GuK9zxpGaBM0?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 09e71fe9-1a40-4be9-4af7-08dec8897e35 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB9079.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2026 13:49:58.8621 (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: n6GryWdMLwSR7pLQ7leaXYFiz35NeBIUKFKITpfST0TdPuINoXm5LNNGTboIZ2QkQbqWEjfDrLvOoOGni/svOQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6023 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 On 06/06/2026 18:32, 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 | 29 ++++ > .../gdb.python/py-inf-exited-at-exit.exp | 125 ++++++++++++++++++ > .../gdb.python/py-inf-exited-at-exit.py | 20 +++ > 4 files changed, 179 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..068e2e6a509 > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-inf-exited-at-exit.c > @@ -0,0 +1,29 @@ > +/* 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 . */ > + > +void > +foo (void) > +{ > + /* Nothing. */ > +} > + > +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..53e2a2b782c > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-inf-exited-at-exit.exp > @@ -0,0 +1,125 @@ > +# 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 > + } > + } > +} > + > +# Clean restart using global TESTFILE as the executable, then run to > +# 'foo'. Return true on success, otherwise, return false. > +proc clean_restart_and_runto_foo {} { > + if {[clean_restart $::testfile] == -1} { > + return false > + } > + > + if {![runto foo]} { > + return false > + } > + > + return true Hi Andrew, Just one minor comment: Can't this be simplified as return [runto foo] ? Otherwise, this looks good to me, and I can confirm it fixes the issue I reported initially. Best, Lancelot Reviewed-by: Lancelot Six > +} > + > +# Check that the current inferior's backtrace is 'main -> foo'. > +proc check_backtrace { testname } { > + gdb_test "bt" \ > + [multi_line \ > + "#0 (?:$::hex in )?foo \\(\\) at \[^\r\n\]+" \ > + "#1 (?:$::hex in )?main \\(\\) at \[^\r\n\]+"] \ > + $testname > +} > + > +# 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 {} { > + if {![clean_restart_and_runto_foo]} { > + return > + } > + > + check_backtrace "backtrace before generating core file" > + > + set corefile "$::binfile.core" > + if {![gdb_gcore_cmd $corefile "dump core file"]} { > + return > + } > + > + clean_restart $::testfile > + > + gdb_core_cmd $corefile "load corefile" > + > + check_backtrace "backtrace after loading core file" > + > + 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 {} { > + if {![clean_restart_and_runto_foo]} { > + return > + } > + > + check_backtrace "backtrace before exiting" > + > + 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 >