From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by sourceware.org (Postfix) with ESMTPS id 5885D3858C52 for ; Thu, 19 Jan 2023 10:33:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5885D3858C52 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=1674124423; x=1705660423; h=from:to:subject:date:message-id:references:in-reply-to: mime-version:content-transfer-encoding; bh=5mR6wPGZgFLM/yuRH0/uYkUgdJPY55WvAuGk074mvIc=; b=AZihXsvEhuGUZ40Lvh10npQI0/0upvQR6L/j2PKW9yTlN4J3rKSyEGFe VcROZIKwPE6qXmoiMLenywQr9jndnB/x7z0YiQVu7tNmaoph+DdTdbCgT mJO1ZigASLwBHUC7pVJvFrK+kfSc9A4UiN1O3/Q9uMyiytt5Da2T8p90u N6UIm9PamFAXP9zCaREA/iiFF7yAeflh0XPD6LSfpSM9+7AIUHgNuV+Th slxr1dbiSUQBVOEns3ArWNnRVKbj1pAGYaKnsH6PSFcStc995ERpNuOF3 rb+0AdqftHA7YWMiQ5nhxBHnJVnCIrmV0e4wsCHwrYVI4K7wHPZbAOLO6 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10594"; a="326511976" X-IronPort-AV: E=Sophos;i="5.97,228,1669104000"; d="scan'208";a="326511976" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2023 02:33:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10594"; a="690578896" X-IronPort-AV: E=Sophos;i="5.97,228,1669104000"; d="scan'208";a="690578896" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orsmga008.jf.intel.com with ESMTP; 19 Jan 2023 02:33:42 -0800 Received: from fmsmsx602.amr.corp.intel.com (10.18.126.82) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Thu, 19 Jan 2023 02:33:41 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Thu, 19 Jan 2023 02:33:41 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.168) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Thu, 19 Jan 2023 02:33:41 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gFYsun5qq+ze9E/2tJ244mcrcRcCEarJRLgiQ1At/9mEG919SPviK1lbLcO1CGZoaLThbZcCaUaZ1ohM9/RszQn7xeO4e3cZzAWqsKebMtNBWZ/VeydGf0PIUQ6tWbgjeSClcuuhCuEEXvrTAZKt2pItExRc0guvYsGrNqBRXw2zY1mKyO2CzUWSCsQA332j0F14n31AL/slneR2Kr0CWqv3Hkmo6SjeuKbuPQBDDjxWnzLbS6DT7grXMwMpXZ6ZQKm4DVV1sB32v33zrS2mzu6WG4rx+aQt+riN4D3+mAuYu8XIP/UnW2E0ZKB3PpWNJ0IyILLUjEaYNUG7tD9BBQ== 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=C9LoD4y6Q1Cteth+gEgzGj9mSYMoY1IFkvhqjOWufJc=; b=fdwvSljst7HR1ApK1z27MmAz+EabDMfYSPuLkXG9ypr4nB6VI4IonYB2ThhZMQTfbVQrw2qQrMRpFxKYRlxPujRfR7LRempKfYuyCHzoXFWH5KsQQrOoh1UjxMXlmB+QzJbhbqi+1mugQogw9GXZn02rWLuN/sSv7k/vF/JNUrYTrn2ulNEnmsgBNR4edq3NXCH5855tlo6ZlChUz93cdwtLt95BF5Xz97B2pteMSeDKCqWgLrntpdU+SOg1WW8h+BSh2hO4zYd71fDw7MXj42DD0zJqutl3MP6a2g3p8J0Fjvp68z3fxBrmldZgRSUZAvkOMAlV6gi5szwkCb3b2A== 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 DM4PR11MB5487.namprd11.prod.outlook.com (2603:10b6:5:39f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.26; Thu, 19 Jan 2023 10:33:39 +0000 Received: from DM4PR11MB7303.namprd11.prod.outlook.com ([fe80::d2a1:8dd2:854f:d5df]) by DM4PR11MB7303.namprd11.prod.outlook.com ([fe80::d2a1:8dd2:854f:d5df%8]) with mapi id 15.20.5986.023; Thu, 19 Jan 2023 10:33:39 +0000 From: "Aktemur, Tankut Baris" To: Andrew Burgess , "gdb-patches@sourceware.org" Subject: RE: [PATCHv2 06/13] gdb: avoid repeated signal reporting during failed conditional breakpoint Thread-Topic: [PATCHv2 06/13] gdb: avoid repeated signal reporting during failed conditional breakpoint Thread-Index: AQHZK1ieCa37WSb1zU2HEBLc4QJaO66lhuKg Date: Thu, 19 Jan 2023 10:33:38 +0000 Message-ID: References: <63d1953385883e9ed1bd87aecc928784fc41ae91.1674058360.git.aburgess@redhat.com> In-Reply-To: <63d1953385883e9ed1bd87aecc928784fc41ae91.1674058360.git.aburgess@redhat.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_|DM4PR11MB5487:EE_ x-ms-office365-filtering-correlation-id: a5de2451-db1d-4924-3811-08dafa08a08d x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: fm3zWnOsRb5Mq+nV6iloUyFIjlIZUbtvJrQz5FsjhxLCBCV1Tfyz6qPoWSq02Ex1nK7wFyYL9/AKDP3xGhqwZCKeP73oaccuGRsIUSwqiegbVGsGSrG9RCgytmLyX24guNx0AP+5mCNFYQZwK2kWv8cj6MY/iU/u/NYonxVENc4PO8Eq9BF5PTDwjg6gnUpW5Z0NOeWm9GsfsPkb+WdYrfuQzHLXNV5BrmRH4nCJCnr7oceMfZ9aM1wbnEhY7YHdEjricaSSBX3Z4l8UAlm2FZkkEhsun02a2FYgJL2a1jLSSEz6iQJ9FkMOQArHntK7hXa0dgQM98jbtY5za/GBSujG1Eyn3bfz971Kxh0jOTAjVqQNSnkeofZFwcoGchY9vkp4P++omwgi9TKNV4CZsk5QHg1ja3n7hwydAnDOy1KOWrdCZHaItTtGept7RroGdPHjmSa4vN7s/QUcyCd8UPwODt9YSUx7lu3wc983QTq1J557d/+hK3jLpkdF5mxEU3iERBFs3ZpFTGMskPlOuT8FrpgWHgaVDu7dAOAsWyOo/svata0rJl9ZOxvOpSLtH3Lw4bmnkMh4vV8O8YJUHczr/6uher/ResJg1T1TqmXoerNH1DqQmy3cEkIOmniob5iYmBJGvW1H14lpf1gsyX4I5P4VL3L6TAHZSMidxTtJGLxonlUuKGFARfWuPMrPCOHUfPQddBIdPzkSYncPvDrR3tkBunUx64rbBoXDNqy12kZMK1QYW5Ax4fe7VXB3 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:(13230022)(136003)(396003)(346002)(376002)(366004)(39860400002)(451199015)(55016003)(38070700005)(6506007)(71200400001)(53546011)(478600001)(7696005)(86362001)(2906002)(110136005)(316002)(5660300002)(122000001)(82960400001)(76116006)(66946007)(66556008)(66476007)(66446008)(64756008)(83380400001)(30864003)(33656002)(52536014)(41300700001)(8936002)(38100700002)(186003)(8676002)(9686003)(26005)(2004002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?lyrj1++CDKjOOp8KGgvNtzDjcLQeI2Gt4HN7zbCEzrRZ5KXXAhDZzqcJz7CN?= =?us-ascii?Q?e+TBa5xe/cU7S1RqOnMUxorM0VB/6RSogA1vh1XTbQ/c8z78SEcFnHaglbNq?= =?us-ascii?Q?7k7j5ASPH3qjyQNc1E3dFAx7zI176EqWA1C8sQ4aSw26376sfNhMRKUBHH1q?= =?us-ascii?Q?nn0bca0REa9P9l5tFHDYAsarUcLmnGkCaqfIDt17jEaVU8m8Zxko7/x+YEu+?= =?us-ascii?Q?5/loqAaGyl2ov1MUkT8f+vCF54yV2V1iG+5DCmnHyMlvL2UX7DrQZ1pTTcK2?= =?us-ascii?Q?2xjUOx/IwIibMWyd3P2xB8wPxbpaHkRVv8CoHEKhpl3j5lR+Zcg4UUWFrUrE?= =?us-ascii?Q?rLdZv/oElxWHsmtB4NCw5Tp1kne0Qc5M1ZPI4mw0rwKDHXHh4t3XCIC/lKQM?= =?us-ascii?Q?Emnl+lFHqaT2WGHcwtg6ZaJgri3EdkDlaGmfVXXlkIXEWOI5vudfRXJdv/EO?= =?us-ascii?Q?cdiDci6bZJFwJ8rM3aXdzfJROLx08/YMEJ38WOInl0fNteBBxsPUFts7c5dS?= =?us-ascii?Q?vXScnA+PsFNNO+RpiiuqHRiO6wyQr7vuBbTn9YeGGSbVsSYMgkO1YGO2AIb7?= =?us-ascii?Q?jOuWSl8ga0Xc/wY2KKMcL6IXPCP9VqSTVttGZbHz1FS6enkCWiIHR16YbwMf?= =?us-ascii?Q?MWNrTfYRXLQ+smlSWUK2hq9mECliC0MMeCTPW63306ycMvDHKWOzwlD5nGxb?= =?us-ascii?Q?uDjtg+JwjppCl9Q2PnmArwS3g4ZpxLGQjhUmkkTo0TuwnGerPyyIuM3jY3m+?= =?us-ascii?Q?3exGWVFX3TvWDeuNqK+q9IkJMgBVrtAkJz3VmfQUsyoTK7S+K7RMEFYE6JlC?= =?us-ascii?Q?YA2iN7HTE7EShccVA4hc84YNFNhOqoG5pfXRZBT8D+B3oyHvS45mwFXItvgK?= =?us-ascii?Q?Zty9JsLJPJl2dp17kztbRyBnlHZYvyjzUHmffZ4/oRfmwiX0Z+bYXEfZloR4?= =?us-ascii?Q?TK0KX4TafEP3uLff7YpViTSDriPbTk+j1FiEIbPMBsPAHiCMYGLZCcntJWC7?= =?us-ascii?Q?Uj5hhHtSJHTqsBiCrNorYoN4msSvFt0IcZU+yUXZ1ns15uokjoe0qJCHpGcv?= =?us-ascii?Q?NJM2DdLpPyxteqZCQYQ9Gdao9EPEaoHg3uJkLHGAjGelr/jCZpu1087RiLYi?= =?us-ascii?Q?AZ5Qpth5VDFUd4mkW/+xkeEK79TyBJZJNmjhH7aqXuVadN2npD2q8DLCNcKS?= =?us-ascii?Q?z7Xk+lak2igXBwTXCw/1PBLOe3mD2y51Uely+qeVbIqhgYi/Bcx2Go+EzPvI?= =?us-ascii?Q?L9iZ7heG602smouoRaUcoO70P/RkK5i+ZLpYi316x3iiWRaNq6cL2TWWJRhN?= =?us-ascii?Q?CJgzHGaCJu2DpAVtsxXwjJqajSep2Q50Z+/x9PAytWhAS68kuJ8Og+2qY0x9?= =?us-ascii?Q?8Rid+OYgeXZOtBJdb9htApWIhSH0aT61ekemv9sMdko5XPLJ/G6qTkglb7HY?= =?us-ascii?Q?AtxjcydsejXoLTX6hEknyg11adf/o+lGYVOSzvePFY0/PrjXNT4Kr/5yglPG?= =?us-ascii?Q?690DszTCVmsnrVNNVUD8dyQlQ99Hr6sr4w2+v6SGTla/RIWg/YWnBeb1YfNd?= =?us-ascii?Q?rEy5u08X7ssvxe/wNvhLTWSBZ30r0R1zZeSrPCNNs9N7nVKqLJPPmOxnovzj?= =?us-ascii?Q?Mg=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: a5de2451-db1d-4924-3811-08dafa08a08d X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jan 2023 10:33:38.6169 (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: 8dvqExyDgSj2Jj0B8VwmZFiRRUeUhtNXEJciE1iz2d01hUKHfQAS6gjJmzUnms2ObPUPTCdKdbLULOKU69q42Yni1ckv6qQT2Ko9APqLGzI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5487 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 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: On Wednesday, January 18, 2023 5:18 PM, Andrew Burgess wrote: > Consider the following case: > = > (gdb) list some_func > 1 int > 2 some_func () > 3 { > 4 int *p =3D 0; > 5 return *p; > 6 } > 7 > 8 void > 9 foo () > 10 { > (gdb) break foo if (some_func ()) > Breakpoint 1 at 0x40111e: file bpcond.c, line 11. > (gdb) r > Starting program: /tmp/bpcond > = > Program received signal SIGSEGV, Segmentation fault. > 0x0000000000401116 in some_func () at bpcond.c:5 > 5 return *p; > Error in testing breakpoint condition: > The program being debugged was signaled while in a function called from= GDB. > GDB remains in the frame where the signal was received. > To change this behavior use "set unwindonsignal on". > Evaluation of the expression containing the function > (some_func) will be abandoned. > When the function is done executing, GDB will silently stop. > = > Program received signal SIGSEGV, Segmentation fault. > = > Breakpoint 1, 0x0000000000401116 in some_func () at bpcond.c:5 > 5 return *p; > (gdb) > = > Notice that this line: > = > Program received signal SIGSEGV, Segmentation fault. > = > Appears twice in the output. The first time is followed by the > current location. The second time is a little odd, why do we print > that? > = > Printing that line is controlled, in part, by a global variable, > stopped_by_random_signal. This variable is reset to zero in > handle_signal_stop, and is set if/when GDB figures out that the > inferior stopped due to some random signal. > = > The problem is, in our case, GDB first stops at the breakpoint for > foo, and enters handle_signal_stop and the stopped_by_random_signal > global is reset to 0. > = > Later within handle_signal_stop GDB calls bpstat_stop_status, it is > within this function (via bpstat_check_breakpoint_conditions) that the > breakpoint condition is checked, and, we end up calling the inferior > function (some_func in our example above). > = > In our case above the thread performing the inferior function call > segfaults in some_func. GDB catches the SIGSEGV and handles the stop, > this causes us to reenter handle_signal_stop. The global variable > stopped_by_random_signal is updated, this time it is set to true > because the thread stopped due to SIGSEGV. As a result of this we > print the first instance of the line (as seen above in the example). > = > Finally we unwind GDB's call stack, the inferior function call is > complete, and we return to the original handle_signal_stop. However, > the stopped_by_random_signal global is still carrying the value as > computed for the inferior function call's stop, which is why we now > print a second instance of the line, as seen in the example. > = > To prevent this, I propose adding a scoped_restore before we start an > inferior function call, this will save and restore the global > stopped_by_random_signal value. Nit: It'd read better, I think, if this read "... function call. This will save ..." = > With this done, the output from our example is now this: > = > (gdb) list some_func > 1 int > 2 some_func () > 3 { > 4 int *p =3D 0; > 5 return *p; > 6 } > 7 > 8 void > 9 foo () > 10 { > (gdb) break foo if (some_func ()) > Breakpoint 1 at 0x40111e: file bpcond.c, line 11. > (gdb) r > Starting program: /tmp/bpcond > = > Program received signal SIGSEGV, Segmentation fault. > 0x0000000000401116 in some_func () at bpcond.c:5 > 5 return *p; > Error in testing condition for breakpoint 1: > The program being debugged stopped while in a function called from GDB. > Evaluation of the expression containing the function > (some_func) will be abandoned. > When the function is done executing, GDB will silently stop. > = > Breakpoint 1, 0x0000000000401116 in some_func () at bpcond.c:5 > 5 return *p; > (gdb) > = > We now only see the 'Program received signal SIGSEGV, ...' line once, > which I think makes more sense. > = > Finally, I'm aware that the last few lines, that report the stop as > being at 'Breakpoint 1', when this is not where the thread is actually > located anymore, is not great. I'll address that in the next commit. > --- > gdb/infcall.c | 9 + > gdb/testsuite/gdb.base/infcall-failure.c | 48 ++++++ > gdb/testsuite/gdb.base/infcall-failure.exp | 184 +++++++++++++++++++++ > 3 files changed, 241 insertions(+) > create mode 100644 gdb/testsuite/gdb.base/infcall-failure.c > create mode 100644 gdb/testsuite/gdb.base/infcall-failure.exp > = > diff --git a/gdb/infcall.c b/gdb/infcall.c > index e09904f9a35..e1b785e437b 100644 > --- a/gdb/infcall.c > +++ b/gdb/infcall.c > @@ -1296,6 +1296,15 @@ call_function_by_hand_dummy (struct value *functio= n, > /* Register a clean-up for unwind_on_terminating_exception_breakpoint.= */ > SCOPE_EXIT { delete_std_terminate_breakpoint (); }; > = > + /* The stopped_by_random_signal variable is global. If we are here > + as part of a breakpoint condition check then the global will have > + already been setup as part of the original breakpoint stop. By > + making the inferior call the global will be changed when GDB > + handles the stop after the inferior call. Avoid confusion by > + restoring the current value after the inferior call. */ > + scoped_restore restore_stopped_by_random_signal > + =3D make_scoped_restore (&stopped_by_random_signal, 0); > + > /* - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - > If you're looking to implement asynchronous dummy-frames, then > just below is the place to chop this function in two.. */ > diff --git a/gdb/testsuite/gdb.base/infcall-failure.c b/gdb/testsuite/gdb= .base/infcall- > failure.c > new file mode 100644 > index 00000000000..00f4369e164 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/infcall-failure.c > @@ -0,0 +1,48 @@ > +/* Copyright 2022 Free Software Foundation, Inc. 2022-2023? > + > + 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 .= */ > + > +/* A function that segfaults (assuming that reads of address zero are > + prohibited), this is used from within a breakpoint condition. */ > +int > +func_segfault () > +{ > + volatile int *p =3D 0; > + return *p; /* Segfault here. */ > +} > + > +/* A function in which we will place a breakpoint. This function is its= elf > + then used from within a breakpoint condition. */ > +int > +func_bp () > +{ > + int res =3D 0; /* Second breakpoint. */ > + return res; > +} > + > +int > +foo () > +{ > + return 0; /* First breakpoint. */ > +} > + > +int > +main () > +{ > + int res =3D foo (); > + > + return res; > +} > diff --git a/gdb/testsuite/gdb.base/infcall-failure.exp b/gdb/testsuite/g= db.base/infcall- > failure.exp > new file mode 100644 > index 00000000000..2dcdda34b4d > --- /dev/null > +++ b/gdb/testsuite/gdb.base/infcall-failure.exp > @@ -0,0 +1,184 @@ > +# Copyright 2022 Free Software Foundation, Inc. 2022-2023? > + > +# 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 . > + > +# Some simple tests of inferior function calls from breakpoint > +# conditions, in a single-threaded inferior. > +# > +# Test what happens when the inferior function (from a breakpoint > +# condition) either hits a nested breakpoint, or segfaults. > + > +standard_testfile > + > +if { [build_executable "failed to prepare" ${binfile} "${srcfile}" \ > + {debug}] =3D=3D -1 } { > + return > +} > + > +set bp_1_line [gdb_get_line_number "First breakpoint"] > +set bp_2_line [gdb_get_line_number "Second breakpoint"] > +set segv_line [gdb_get_line_number "Segfault here"] > + > +# Start GDB based on TARGET_ASYNC and TARGET_NON_STOP, and then runto > +# main. > +proc start_gdb_and_runto_main { target_async target_non_stop } { > + save_vars { ::GDBFLAGS } { > + append ::GDBFLAGS \ > + " -ex \"maint set target-non-stop $target_non_stop\"" > + append ::GDBFLAGS \ > + " -ex \"maintenance set target-async ${target_async}\"" > + > + clean_restart ${::binfile} > + } > + > + if {![runto_main]} { Other if-statements in this file put spaces around the condition. > + fail "run to main" Commit 4dfef5be6812dd7abfbc8f18e9c0384f2522b511 ("gdb/testsuite: make runto_main not pass no-message to runto") eliminated the need to emit a = fail explicitly. = > + return -1 > + } > + > + return 0 > +} > + > +# Start GDB according to ASYNC_P and NON_STOP_P, then setup a > +# conditional breakpoint. The breakpoint condition includes an > +# inferior function call that will itself hit a breakpoint. Check how > +# GDB reports this to the user. > +proc_with_prefix run_cond_hits_breakpoint_test { async_p non_stop_p } { > + if { [start_gdb_and_runto_main $async_p $non_stop_p] =3D=3D -1 } { > + return > + } > + > + # Setup the conditional breakpoint and record its number. > + gdb_breakpoint "${::srcfile}:${::bp_1_line} if (func_bp ())" > + set bp_1_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ > + "get number of first breakpoint"] > + > + # Setup a breakpoint inside func_bp. > + gdb_breakpoint "${::srcfile}:${::bp_2_line}" > + set bp_2_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ > + "get number of second breakpoint"] > + > + gdb_test "continue" \ > + [multi_line \ > + "Continuing\\." \ > + "" \ > + "Breakpoint ${bp_2_num}, func_bp \\(\\) at \[^\r\n\]+:${::bp_2_lin= e}" \ > + "${::decimal}\\s+\[^\r\n\]+Second breakpoint\[^\r\n\]+" \ > + "Error in testing condition for breakpoint ${bp_1_num}:" \ > + "The program being debugged stopped while in a function called fro= m GDB\\." \ > + "Evaluation of the expression containing the function" \ > + "\\(func_bp\\) will be abandoned\\." \ > + "When the function is done executing, GDB will silently stop\\." \ > + "" \ > + "Breakpoint ${bp_1_num}, \[^\r\n\]+" \ > + "${::decimal}\\s+\[^\r\n\]+Second breakpoint\[^\r\n\]+"] > +} > + > +# Start GDB according to ASYNC_P and NON_STOP_P, then call an inferior > +# function. The inferior function being called will itself have a > +# breakpoint within it. Check how GDB reports this to the user. > +proc_with_prefix run_call_hits_breakpoint_test { async_p non_stop_p } { > + if { [start_gdb_and_runto_main $async_p $non_stop_p] =3D=3D -1 } { > + return > + } > + > + # Setup a breakpoint inside func_bp. > + gdb_breakpoint "${::srcfile}:${::bp_2_line}" > + set bp_2_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ > + "get number of second breakpoint"] > + > + > + gdb_test "call func_bp ()" \ > + [multi_line \ > + "" \ > + "Breakpoint ${bp_2_num}, func_bp \\(\\) at \[^\r\n\]+:${::bp_2_lin= e}" \ > + "${::decimal}\\s+\[^\r\n\]+Second breakpoint\[^\r\n\]+" \ > + "The program being debugged stopped while in a function called fro= m GDB\\." \ > + "Evaluation of the expression containing the function" \ > + "\\(func_bp\\) will be abandoned\\." \ > + "When the function is done executing, GDB will silently stop\\."] > +} > + > +# Start GDB according to ASYNC_P and NON_STOP_P, then setup a > +# conditional breakpoint. The breakpoint condition includes an > +# inferior function call that segfaults. Check how GDB reports this > +# to the user. > +proc_with_prefix run_cond_hits_segfault_test { async_p non_stop_p } { > + if { [start_gdb_and_runto_main $async_p $non_stop_p] =3D=3D -1 } { > + return > + } > + > + # This test relies on the inferior segfaulting when trying to > + # access address zero. > + if { [is_address_zero_readable] } { Maybe emit an UNTESTED in this case? > + return > + } > + > + # Setup the conditional breakpoint and record its number. > + gdb_breakpoint "${::srcfile}:${::bp_1_line} if (func_segfault ())" > + set bp_1_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ > + "get number of first breakpoint"] > + > + gdb_test "continue" \ > + [multi_line \ > + "Continuing\\." \ > + "" \ > + "Program received signal SIGSEGV, Segmentation fault\\." \ > + "${::hex} in func_segfault \\(\\) at \[^\r\n\]+:${::segv_line}" \ > + "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+" \ > + "Error in testing condition for breakpoint ${bp_1_num}:" \ > + "The program being debugged stopped while in a function called fro= m GDB\\." \ > + "Evaluation of the expression containing the function" \ > + "\\(func_segfault\\) will be abandoned\\." \ > + "When the function is done executing, GDB will silently stop\\." \ > + "" \ > + "Breakpoint ${bp_1_num}, \[^\r\n\]+" \ > + "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+"] > +} > + > +# Start GDB according to ASYNC_P and NON_STOP_P, then call an inferior > +# function. The inferior function will segfault. Check how GDB > +# reports this to the user. > +proc_with_prefix run_call_hits_segfault_test { async_p non_stop_p } { > + if { [start_gdb_and_runto_main $async_p $non_stop_p] =3D=3D -1 } { > + return > + } > + > + # This test relies on the inferior segfaulting when trying to > + # access address zero. > + if { [is_address_zero_readable] } { Here, too. > + return > + } > + > + gdb_test "call func_segfault ()" \ > + [multi_line \ > + "" \ > + "Program received signal SIGSEGV, Segmentation fault\\." \ > + "${::hex} in func_segfault \\(\\) at \[^\r\n\]+:${::segv_line}" \ > + "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+" \ > + "The program being debugged stopped while in a function called fro= m GDB\\." \ > + "Evaluation of the expression containing the function" \ > + "\\(func_segfault\\) will be abandoned\\." \ > + "When the function is done executing, GDB will silently stop\\."] > +} > + > +foreach_with_prefix target_async { "on" "off" } { > + foreach_with_prefix target_non_stop { "on" "off" } { > + run_cond_hits_breakpoint_test $target_async $target_non_stop > + run_call_hits_breakpoint_test $target_async $target_non_stop > + > + run_cond_hits_segfault_test $target_async $target_non_stop > + run_call_hits_segfault_test $target_async $target_non_stop > + } > +} > -- > 2.25.4 Regards -Baris 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