From patchwork Thu May 25 11:14:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciaran Woodward X-Patchwork-Id: 70067 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C05653858414 for ; Thu, 25 May 2023 11:14:32 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2113.outbound.protection.outlook.com [40.107.22.113]) by sourceware.org (Postfix) with ESMTPS id 8DC263858D32 for ; Thu, 25 May 2023 11:14:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8DC263858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=xmos.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xmos.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DQsAzZqjnJh5AMWyd3pfvVQ80LDhRUUVnsrcSLBq5xc2odZqjj7agz3tW9vAkt0Lqft0XVts2bB4OSQSDjFVFU23YOGo5XUCDK6T/uY+9TvobxPfXYIZBzyl1laMAUZVXZGiPLJk/fKdtZvNhxWgdLm2aZYNFiNbZcSiCkWfUK3F3cTU1vjjWIo2YNTwbmB0ZP51M/YcLjuPHi42HknAOpZVW0Er4ZINtLOXncMdGO9reHDGCO87CmBftYzQO3JY5m+PvZ9M3r8FLA9g0i11dekjaarTkljB6mUIxiUI6kBxZbA/Ayg4NYQq/JSWi9KSvrcQI9IYTXOl3zPF6/TopA== 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=sRarTBe+eeKkg5G2c9oYrWS0mZlqqM89FG2IJkfNAY0=; b=Ds/uSUqdrnjjrKfj6Dh15KOGIhZuKiKeInXDx3W1Aq80xlIUEUc8Hq0wsgoTFtbhJfvMoPbRZDhwSWuce/bk8jstbtUjTCliNWnz64PBjqTcdcW3/ek5xlD23WLGGdIXMPxyGE1tGYEctKY7VJDRQEiW4gG8Wsm8o2CSO2AJpRRmZsXPOKbBUEOaFUr6eO13gB1QUg+oeeA/KustgFX4LEHGcu2K9sePHAzwUN15tJrHJkZ88rWWsZ+nEvTTpTfBP/EevS6kUPfwLkTMGwaRKgIR1dm4FGG8pTJYbPa/8rRecSaXMFgzmKSPGnblv66GTM6aK+rIvE7kODl2BSm9nw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=xmos.com; dmarc=pass action=none header.from=xmos.com; dkim=pass header.d=xmos.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xmos1.onmicrosoft.com; s=selector2-xmos1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sRarTBe+eeKkg5G2c9oYrWS0mZlqqM89FG2IJkfNAY0=; b=TuKNqC95IRJN+DA1ZLVdUisAyP7r0ylwAKuTml4IXlB7xwLQudSTXQrwysxdYjUpxWuQagqvC4rkPU4nKli1Ql5jxvHWeqsQJlxAik27gtuHHK+LfrGhtvLIIXdN5j6Oq97+T/nyok0DxF3EdxI/0Mnxi4580XOIYaqqiYiY/fQ= Received: from PAXPR09MB5583.eurprd09.prod.outlook.com (2603:10a6:102:280::6) by AS2PR09MB6293.eurprd09.prod.outlook.com (2603:10a6:20b:57b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.21; Thu, 25 May 2023 11:14:15 +0000 Received: from PAXPR09MB5583.eurprd09.prod.outlook.com ([fe80::8ada:b671:a905:128a]) by PAXPR09MB5583.eurprd09.prod.outlook.com ([fe80::8ada:b671:a905:128a%3]) with mapi id 15.20.6433.016; Thu, 25 May 2023 11:14:15 +0000 From: Ciaran Woodward To: "gdb-patches@sourceware.org" CC: Ciaran Woodward , "tom@tromey.com" Subject: [PATCH v2] Fix scoped_value_mark not working with empty value chain Thread-Topic: [PATCH v2] Fix scoped_value_mark not working with empty value chain Thread-Index: AQHZjvml8N1+RKfKWUCQ/7Yqjb6Zxw== Date: Thu, 25 May 2023 11:14:15 +0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=xmos.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PAXPR09MB5583:EE_|AS2PR09MB6293:EE_ x-ms-office365-filtering-correlation-id: 1ab9813d-b734-4fe7-2f67-08db5d112cd6 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 9leHUmzTwagrd+yfr0z2UqaZvE9O+i7DO4X9sTmEeuZ9yFWhzNdEDBkNyCYFT6mMctP9LU4+wiV/6HcVpHNS8KwzIBLM/xJeahQGphAqoLr40KoENF+U85+VeoT+PfhtX2PZnhROvgU/hPX5cpuOQKEHDSFFxHDUuykrdsp2EXG4htQ9bRGWVVHSrB8GH/0RfVi1dJL+PkfN+aNXhssb4J0cp+fZUudde/uFc7kaQMgFLtkHFt4iei3hM2BCMoaYTuVvf+qXSOCDSzZuLqPQsvmPPlfEMGaiGy78eqgontIts7HNUq+de+kQ2NC9Ca0jLOECWuwLMhlgYM4P45R88G7hCDGWuk/z7zFVhMaArI1+zq18oQ4aAb8kzO8npbQSQqumeUB8bYXn0B4h86UAxZZpvqB33qe1EwjeENzIsQELsGv1CHYzjhkZvsruRxWC/MhGQy62BjazPVD5/EKSm+jPeLGyjbHUdHxznkd2T21mmYAXPnO14XeoqxHTQI2xBsaYO8lYc0x4DvKNqErwXmW7qWwB/45fQWy6ihUD/+0PQkcwG759p/S6MrcK8+ugLNi9bxsEUQKdppmPhenS2jSRM/b+BClOX89ptbuDdnAeGCO0jPkeCVNxhXOm2Rzt x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR09MB5583.eurprd09.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(396003)(346002)(39840400004)(366004)(136003)(376002)(451199021)(76116006)(478600001)(91956017)(66946007)(66446008)(66476007)(64756008)(6916009)(66556008)(4326008)(54906003)(41300700001)(52536014)(8676002)(7696005)(316002)(71200400001)(8936002)(5660300002)(26005)(38070700005)(186003)(9686003)(122000001)(2906002)(6506007)(33656002)(38100700002)(55016003)(83380400001)(86362001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?9mqOscmxzRkHA8+CLSnPwiv?= =?iso-8859-1?q?NhN/cQSJ4XegweqA9uTAY6HDbRo7hDVy9qalG45AFxiGXtRLGCoQ6KtDnfv6?= =?iso-8859-1?q?lDMX9AtSiWQVw+mr3yLWjG18SSHUlM5ZeT7lrFbs0+WAhl3BNoxUId0OyMue?= =?iso-8859-1?q?lc6VK5Jm9F9kyGn6KrvBA8xlM6ZM7pgeuEpfkQSDcrX/DgUkouCzHpKNYiez?= =?iso-8859-1?q?rqYtZa1eJzdsD8/63M715WSOZW/uH8F+jwms3Kj26euZymYcYW2uKUv3Yd4B?= =?iso-8859-1?q?x/8lqfUXoSCJgGg76QCi2xhF0WgOLe9gibaBFdL5SbhVxkO7MFJtId1gU9vT?= =?iso-8859-1?q?CnAGgmKqldn7K/Yghi+O2g2Jgt0EpovahWFJsHPSw00en3EzrwvJHkjrHuVi?= =?iso-8859-1?q?BzC8nGoqaw4NJasUk45gt52qEQaFNcJd9e2PSi88dDQdts/VkI27oDJCUN84?= =?iso-8859-1?q?siTcExXPIelWW6foK3Hyp2pJEYV8PMopSJj5+bTqeCZ0bEDThtGkAGAiuh8f?= =?iso-8859-1?q?ZECXzx974hGA/PsEl0nPS9FlaqQ/BlpuUlbsDIL2I2uor11HmcSez+uQ1rNa?= =?iso-8859-1?q?OK5CweLnBuyntJoFXY3QHT2F+P/Apr/E9GQDdGmw1RvErRoS1D1D0wo3UbtA?= =?iso-8859-1?q?IZyNLDQWZ4SbizfsOIPjxIRdzRUh2AH8gKrBgBcOPfGiSe6xgpWhxcLrrYaM?= =?iso-8859-1?q?rJyUq/HPggM7IQYvrvd0DFqn0Z/bJsEnmjBNcPYOZA6QuCuuYz72nrvZVzWS?= =?iso-8859-1?q?y4QHGYpy2Tii29+DIHKF1yS9alWX+bn3mEBlei6soWMyaScitrN7bLx/Oe+a?= =?iso-8859-1?q?92QoR2Ehno3w7tB6E/wUtjaFzG3tsg1c+m069g0WW79cUoY63F23XY7vfyln?= =?iso-8859-1?q?fPh9HH78QzRSXg7SYBvyEeYKh0jxhVnsHpPtd+VNMTgHHcF8yc7EZICOkjQ9?= =?iso-8859-1?q?6Lxe3M+EQphyXe38tbuGFntOnCtUs1T6b67H39Z1/2jBu00hE1f6Dm5pmYnL?= =?iso-8859-1?q?RTpn3PfwdWvPveJLOP1q/rdsMlGyxEKLcqpwy3h7pf1g3uzvfxY5/cyejKXC?= =?iso-8859-1?q?8o5MqKNPaIVt1T9yqGo2yKGDriobrhvxzHATSnUdkFIRdOngU9JYgS7T5ngO?= =?iso-8859-1?q?HOnHXAGsrtfFnd+dWWY6FEMVEe/WamIlom/jYT678VHH4DcBVO1I9wJezjRR?= =?iso-8859-1?q?nMQFgSYl3uod3zUzpi4MDUO1elNtM53zo79qsMcvK4x9tNBTePTTRZ5fyOfp?= =?iso-8859-1?q?0GVsdjR2le5CyC0crpqQik/219SQ2g0j+IhBlJfK0D4ekp/LZXcYQ9T62DxP?= =?iso-8859-1?q?b8jbkWEa72UAxDvXxBDqAVn6C325FmKB4IVwiuxRz0R7mG7oYWaFgmwm2g68?= =?iso-8859-1?q?3iUlTpT6hVKfuts5QqJ/aD1DP/SYpFVeBNgTXKICy0XEpXdCVezvBAYhZmbg?= =?iso-8859-1?q?3w7RjrkQ4k2P0B2SBhL6ul6JZomYMDbOqX6+WBxxEQrS4XW2i4MpRmBmFJfV?= =?iso-8859-1?q?ldkhkYp2D+kMFpsWo4UN9XP7iv+qi0EJ81nAl4NrzXiS+z9MsSEHWnhRFO8W?= =?iso-8859-1?q?ULpbAR2gSnkIOdxiM+SPdr7wjMHq77QsZO/Yl96WUDNHn0KJg6x3DU+BcERf?= =?iso-8859-1?q?ap+usvnJ+MUIQ6HPo?= MIME-Version: 1.0 X-OriginatorOrg: xmos.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PAXPR09MB5583.eurprd09.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ab9813d-b734-4fe7-2f67-08db5d112cd6 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 May 2023 11:14:15.0634 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 975ecfb1-4080-42d2-a01d-4a4d0707a539 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: aeIErheVVwVL9wCUHaU4W1GAxs9Zxhw2U6XAsO66i3oUrsBsrS9ryGuiXxQsXs5+F87OLoFkB2HGmbYYJtn5lg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR09MB6293 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The scoped_value_mark helper class was setting its internal mark value to NULL to indicate that the value chain had already been freed to mark. However, value_mark() also returns NULL if the value chain is empty at the time of call. This lead to the situation that if the value chain was empty at the time the scoped_value_mark was created, the class would not correctly clean up the state when it was destroyed, because it believed it had already been freed. I noticed this because I was setting a watchpoint very early in my debug session, and it was becoming a software watchpoint rather than hardware. Running any command that called evaluate() beforehand (such as 'x 0') would mean that a hardware watchpoint was correctly used. After some careful examination of the differences in execution, I noticed that values were being freed later in the 'bad case', which lead me to notice the issue with scoped_value_mark. --- gdb/value.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 2.25.1 diff --git a/gdb/value.h b/gdb/value.h index a9c77a033ab..fe05ed1d4dd 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -1170,16 +1170,17 @@ class scoped_value_mark /* Free the values currently on the value stack. */ void free_to_mark () { - if (m_value != NULL) + if (!m_freed) { - value_free_to_mark (m_value); - m_value = NULL; + value_free_to_mark (m_value); + m_freed = true; } } private: const struct value *m_value; + bool m_freed = false; }; extern struct value *value_cstring (const char *ptr, ssize_t len,