From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Gy4uBWP7eWnKvxkAWB0awg (envelope-from ) for ; Wed, 28 Jan 2026 07:04:51 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=XSZo4qoL; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=XSZo4qoL; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 01F381E08D; Wed, 28 Jan 2026 07:04:50 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, 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 722411E08D for ; Wed, 28 Jan 2026 07:04:49 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id E825A4BAD14B for ; Wed, 28 Jan 2026 12:04:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E825A4BAD14B Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=XSZo4qoL; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=XSZo4qoL Received: from GVXPR05CU001.outbound.protection.outlook.com (mail-swedencentralazlp170130007.outbound.protection.outlook.com [IPv6:2a01:111:f403:c202::7]) by sourceware.org (Postfix) with ESMTPS id 898424BA2E3E for ; Wed, 28 Jan 2026 12:04:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 898424BA2E3E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 898424BA2E3E Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c202::7 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1769601855; cv=pass; b=CyXQ7ez8hUcx4b/McBnr9uKUNoaowr6NzRL77K8KgNA6SwBl3juF7x75tyPiBx/iJBTMq5D+ER1UU1VNL61fi3DcOK1H1xjwNocF4f1kBYUwLCXAzDw2VKfxL15vEAvmUst8oo3eYLYLdFGK+zmi3pD9UCCIHj49bcuz78tLzqg= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1769601855; c=relaxed/simple; bh=UIYnbFkD1VBd1wPgnuTIHCeACva6UU6QpodemnARUak=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=hAvuXbDSlGptf+WNcrhPrSkwTvaoHmKYXXPMctPnuQ5BYbtux2TrUZj2bdME1xu1nSFVoGEgvsuJKn/5t9Ouda5VSDQUUDrPVuePonYk5UxK/VasF3lqQ8k5piFyjUPn2orot3El0t3mrs9cZQciCBeaFBjOaDm+QiSt0OVmU7Q= ARC-Authentication-Results: i=3; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 898424BA2E3E ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=QnRUDR8ELye4CpDtTekR6gDTlsyfQobSc1PWKzjzouMp2fsDPmj2cNVCYbXmmRcjlpj/HwKNL+FPaqgcHNdWh+7cKqr0FBRRcI7v1Oc76nASgH8MBvEL6sGNleGENVCA/c71YBr1jl6PjZHMPRTB1CT9LPM0G3awFEknyEGZ5DgLeYqVL/gu6NbTCv/jlPOz02lCLoK8aUgt4C9B2Hr4eKlkcaaMHebhoQxELOfAFweN9JsZ0js5EFlypBbj8VJMHxuMwf6yIb5Dg04b94Th3OAOM8yJSfl7Hk89rpMLQCi22+iiEZVBmuUjGljvvL+Of2zfAx5mv5MJXMuHwcoizw== ARC-Message-Signature: i=2; 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=xtWNC8cPFxGBFlZaYxPLMZpVwdhhAChuXo2CfjRWXZY=; b=MYd/N+LsU+AEbxy2l9NZzEJyqSDaaV3pCH1MTIEZpVvFf3rnaxXMEwx3hMYFtmPp/RHvC2O9rcMUA6DBVIXJ+ZBCwod3MKsxFi9kICi3jB27cHQ0Y/udVOeU+v/HPIhexS0AFHwBZ/zkTWGqX32qzhX1F+Ew3yMwDTkwgaxKzx3OetWwZw3AWEOmepyfNZsHz4hkZmuAYUFyDEiLSzQwhUAtT/YfddFJLssvK0cSAF8v59xdtPm8e/2GeOpOTFnEVvzRo4R57bqok1U8x/Y4aLeO73XRGWKqxvgpkilLb3cxNf9gzeWAhNw8hHsQdfUc6c38hWDAsfe3BETfHD33jg== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 4.158.2.129) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xtWNC8cPFxGBFlZaYxPLMZpVwdhhAChuXo2CfjRWXZY=; b=XSZo4qoL/JB7JHqK+vVlwzXbZCHA70Hw4Zh1wiF7+uoNjwCvlxh21R4Ji7m3RFe0t12LytqJvBd6LsHxVFYVJYt/4KxfzIXa2Tb5h8yYSVMSqOr3ahVjOPzkpwODJ/gf2z6nmykiu+S1bRyEbXdTgKRRukY0jd0i9zJI/j8DYcM= Received: from AM0P190CA0001.EURP190.PROD.OUTLOOK.COM (2603:10a6:208:190::11) by GVXPR08MB7701.eurprd08.prod.outlook.com (2603:10a6:150:6d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.15; Wed, 28 Jan 2026 12:03:57 +0000 Received: from AM4PEPF00027A6A.eurprd04.prod.outlook.com (2603:10a6:208:190:cafe::a5) by AM0P190CA0001.outlook.office365.com (2603:10a6:208:190::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.7 via Frontend Transport; Wed, 28 Jan 2026 12:03:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 4.158.2.129) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=arm.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 4.158.2.129 as permitted sender) receiver=protection.outlook.com; client-ip=4.158.2.129; helo=outbound-uk1.az.dlp.m.darktrace.com; pr=C Received: from outbound-uk1.az.dlp.m.darktrace.com (4.158.2.129) by AM4PEPF00027A6A.mail.protection.outlook.com (10.167.16.88) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 12:03:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sVH5IN6xeo82SsF7N/1NB9GOiNRQBbjUOm+EoTVkmUaFDxi82o5Fu1wzCm88lIYpGcKnsZpb6MYTKq53NeqK6X/QKs4HEm0qNhiM8eZk7wvOjBwEu/Ub4lC3wsUZosiQKTA7UDpTY+gj9jf07A9w1Peb/LJT9ir3K/asjh3BDi4DbYyFdYuPm8BvumMGFhWgXFWas9pSNlkASNYKlLupxPGo7tIi0hehVViBgI3XfRKDHL5ejbfKvyZyft7JphvJqEwDtKP36MvuBiPNV0ok+Tg3CndA9qTKGaCEO6V/trkIioQh/DBp7DcePulLd+auE9EJJhrcOQxGjDZlC/Cziw== 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=xtWNC8cPFxGBFlZaYxPLMZpVwdhhAChuXo2CfjRWXZY=; b=T4yelzMQYEaOfj14AP0kA28inT2Z/cIRt12H/2+cVBS9l2B0Z8cWJi7PuXqJHNBxV3EGrdlvzn/L/isNARoNUCztuZIIS5n8UWWqK9qqgAOqPwmX5aMr/Mhs0wq3TLAc5YyPwqYXMHpPZDAlojWSngiIMFsa5G6nRiSRVWEE9N5HFXaHHJPgz+qjsLUEaVkQr/EZFJPoOvY7kGhfutJfMhR5YIXXA4X/f1B+FBvv2jtEmUuxbmth4GEYcS9r1y7Gsez3/p7l83t00grU1O8fkxyaxQDXrw6RrIH97Xha/q6tAWEVA8X5HflIEpcr0eSsCcEOX5geIjhdFu7aifbSpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 172.205.89.229) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xtWNC8cPFxGBFlZaYxPLMZpVwdhhAChuXo2CfjRWXZY=; b=XSZo4qoL/JB7JHqK+vVlwzXbZCHA70Hw4Zh1wiF7+uoNjwCvlxh21R4Ji7m3RFe0t12LytqJvBd6LsHxVFYVJYt/4KxfzIXa2Tb5h8yYSVMSqOr3ahVjOPzkpwODJ/gf2z6nmykiu+S1bRyEbXdTgKRRukY0jd0i9zJI/j8DYcM= Received: from AS4P189CA0031.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:5dd::11) by DU4PR08MB11811.eurprd08.prod.outlook.com (2603:10a6:10:640::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.7; Wed, 28 Jan 2026 12:02:54 +0000 Received: from AMS0EPF000001A7.eurprd05.prod.outlook.com (2603:10a6:20b:5dd:cafe::38) by AS4P189CA0031.outlook.office365.com (2603:10a6:20b:5dd::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.8 via Frontend Transport; Wed, 28 Jan 2026 12:02:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 172.205.89.229) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 172.205.89.229 as permitted sender) receiver=protection.outlook.com; client-ip=172.205.89.229; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (172.205.89.229) by AMS0EPF000001A7.mail.protection.outlook.com (10.167.16.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Wed, 28 Jan 2026 12:02:54 +0000 Received: from AZ-NEU-EX04.Arm.com (10.240.25.138) by AZ-NEU-EX04.Arm.com (10.240.25.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.29; Wed, 28 Jan 2026 12:02:50 +0000 Received: from PF4S4363.arm.com (10.57.53.67) by mail.arm.com (10.240.25.138) with Microsoft SMTP Server id 15.2.2562.29 via Frontend Transport; Wed, 28 Jan 2026 12:02:50 +0000 From: Matthieu Longo To: , Tom Tromey CC: Matthieu Longo Subject: Re: [PATCH v2 4/6] gdb: new setters and getters for __dict__, and attributes Date: Wed, 28 Jan 2026 12:02:39 +0000 Message-ID: <20260128120239.1959325-1-matthieu.longo@arm.com> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AMS0EPF000001A7:EE_|DU4PR08MB11811:EE_|AM4PEPF00027A6A:EE_|GVXPR08MB7701:EE_ X-MS-Office365-Filtering-Correlation-Id: d2f68864-3df6-4879-7e26-08de5e655034 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; ARA:13230040|1800799024|376014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info-Original: =?utf-8?B?UmwyQ2IwZ21zMnRHNmlQam5kaDdFN3h0ZW9qRk54bEdlTnJhTDRCbEMvL2pI?= =?utf-8?B?dUFKSnJQeUFsK3ppNHlmZVpPSVkrcXorWnNyTEd5L0xiRzdaK0l1Qk4ycStH?= =?utf-8?B?S1EyNXZuMzV5SWVGeFpnMUVQUzVmRmt0aUx6UldaMmRhVnYzVStUbFA1ZTVW?= =?utf-8?B?UlVESEVMVDBQNkZyNjRPNFc2bmVxT1NFMHlkdVdtcGVMdUdtY0xsYkpZcmFs?= =?utf-8?B?L0d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Jrak9MUkJNeUtGL01TR0lo?= =?utf-8?B?RjlZWWpUSDFlMmNRSzI4NUdPU0x1aldiVTlPZzBXekxVVU8rSHh1Rm5RbHla?= =?utf-8?B?U0hZWEhJM2ROelNaU3JzRVdrYm9aeE45Szk5L1Z6L2tpendKREpJOHhsd2hE?= =?utf-8?B?V1daektYR09FWkEzSHlkQmRJeWxRcmpmMWdXQjFFZVJZSmZOLzMxVk92VExF?= =?utf-8?B?N1RQMXJiMUJqRWtzK3FwSDVSakpBPT0=?= X-Forefront-Antispam-Report-Untrusted: CIP:172.205.89.229; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(376014)(82310400026)(36860700013); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU4PR08MB11811 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM4PEPF00027A6A.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 0ec69c83-73b0-4651-1d84-08de5e652b26 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|82310400026|376014|35042699022|36860700013|14060799003|13003099007; X-Microsoft-Antispam-Message-Info: =?utf-8?B?TzFFUkFJek5yenVQMFhkempiM21xT0w0dis3bXRPQ2NPdXVYNUgzWkljRGRN?= =?utf-8?B?cGpCVkplWDFFSUxIS1pGNUd2OTVrQnlBdnVyUXh3cUdJR2J2amNzc1ZETEtk?= =?utf-8?B?UHRsOUgraWRJRXBnRWYrbEpRZktqYlVYdXpTSVRWelVvRjlLVW5WZFZnTXFS?= =?utf-8?B?bG4yNUQ3N1dmRC9VZ3hTRkJZWms0dFJSUzc4Tk1nTnRlOWNXTjVTa3cvR2dR?= =?utf-8?B?Qm91cXRaeEJxcEovZHBJUWtmeEZVZUY3QjhlbE5LY1I3Mng1ZE56aXE2SzQy?= =?utf-8?B?b2NsWG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FQRzdPcmJS?= =?utf-8?B?a1JRMnA2a0ZQakxSN2ZhYndUZjJDRDV4NFY4Q2dQeHdYbTdPbFJ3dmlyeS9u?= =?utf-8?B?cWoyWk50Q1RCS09CK3JQSGNEajlEWEdIUTlOVVkxVS9MYXVrcmt3aEE2N1FD?= =?utf-8?B?Uy9iVjNhTHVPckE2WW1haW82bUpnPT0=?= X-Forefront-Antispam-Report: CIP:4.158.2.129; CTRY:GB; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:outbound-uk1.az.dlp.m.darktrace.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(82310400026)(376014)(35042699022)(36860700013)(14060799003)(13003099007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2026 12:03:56.3022 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d2f68864-3df6-4879-7e26-08de5e655034 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[4.158.2.129]; Helo=[outbound-uk1.az.dlp.m.darktrace.com] X-MS-Exchange-CrossTenant-AuthSource: AM4PEPF00027A6A.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR08MB7701 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 GDB is currently using the Python unlimited API. Migrating the codebase to the Python limited API would have for benefit to make a GDB build artifacts compatible with older and newer versions of Python that they were built with. This patch prepares the ground for migrating the existing C extension types from static types to heap-allocated ones, by removing the dependency on tp_dictoffset, which is unavailable when using the limited API. One of the most common incompatibilities in the current static type declarations is the tp_dictoffset slot, which specifies the dictionary offset within the instance structure. Historically, the unlimited API has provided two approaches to supply a dictionary for __dict__: * A managed dictionary. Setting Py_TPFLAGS_MANAGED_DICT in tp_flags indicates that the instances of the type have a __dict__ attribute, and that the dictionary is managed by Python. According to the Python documentation, this is the recommended approach. However, this flag was introduced in 3.12, together with PyObject_VisitManagedDict() and PyObject_ClearManagedDict(), neither of which is part of the limited API (at least for now). As a result, this recommended approach is not viable in the context of the limited API. * An instance dictionary, for which the offset in the instance is provided via tp_dictoffset. According to the Python documentation, this "tp slot" is on the deprecation path, and Py_TPFLAGS_MANAGED_DICT should be used instead. Given the age of the GDB codebase and the requirement to support older Python versions (>= 3.4), no need to argue that today, the implementation of __dict__ relies on tp_dictoffset. However, in the context of the limited API, PyType_Slot does not provide a Py_tp_dictoffset member, so another approach is needed to provide __dict__ to instances of C extension types. Given the constraints of the limited API, the proposed solution consists in providing a dictionary through a common base class, gdbpy__dict__wrapper. This helper class owns a dictionary member corresponding to __dict__, and any C extension type requiring a __dict__ must inherit from it. Since extension object must also be convertible to PyObject, this wrapper class publicly inherits from PyObject as well. Access to the dictionary is provided via a custom getter defined in a PyGetSetDef, similarily to what was previously done with gdb_py_generic_dict(). Because __dict__ participates in attribute look-up, and since this dictionary is neither managed by Python nor exposed via tp_dictoffset, custom implementations of tp_getattro and tp_setattro are required to correctly redirect attribute look-ups to the dictionary. These custom implementations — equivalent to PyObject_GenericGetAttr() and PyObject_GenericSetAttr() — must be installed via tp_getattro / tp_setattro for static types, or Py_tp_getattro / Py_tp_setattro for heap-allocated types. - gdbpy__dict__wrapper: a base class for C extension objects that own a __dict__. - gdb_py_generic_dict_getter: a __dict__ getter for extension types derived from gdbpy__dict__wrapper. - gdb_py_generic_getattro: equivalent of PyObject_GenericGetAttr, but fixes the look-up of __dict__. - gdb_py_generic_setattro: equivalent of PyObject_GenericSetAttr, but fixes the look-up of __dict__. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23830 --- gdb/python/py-corefile.c | 18 +++----- gdb/python/py-event.c | 10 ++-- gdb/python/py-event.h | 8 +--- gdb/python/py-inferior.c | 29 ++---------- gdb/python/py-infthread.c | 10 ++-- gdb/python/py-objfile.c | 18 +++----- gdb/python/py-progspace.c | 18 +++----- gdb/python/py-ref.h | 38 +++++++++++++++ gdb/python/py-type.c | 19 +++----- gdb/python/py-utils.c | 89 +++++++++++++++++++++++++++++++----- gdb/python/python-internal.h | 34 ++++++++++---- 11 files changed, 183 insertions(+), 108 deletions(-) diff --git a/gdb/python/py-corefile.c b/gdb/python/py-corefile.c index 6847722628f..24b573b2dbd 100644 --- a/gdb/python/py-corefile.c +++ b/gdb/python/py-corefile.c @@ -26,20 +26,14 @@ /* A gdb.Corefile object. */ -struct corefile_object +struct corefile_object : public gdbpy_dict_wrapper { - PyObject_HEAD - /* The inferior this core file is attached to. This will be set to NULL when the inferior is deleted, or if a different core file is loaded for the inferior. When this is NULL the gdb.Corefile object is considered invalid.*/ struct inferior *inferior; - /* Dictionary holding user-added attributes. This is the __dict__ - attribute of the object. This is an owning reference. */ - PyObject *dict; - /* A Tuple of gdb.CorefileMappedFile objects. This tuple is only created the first time the user calls gdb.Corefile.mapped_files(), the result is cached here. If this pointer is not NULL then this is an owning @@ -511,8 +505,8 @@ GDBPY_INITIALIZE_FILE (gdbpy_initialize_corefile); static gdb_PyGetSetDef corefile_getset[] = { - { "__dict__", gdb_py_generic_dict, nullptr, - "The __dict__ for the gdb.Corefile.", &corefile_object_type }, + { "__dict__", gdb_py_generic_dict_getter, nullptr, + "The __dict__ for the gdb.Corefile.", nullptr }, { "filename", cfpy_get_filename, nullptr, "The filename of a valid Corefile object.", nullptr }, { nullptr } @@ -548,8 +542,8 @@ PyTypeObject corefile_object_type = 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ + gdb_py_generic_getattro, /*tp_getattro*/ + gdb_py_generic_setattro, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "GDB corefile object", /* tp_doc */ @@ -566,7 +560,7 @@ PyTypeObject corefile_object_type = 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ - offsetof (corefile_object, dict), /* tp_dictoffset */ + 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c index c985159a6f7..8fb21b7fdad 100644 --- a/gdb/python/py-event.c +++ b/gdb/python/py-event.c @@ -101,8 +101,8 @@ GDBPY_INITIALIZE_FILE (gdbpy_initialize_event); static gdb_PyGetSetDef event_object_getset[] = { - { "__dict__", gdb_py_generic_dict, NULL, - "The __dict__ for this event.", &event_object_type }, + { "__dict__", gdb_py_generic_dict_getter, NULL, + "The __dict__ for this event.", NULL }, { NULL } }; @@ -124,8 +124,8 @@ PyTypeObject event_object_type = 0, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ + gdb_py_generic_getattro, /* tp_getattro */ + gdb_py_generic_setattro, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ "GDB event object", /* tp_doc */ @@ -142,7 +142,7 @@ PyTypeObject event_object_type = 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ - offsetof (event_object, dict), /* tp_dictoffset */ + 0, /* tp_dictoffset */ 0, /* tp_init */ 0 /* tp_alloc */ }; diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h index 6c81d64eb4f..ec2e7bc03c5 100644 --- a/gdb/python/py-event.h +++ b/gdb/python/py-event.h @@ -31,12 +31,8 @@ #include "py-event-types.def" #undef GDB_PY_DEFINE_EVENT_TYPE -struct event_object -{ - PyObject_HEAD - - PyObject *dict; -}; +struct event_object : public gdbpy_dict_wrapper +{}; extern int emit_continue_event (ptid_t ptid); extern int emit_exited_event (const LONGEST *exit_code, struct inferior *inf); diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 8230f9d3943..69a7bfa3c37 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -32,25 +32,6 @@ #include "progspace-and-thread.h" #include "gdbsupport/unordered_map.h" -using thread_map_t - = gdb::unordered_map>; - -struct inferior_object -{ - PyObject_HEAD - - /* The inferior we represent. */ - struct inferior *inferior; - - /* thread_object instances under this inferior. This owns a - reference to each object it contains. */ - thread_map_t *threads; - - /* Dictionary holding user-added attributes. - This is the __dict__ attribute of the object. */ - PyObject *dict; -}; - extern PyTypeObject inferior_object_type; /* Deleter to clean up when an inferior is removed. */ @@ -1061,8 +1042,8 @@ GDBPY_INITIALIZE_FILE (gdbpy_initialize_inferior); static gdb_PyGetSetDef inferior_object_getset[] = { - { "__dict__", gdb_py_generic_dict, nullptr, - "The __dict__ for this inferior.", &inferior_object_type }, + { "__dict__", gdb_py_generic_dict_getter, nullptr, + "The __dict__ for this inferior.", nullptr }, { "arguments", infpy_get_args, infpy_set_args, "Arguments to this program.", nullptr }, { "num", infpy_get_num, NULL, "ID of inferior, as assigned by GDB.", NULL }, @@ -1144,8 +1125,8 @@ PyTypeObject inferior_object_type = 0, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ + gdb_py_generic_getattro, /* tp_getattro */ + gdb_py_generic_setattro, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ "GDB inferior object", /* tp_doc */ @@ -1162,7 +1143,7 @@ PyTypeObject inferior_object_type = 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ - offsetof (inferior_object, dict), /* tp_dictoffset */ + 0, /* tp_dictoffset */ 0, /* tp_init */ 0 /* tp_alloc */ }; diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c index e5d3222f9ae..d75742360d4 100644 --- a/gdb/python/py-infthread.c +++ b/gdb/python/py-infthread.c @@ -415,8 +415,8 @@ GDBPY_INITIALIZE_FILE (gdbpy_initialize_thread); static gdb_PyGetSetDef thread_object_getset[] = { - { "__dict__", gdb_py_generic_dict, nullptr, - "The __dict__ for this thread.", &thread_object_type }, + { "__dict__", gdb_py_generic_dict_getter, nullptr, + "The __dict__ for this thread.", nullptr }, { "name", thpy_get_name, thpy_set_name, "The name of the thread, as set by the user or the OS.", NULL }, { "details", thpy_get_details, NULL, @@ -479,8 +479,8 @@ PyTypeObject thread_object_type = 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ + gdb_py_generic_getattro, /*tp_getattro*/ + gdb_py_generic_setattro, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "GDB thread object", /* tp_doc */ @@ -497,7 +497,7 @@ PyTypeObject thread_object_type = 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ - offsetof (thread_object, dict), /* tp_dictoffset */ + 0, /* tp_dictoffset */ 0, /* tp_init */ 0 /* tp_alloc */ }; diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index 8cf365a27dc..36acdb06a25 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -26,17 +26,11 @@ #include "python.h" #include "inferior.h" -struct objfile_object +struct objfile_object : public gdbpy_dict_wrapper { - PyObject_HEAD - /* The corresponding objfile. */ struct objfile *objfile; - /* Dictionary holding user-added attributes. - This is the __dict__ attribute of the object. */ - PyObject *dict; - /* The pretty-printer list of functions. */ PyObject *printers; @@ -739,8 +733,8 @@ Look up a static-linkage global symbol in this objfile and return it." }, static gdb_PyGetSetDef objfile_getset[] = { - { "__dict__", gdb_py_generic_dict, NULL, - "The __dict__ for this objfile.", &objfile_object_type }, + { "__dict__", gdb_py_generic_dict_getter, NULL, + "The __dict__ for this objfile.", NULL }, { "filename", objfpy_get_filename, NULL, "The objfile's filename, or None.", NULL }, { "username", objfpy_get_username, NULL, @@ -785,8 +779,8 @@ PyTypeObject objfile_object_type = 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ + gdb_py_generic_getattro, /*tp_getattro*/ + gdb_py_generic_setattro, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "GDB objfile object", /* tp_doc */ @@ -803,7 +797,7 @@ PyTypeObject objfile_object_type = 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ - offsetof (objfile_object, dict), /* tp_dictoffset */ + 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ objfpy_new, /* tp_new */ diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index ee26b761adb..19f5e533b0a 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -29,17 +29,11 @@ #include "observable.h" #include "inferior.h" -struct pspace_object +struct pspace_object : public gdbpy_dict_wrapper { - PyObject_HEAD - /* The corresponding pspace. */ struct program_space *pspace; - /* Dictionary holding user-added attributes. - This is the __dict__ attribute of the object. */ - PyObject *dict; - /* The pretty-printer list of functions. */ PyObject *printers; @@ -758,8 +752,8 @@ GDBPY_INITIALIZE_FILE (gdbpy_initialize_pspace); static gdb_PyGetSetDef pspace_getset[] = { - { "__dict__", gdb_py_generic_dict, NULL, - "The __dict__ for this progspace.", &pspace_object_type }, + { "__dict__", gdb_py_generic_dict_getter, NULL, + "The __dict__ for this progspace.", NULL }, { "filename", pspy_get_filename, NULL, "The filename of the progspace's main symbol file, or None.", nullptr }, { "symbol_file", pspy_get_symbol_file, nullptr, @@ -821,8 +815,8 @@ PyTypeObject pspace_object_type = 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ + gdb_py_generic_getattro, /*tp_getattro*/ + gdb_py_generic_setattro, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "GDB progspace object", /* tp_doc */ @@ -839,7 +833,7 @@ PyTypeObject pspace_object_type = 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ - offsetof (pspace_object, dict), /* tp_dictoffset */ + 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ diff --git a/gdb/python/py-ref.h b/gdb/python/py-ref.h index b09d88dc30d..4d44ca90e21 100644 --- a/gdb/python/py-ref.h +++ b/gdb/python/py-ref.h @@ -42,4 +42,42 @@ struct gdbpy_ref_policy template using gdbpy_ref = gdb::ref_ptr>; +/* A wrapper class for Python extension objects that have a __dict__ attribute. + + Any Python C object extension needing __dict__ should inherit from this + class. Given that the C extension object must also be convertible to + PyObject, this wrapper class publicly inherits from PyObject as well. + + Access to the dict requires a custom getter defined via PyGetSetDef. + gdb_PyGetSetDef my_object_getset[] = + { + { "__dict__", gdb_py_generic_dict_getter, nullptr, + "The __dict__ for this object.", nullptr }, + ... + { nullptr } + }; + + It is also important to note that __dict__ is used during the attribute + look-up. Since this dictionary is not managed by Python and is not exposed + via tp_dictoffset, custom attribute getter (tp_getattro) and setter + (tp_setattro) are required to correctly redirect attribute access to the + dictionary: + - gdb_py_generic_getattro (), assigned to tp_getattro for static types, + or Py_tp_getattro for heap-allocated types. + - gdb_py_generic_setattro (), assigned to tp_setattro for static types, + or Py_tp_setattro for heap-allocated types. */ +struct gdbpy_dict_wrapper : public PyObject +{ + /* Dictionary holding user-added attributes. + This is the __dict__ attribute of the object. */ + PyObject *dict; + + /* Compute the address of the __dict__ attribute for the given PyObject. */ + static PyObject **compute_addr (PyObject *self) + { + auto *wrapper = reinterpret_cast (self); + return &wrapper->dict; + } +}; + #endif /* GDB_PYTHON_PY_REF_H */ diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index f39cb0240c8..76f001b99da 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -36,13 +36,8 @@ struct type_object : public PyObject extern PyTypeObject type_object_type; /* A Field object. */ -struct field_object -{ - PyObject_HEAD - - /* Dictionary holding our attributes. */ - PyObject *dict; -}; +struct field_object : public gdbpy_dict_wrapper +{}; extern PyTypeObject field_object_type; @@ -1707,8 +1702,8 @@ PyTypeObject type_object_type = static gdb_PyGetSetDef field_object_getset[] = { - { "__dict__", gdb_py_generic_dict, NULL, - "The __dict__ for this field.", &field_object_type }, + { "__dict__", gdb_py_generic_dict_getter, NULL, + "The __dict__ for this field.", NULL }, { NULL } }; @@ -1730,8 +1725,8 @@ PyTypeObject field_object_type = 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ + gdb_py_generic_getattro, /*tp_getattro*/ + gdb_py_generic_setattro, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "GDB field object", /* tp_doc */ @@ -1748,7 +1743,7 @@ PyTypeObject field_object_type = 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ - offsetof (field_object, dict), /* tp_dictoffset */ + 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 131230f80b3..e8485386d8d 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -309,24 +309,91 @@ gdb_py_int_as_long (PyObject *obj, long *result) -/* Generic implementation of the __dict__ attribute for objects that - have a dictionary. The CLOSURE argument should be the type object. - This only handles positive values for tp_dictoffset. */ +/* Generic implementation of the getter for the __dict__ attribute for objects + having a dictionary. The CLOSURE argument is unused. */ PyObject * -gdb_py_generic_dict (PyObject *self, void *closure) +gdb_py_generic_dict_getter (PyObject *self, + void *closure ATTRIBUTE_UNUSED) { - PyObject *result; - PyTypeObject *type_obj = (PyTypeObject *) closure; - char *raw_ptr; + PyObject **py_dict_ptr = gdbpy_dict_wrapper::compute_addr (self); + PyObject *py_dict = *py_dict_ptr; + if (py_dict == nullptr) + { + PyErr_SetString (PyExc_AttributeError, + "This object has no __dict__"); + return nullptr; + } + return Py_NewRef (py_dict); +} - raw_ptr = (char *) self + type_obj->tp_dictoffset; - result = * (PyObject **) raw_ptr; +/* Generic attribute getter function similar to PyObject_GenericGetAttr () but + that should be used when the object has a dictionary __dict__. */ +PyObject * +gdb_py_generic_getattro (PyObject *self, PyObject *attr) +{ + PyObject *value = PyObject_GenericGetAttr (self, attr); + if (value != nullptr) + return value; + + if (! PyErr_ExceptionMatches (PyExc_AttributeError)) + return nullptr; + + gdbpy_ref<> dict (gdb_py_generic_dict_getter (self, nullptr)); + if (dict == nullptr) + return nullptr; + + /* Clear previous AttributeError set by PyObject_GenericGetAttr when it + did not find the attribute, and try to get the attribute from __dict__. */ + PyErr_Clear(); + + value = PyDict_GetItemWithError (dict.get (), attr); + if (value != nullptr) + return Py_NewRef (value); + + /* PyDict_GetItemWithError() has a misleading name that lets one believe that + the function sets PyExc_AttributeError when the key is not found, whereas + it actually does not and only returns NULL. + Not setting the exception for an unfound key causes the raising of another + exception: + : error return without exception set + Hence this surprising manual setting of an exception to makes everything + fit into place. */ + PyErr_Format (PyExc_AttributeError, + "'%s' object has no attribute '%s'", + Py_TYPE (self)->tp_name, + PyUnicode_AsUTF8AndSize (attr, nullptr)); + return nullptr; +} - Py_INCREF (result); - return result; +/* Generic attribute setter function similar to PyObject_GenericSetAttr () but + that should be used when the object has a dictionary __dict__. */ +int +gdb_py_generic_setattro (PyObject *self, PyObject *attr, PyObject *value) +{ + if (PyObject_GenericSetAttr (self, attr, value) == 0) + return 0; + + if (! PyErr_ExceptionMatches (PyExc_AttributeError)) + return -1; + + gdbpy_ref<> dict (gdb_py_generic_dict_getter (self, nullptr)); + if (dict == nullptr) + return -1; + + /* Clear previous AttributeError set by PyObject_GenericGetAttr() when it + did not find the attribute, and try to set the attribute into __dict__. */ + PyErr_Clear(); + + /* Set the new value. + Note: the old value is managed by PyDict_SetItem(), so no need to get + a borrowed reference on it and decrement its reference counter before + setting a new value. */ + return PyDict_SetItem (dict.get (), attr, value); } + + /* Like PyModule_AddObject, but does not steal a reference to OBJECT. */ diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 95619bf775e..f6915a62b7a 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -107,6 +107,15 @@ typedef unsigned long gdb_py_ulongest; #endif /* HAVE_LONG_LONG */ +#if PY_VERSION_HEX < 0x030a0000 +static inline PyObject * +Py_NewRef (PyObject *obj) +{ + Py_INCREF (obj); + return obj; +} +#endif + /* A template variable holding the format character (as for Py_BuildValue) for a given type. */ template @@ -384,22 +393,27 @@ struct gdbpy_breakpoint_object extern gdbpy_breakpoint_object *bppy_pending_object; -struct thread_object +struct thread_object : public gdbpy_dict_wrapper { - PyObject_HEAD - /* The thread we represent. */ struct thread_info *thread; /* The Inferior object to which this thread belongs. */ PyObject *inf_obj; - - /* Dictionary holding user-added attributes. This is the __dict__ - attribute of the object. */ - PyObject *dict; }; -struct inferior_object; +using thread_map_t + = gdb::unordered_map>; + +struct inferior_object : public gdbpy_dict_wrapper +{ + /* The inferior we represent. */ + struct inferior *inferior; + + /* thread_object instances under this inferior. This owns a + reference to each object it contains. */ + thread_map_t *threads; +}; extern struct cmd_list_element *set_python_list; extern struct cmd_list_element *show_python_list; @@ -989,7 +1003,9 @@ gdbpy_ref<> gdb_py_object_from_longest (LONGEST l); gdbpy_ref<> gdb_py_object_from_ulongest (ULONGEST l); int gdb_py_int_as_long (PyObject *, long *); -PyObject *gdb_py_generic_dict (PyObject *self, void *closure); +PyObject *gdb_py_generic_dict_getter (PyObject *self, void *closure); +PyObject *gdb_py_generic_getattro (PyObject *self, PyObject *attr); +int gdb_py_generic_setattro (PyObject *self, PyObject *attr, PyObject *value); int gdb_pymodule_addobject (PyObject *mod, const char *name, PyObject *object); -- 2.52.0