From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by sourceware.org (Postfix) with ESMTPS id 8FBB13858D28 for ; Tue, 20 Jun 2023 13:04:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8FBB13858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687266249; x=1718802249; h=from:to:cc:subject:date:message-id:references: in-reply-to:mime-version:content-transfer-encoding; bh=PHzquYOidSrGt8CgL5GDK2itrjntGpUoHPE33QKfiEU=; b=jvccWGFeJHyC0BZP+pN9p0IxMnt5WTHorBFxC2YkCSr10k7hz5nb9EUK M5tsmGFfo6Ux8FWCy+S9MO1LeTeBSogCfZqcpBqxhMtAIF0xiZhep75tq Y4SZw23rEAe4Ss1f5d04Qhf5QvUPr7elFVBp/cO8K+y1uDBQIdrYXbXu+ i1/EppnvVvGO63HmQQCQt5KjN1V/lvLfSpRLK18/FWSRqdLXOfdPc0OLs q8fu7ri2rmGUssFUtudZrz1kN+UWafJApEFmE9sDg1Tg/0TJ5WaSvy6xA 7fiSxYI9QCpxt9QTtJDqhfDXFIb5XPtNZ2AHpZklwCTcddH6QgF/NL9X/ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="349583906" X-IronPort-AV: E=Sophos;i="6.00,257,1681196400"; d="scan'208";a="349583906" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 06:04:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10747"; a="708256745" X-IronPort-AV: E=Sophos;i="6.00,257,1681196400"; d="scan'208";a="708256745" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orsmga007.jf.intel.com with ESMTP; 20 Jun 2023 06:04:08 -0700 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 20 Jun 2023 06:04:07 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 20 Jun 2023 06:04:07 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Tue, 20 Jun 2023 06:04:07 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.109) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Tue, 20 Jun 2023 06:04:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=miKTcSaTJr40g1IfokGtHQX5YSbvZq0qo31v7tDFXW8+NvrcQbZtB8RzAN0hYxLHvzFDvBWzjTrk3dxZCstv0Un9sk4ge+MqVMk/C5lPMkR3zYyXutoUiNp0buWN5yfi+UePsG3f3rngrUiz5Stg/TiMu0Fu8nOMAOawC6cGTS4YZUjOn4KZYrXgcZBfAne8iF89Kb8th8CezZfiueo4MYCx37Ubdwq32DcGiVAVwsKQWWLkG4flDLE9Uu1qanGHnOnuEqZEZX/CNmTgN5Ae8rL6gf4GZEZF0nZwV3/TEqFF6rfBuiMY5Bl6CzOeFLpFy0/cP3zmYajOZql9OVOC+Q== 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=TMOSpEWqsQV1MAauqXrT1eQnGpTZPSU5+NHmw6Mj1Lc=; b=RJWhlDuouvYnPot0e4mTsniZu5v9cqS+Y+8fmGwM+a2+y5AJjFt0dMMQIfRordZhkl+/EdwJ+Q4WTk+Eo7hW9tHWLlWOS6ERZ4CHtHBgrQIDyCxsSyvkfJag+x6uiJsOlML3TQnfR/oYC8VH4b4RWj8RN+jNVEtDik+gI9ahodRA4AlnNe7SfNn+3naF19D3108h4+naK2Sfzd3XaOuN0+L5TZlIHp5x6ZNl3oiipzzcGAJvOhk8LbSZXs7KuK7lERT5Kpw1OCeaCvGSHLqI3WYIX7h1K4k+sdJWxE9X5Y5bl1z8eT0YbzqkQnhsQCp/5tEDBzlNYEvlIifd4OFgJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from DM4PR11MB7303.namprd11.prod.outlook.com (2603:10b6:8:108::21) by MW3PR11MB4570.namprd11.prod.outlook.com (2603:10b6:303:5f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.37; Tue, 20 Jun 2023 13:04:04 +0000 Received: from DM4PR11MB7303.namprd11.prod.outlook.com ([fe80::e57e:3584:99ad:d384]) by DM4PR11MB7303.namprd11.prod.outlook.com ([fe80::e57e:3584:99ad:d384%7]) with mapi id 15.20.6500.036; Tue, 20 Jun 2023 13:04:04 +0000 From: "Aktemur, Tankut Baris" To: "gdb-patches@sourceware.org" CC: "blarsen@redhat.com" , "tom@tromey.com" , "aburgess@redhat.com" Subject: RE: [PATCH v3] gdb, python: selectively omit enabling stdin in gdb.execute exception Thread-Topic: [PATCH v3] gdb, python: selectively omit enabling stdin in gdb.execute exception Thread-Index: AQHZY6hs2BY5O6ke80CPyspDZx+zaq+UJ9XA Date: Tue, 20 Jun 2023 13:04:04 +0000 Message-ID: References: <20230331081114.1319992-1-tankut.baris.aktemur@intel.com> In-Reply-To: <20230331081114.1319992-1-tankut.baris.aktemur@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM4PR11MB7303:EE_|MW3PR11MB4570:EE_ x-ms-office365-filtering-correlation-id: 900e1380-9ac8-4a26-064a-08db718ed339 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 5JpEXU9sAr2Cyaz5zVrVZzYkcrs2PRBlN4qJ9FKitidkFGL4DAzn64ynvnT1D2mZlgbm8EPaYX8ZgqMnB7chbTTx76A92PgOD3xIRX3vf266G5xRveTP07dh/v7HBXho0ypog2GqUjhNmyA4o6mLAtlZTl+bNUo3IkYCEHGH/BRcSHAg71iZ2XgG3GxwuUYQqEgwnse36fn6b2pLx/8jKI2Em+Dt+diGwoP4XUlSdwnN7ruLXq8mN9XbSDeqcIcOxfivfzwx7ffLstqIHfmc/xUC+0qYQtbFcX/0a27PPDDe7s6nvUfX4GldgAAriFc7Y343BKTd8R9F8gBYgsCfj63BJe5QQLO0KER+ff1IZthyg2Zrta6uO4BMjUtQeVD+4WWYUce1ppPAG87EMWM3zNxVFf5KDz2/qXK9pVODfJ9WxzD7xURtr/sxqHJK2nrZLu0SUy1GIaICS68fqKt02HaPGPzcQ58t0WMAqvfabP2jbSMMBl9pY37mnhuaSG0LgX+ZIlRcfg6PLrA0bwJrhcc/9047fKLlrp8lE8UoSKwXhVtr8Ne1UqZ0Mh08CUWj1Rl6IvYMyCPqLivR9zDKz+iFteSbIT2tpI6LsKCqpP5ExcZAx6qL7EKxn2jgKUy/ x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR11MB7303.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(366004)(346002)(136003)(376002)(396003)(451199021)(8676002)(8936002)(186003)(82960400001)(38100700002)(5660300002)(52536014)(122000001)(26005)(53546011)(6506007)(9686003)(38070700005)(7696005)(71200400001)(33656002)(86362001)(55016003)(83380400001)(478600001)(54906003)(316002)(41300700001)(6916009)(66446008)(66476007)(66556008)(66946007)(4326008)(64756008)(76116006)(2906002)(2004002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?/iuXBi/Lh4ryhEqfxn6anababhOn/cptpfIQgDOZRPsqEZt5eJz5aX7s94Cw?= =?us-ascii?Q?6nH3wYxifnGtg+Uj9nAGy9O/sSn0bB2FV28du1cMuuopspBLpoE6zDzIV7PG?= =?us-ascii?Q?AB2hdBz2/295lUlygllP7NvD89aEvwa9cMvzk3bHJva/hQ5O3P5Cfqd131xH?= =?us-ascii?Q?8L4tHNs57Jdce7bpjWJALY36iy38blTrnLetcdoVCI+DDh4CBoH6q53Nr8rx?= =?us-ascii?Q?e/CpKna/OEWO/usi7/eISMdj+ycSxTMDmyjpUDb7bTGAhkCuQFseAZBJXMHP?= =?us-ascii?Q?5hrdWujSzXd1+Un30GTTAa0jVnXS2Jj1SV3yxIGG+ztxQdv34h4J2NLAgSyI?= =?us-ascii?Q?66vk9Kj+kRjzfjhhJPmOCAOBsBlDAGeygAp7W+EUXBtuAnkd0VVELxTIFxjp?= =?us-ascii?Q?i9rObasWPvHRxCLrvvCi5w39Zi6JN30FzbaHncb8wmX9tFvVLhae4hPfN/Bt?= =?us-ascii?Q?+uQsSPMfldBTWAk+DbjpnIHMegxfiJ8JxCfWQ8z/kSmgUhoW6ASl7xm5Zrd+?= =?us-ascii?Q?hFRudpLIMg/fcnMWBYnEWRNSLmBRKjrZHJoC2NWFdc1GwZtZwgTZ7ID7ha2J?= =?us-ascii?Q?MYgFV8wEmqjWvkqACCb601mB8PR9Zz7Ovu7XzxEL25qTGUZMGS6klNsts/oi?= =?us-ascii?Q?vslzmVCbsvuUAt4lBD9pIjDXGX7pBLMBhc8+ysRR12NlJW3N+pp6Wq+kOmJ6?= =?us-ascii?Q?R8KpoP37dba0vCR+JvmJQm5ifoRJEPa860eIuAiPSes1ThubM+MN5FbY1+Wx?= =?us-ascii?Q?sDTRQcYvY0erX8q62KAws9zqqnKnquynx6jRni6Z2BlQA9O737g2ci9tXFXP?= =?us-ascii?Q?FgYnPvUpwk80SIPNABunLi4yWYmoGzD7XkR/LYcPbIFA2giRenYU25Qwm7s9?= =?us-ascii?Q?2Fn/xxC6mC2f2FK2KLsQBMVPIWV2jn5lFWVVADgULAA7evHHBST8tUQQ1482?= =?us-ascii?Q?+REjfdb5W7dHHp9JLMLtDs+hRLjrqdmLe4SmC5htIP4X8KtuuzRm7oF5NTF/?= =?us-ascii?Q?/CVGVgvlRpGM33l6/qko1RyCsEcgYC/R/AF38bEzRBqp3MbWP3eNNHNDxvr2?= =?us-ascii?Q?gJV/PgKJPqBKMSUwxAA6VVkL936qryPmSX400cDWiKK+71SwGPSsAjbgTpua?= =?us-ascii?Q?gaE6S6KVBCEf1JlDaRssmlsXJDw2ju8EkaSeq8Exjt9mvw+nctmwaYK6tsh1?= =?us-ascii?Q?JDpK2CIGU/lY/hoG1eazQqBZJwUbKfkA3kGZCz4FY0a79jHfONUqCUwGV6CR?= =?us-ascii?Q?WoUsMtd+sW5aWCZUznN4aiCXE3T50G88gB6r1yK0JXagQUkPVDfmY4XCv5uj?= =?us-ascii?Q?g9HDnNGcYkXZamajPUbjLS2DN1L6vAj2p9SnuMHiL7LFZ/shPzNdlYBrIyYd?= =?us-ascii?Q?8C4I6NaY+51mMrujBt9qnHT5zCz44HAXfAzhBpKQyrtIzSJ97LK3z46dz+YC?= =?us-ascii?Q?VHbSAl7fYWi5a5WTReCGTtavajB5XreHFk/rRLV0MspM8KVhT2DguGYzIRe9?= =?us-ascii?Q?BpY2rKpYKb+j4lAunHJ9O7uRsq7w+EG4mD05znDl82lB9W1yClGfgpf5+FGV?= =?us-ascii?Q?XB9n6faOnPdZppfm/IgsfJby6/Piz07bwFWjQLhi4UHHwk5MoYJU+KNvwxVz?= =?us-ascii?Q?yQ=3D=3D?= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB7303.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 900e1380-9ac8-4a26-064a-08db718ed339 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jun 2023 13:04:04.5709 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 9S3Q/HSbCwx216uUUbcRBeVxMFa5m9ld5YX6SnOOSJuJsGs4I9qy7Ug2ZUQnDNlE6++vAEL/1CHjXcoKAYIVEwPxnnFS4PG7vaBmrHLvQa8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR11MB4570 X-OriginatorOrg: intel.com Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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: Kindly pinging. Regards -Baris On Friday, March 31, 2023 10:11 AM, Aktemur, Tankut Baris wrote: > From the Python API, we can execute GDB commands via gdb.execute. If > the command gives an exception, however, we need to recover the GDB > prompt and enable stdin, because the exception does not reach > top-level GDB or normal_stop. This was done in commit > = > commit 1ba1ac88011703abcd0271e4f5d00927dc69a09a > Author: Andrew Burgess > Date: Tue Nov 19 11:17:20 2019 +0000 > = > gdb: Enable stdin on exception in execute_gdb_command > = > However, we face a glitch if the Python side executes the command in a > context where GDB had already disabled stdin, because it was running a > synchronous execution command such as "continue" or "run". As an > example, suppose we have the following objfile event listener, > specified in a file named file.py: > = > ~~~ > import gdb > = > class MyListener: > def __init__(self): > gdb.events.new_objfile.connect(self.handle_new_objfile_event) > self.processed_objfile =3D False > = > def handle_new_objfile_event(self, event): > if self.processed_objfile: > return > = > print("loading " + event.new_objfile.filename) > self.processed_objfile =3D True > gdb.execute("print a") > = > the_listener =3D MyListener() > ~~~ > = > The executed command "print a", gives an error because "a" is not > defined. We use the listener as follows: > = > $ gdb -q -ex "source file.py" -ex "run" --args a.out > Reading symbols from /tmp/a.out... > Starting program: /tmp/a.out > loading /lib64/ld-linux-x86-64.so.2 > Python Exception : No symbol "a" in current context. > (gdb) [Inferior 1 (process 3980401) exited normally] > = > Note how the GDB prompt comes inbetween the exception message and the > inferior's exit message. We have this obscure behavior, because GDB > continues to execute its flow after emitting the Python event. In > this case, GDB would enable stdin in the normal way. Hence, we do not > need to explicitly enable stdin in execute_gdb_command when an > exception occurs. > = > As a solution, we track whether the prompt was already blocked. If so, > we leave enabling stdin to GDB. > = > With this patch, we see > = > $ gdb -q -ex "source file.py" -ex "run" --args a.out > Reading symbols from /tmp/a.out... > Starting program: /tmp/a.out > loading /lib64/ld-linux-x86-64.so.2 > Python Exception : No symbol "a" in current context. > [Inferior 1 (process 3984511) exited normally] > (gdb) > = > Regression-tested on X86_64 Linux using the default board file (i.e. uni= x). > = > Co-Authored-By: Oguzhan Karakaya > Reviewed-By: Bruno Larsen > --- > gdb/python/python.c | 29 +++++++++++-- > gdb/testsuite/gdb.python/py-cmd-exception.c | 22 ++++++++++ > gdb/testsuite/gdb.python/py-cmd-exception.exp | 43 +++++++++++++++++++ > gdb/testsuite/gdb.python/py-cmd-exception.py | 33 ++++++++++++++ > 4 files changed, 123 insertions(+), 4 deletions(-) > create mode 100644 gdb/testsuite/gdb.python/py-cmd-exception.c > create mode 100644 gdb/testsuite/gdb.python/py-cmd-exception.exp > create mode 100644 gdb/testsuite/gdb.python/py-cmd-exception.py > = > diff --git a/gdb/python/python.c b/gdb/python/python.c > index b295ff88743..5b34d142d1d 100644 > --- a/gdb/python/python.c > +++ b/gdb/python/python.c > @@ -653,6 +653,11 @@ execute_gdb_command (PyObject *self, PyObject *args,= PyObject *kw) > = > scoped_restore preventer =3D prevent_dont_repeat (); > = > + /* If the executed command raises an exception, we may have to > + enable stdin and recover the GDB prompt. Check the current > + state. */ > + bool prompt_was_blocked =3D (current_ui->prompt_state =3D=3D PROMPT_BL= OCKED); > + > try > { > gdbpy_allow_threads allow_threads; > @@ -698,10 +703,26 @@ execute_gdb_command (PyObject *self, PyObject *args= , PyObject *kw) > { > /* If an exception occurred then we won't hit normal_stop (), or h= ave > an exception reach the top level of the event loop, which are the > - two usual places in which stdin would be re-enabled. So, before we > - convert the exception and continue back in Python, we should > - re-enable stdin here. */ > - async_enable_stdin (); > + two usual places in which stdin would be re-enabled. So, we check > + here if stdin should be re-enabled, and do so if it is the case. > + Stdin should not be re-enabled if it is already blocked because, > + for example, we are running a command in the context of a > + synchronous execution command ("run", "continue", etc.). Like > + this: > + > + User runs "continue" > + --> command blocks the prompt > + --> Python API is invoked, e.g. via events > + --> gdb.execute(C) invoked inside Python > + --> command C raises an exception > + --> this location > + > + In this case case, GDB would go back to the top "continue" command > + and move on with its normal course of execution. That is, it > + would enable stdin in the way it normally does. */ > + if (!prompt_was_blocked) > + async_enable_stdin (); > + > GDB_PY_HANDLE_EXCEPTION (except); > } > = > diff --git a/gdb/testsuite/gdb.python/py-cmd-exception.c b/gdb/testsuite/= gdb.python/py-cmd- > exception.c > new file mode 100644 > index 00000000000..f151960ce3a > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-cmd-exception.c > @@ -0,0 +1,22 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 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 = . */ > + > +int > +main () > +{ > + return 0; > +} > diff --git a/gdb/testsuite/gdb.python/py-cmd-exception.exp b/gdb/testsuit= e/gdb.python/py- > cmd-exception.exp > new file mode 100644 > index 00000000000..3b81131ee08 > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-cmd-exception.exp > @@ -0,0 +1,43 @@ > +# Copyright (C) 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 . > + > +# This file is part of the GDB testsuite. It tests a corner case where > +# the executed GDB command gives an exception and enabling the stdin wou= ld > +# cause the GDB prompt to be displayed prematurely. > + > +load_lib gdb-python.exp > + > +require !use_gdb_stub allow_python_tests > + > +standard_testfile > + > +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { > + return -1 > +} > + > +set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py] > +gdb_test_no_output "source $pyfile" "source the script" > + > +gdb_start_cmd > + > +gdb_test_multiple "" "check the prompt" { > + -re "breakpoint $decimal, main .*\r\n$gdb_prompt $" { > + # The prompt is positioned correctly. > + pass $gdb_test_name > + } > + -re "No symbol \"a\" in current context.\r\n$gdb_prompt " { > + fail $gdb_test_name > + } > +} > diff --git a/gdb/testsuite/gdb.python/py-cmd-exception.py b/gdb/testsuite= /gdb.python/py-cmd- > exception.py > new file mode 100644 > index 00000000000..51199bd3fe3 > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-cmd-exception.py > @@ -0,0 +1,33 @@ > +# Copyright (C) 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 . > + > +import gdb > + > +class MyListener: > + def __init__(self): > + gdb.events.new_objfile.connect(self.handle_new_objfile_event) > + self.processed_objfile =3D False > + > + def handle_new_objfile_event(self, event): > + if self.processed_objfile: > + return > + > + print('loading ' + event.new_objfile.filename) > + self.processed_objfile =3D True > + > + # There is no variable 'a'. The command raises an exception. > + gdb.execute('print a') > + > +the_listener =3D MyListener() > -- > 2.25.1 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva = Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928