From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gd4mETnFFWoztB0AWB0awg (envelope-from ) for ; Tue, 26 May 2026 12:07:21 -0400 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=XHFA5kes; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=XHFA5kes; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 402D91E0A3; Tue, 26 May 2026 12:07:21 -0400 (EDT) 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 887821E024 for ; Tue, 26 May 2026 12:07:19 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E866A4BA79A9 for ; Tue, 26 May 2026 16:07:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E866A4BA79A9 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=XHFA5kes; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=XHFA5kes Received: from GVXPR05CU001.outbound.protection.outlook.com (mail-swedencentralazon11013067.outbound.protection.outlook.com [52.101.83.67]) by sourceware.org (Postfix) with ESMTPS id CC3E04BA23E1 for ; Tue, 26 May 2026 16:06:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CC3E04BA23E1 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 CC3E04BA23E1 Authentication-Results: sourceware.org; arc=fail smtp.remote-ip=52.101.83.67 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC3E04BA23E1 ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=fail; b=IgJ8eCJ8jBWRCFrtoLBKLVl57vyAQ7XxkGNjxLW3GXQRsIU3ozZOspOG43CGF5X8UhwrHzhx8mNBJ5EqC74T7+Guq0w2KuYFax2cbL1qm7xNf0J5heuh00hzgLKINnVXqZK3t7mc82fktrCsrMvxpIwS54oDzhaMu1mmKAdSWVCYUePh/TTbdA/Lq0wrJ+RQnTwzqHL1JjjYLr7hXl2WL85uTC/NQmaAmTlXciRkt8fJdGOSJ7EnP0Y3WFTCadnFgYH8iSwOL72+hdUAxJSzPyr6flRbEDqJ62VamVhk2ykT/A2F6N+RNA+TYWpozE2AG+DpkfBuRsOl997NJQ+Jmw== 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=hVE3Bgw7wZwNM5lQJ8d3jWW/Qm3yJf4BOx9gXGErMF8=; b=A4xf7FgyH0hva36LmiAoItkRnyT5gUHZ0KvqmjX3Xt4G7R6XB/nvaAe4HGfcCQyCUPe3VhD5WZ6RAkcoxIglSdsuKCfAkM2yWrqxNpqhNvvqEOaNMT7Yut51XRmmhI2BzXdqwkY3dzowXCiuNQx2abpipArpjOi5ZCrEPoOj0fCDxoR1lteiyftQf2xd7pweeqb3RJeeCXkcaU00eI4oq7e6Kexr46YnEPxOcjIurPjwO7GaK7vdbqDMrxjDq/lq4ai/LHyBcsfHK4ZuWVvfAHEAkwSg9+rtUyHcSktJYnCCt78JR0oGN8cHxAqESVODGmHqxXvPmA+JFNeZTsAJbA== 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=fail (48) 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=hVE3Bgw7wZwNM5lQJ8d3jWW/Qm3yJf4BOx9gXGErMF8=; b=XHFA5kesUp7AI1GHkQPebMNOV0vJTb45RiOWyIwXNiOkJczaQRsViEQq5zaXPkxv/S006tbAfjYp1CkSI10g3CmH7yDbCmeBLJiqwFk53mTwMab5qKl04vA9dtATV5QzpobW6stHX8hURVuZMDBVKKnkRgnCDyVKwRw73S2eL6w= Received: from AS9PR05CA0071.eurprd05.prod.outlook.com (2603:10a6:20b:499::8) by FRZPR08MB11162.eurprd08.prod.outlook.com (2603:10a6:d10:13b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.20; Tue, 26 May 2026 16:06:11 +0000 Received: from AMS0EPF000001AC.eurprd05.prod.outlook.com (2603:10a6:20b:499:cafe::4d) by AS9PR05CA0071.outlook.office365.com (2603:10a6:20b:499::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.71.11 via Frontend Transport; Tue, 26 May 2026 16:06:11 +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 AMS0EPF000001AC.mail.protection.outlook.com (10.167.16.152) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Tue, 26 May 2026 16:06:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GexSuVqduVsgH0RqQEzo8Wk3yxOafTDH6OxWBIicHp0dRKExznuVO3EhRLDpr1bqQgrU8k02s44DWqnBqZ/tqFz9wiAQDeSUiWzfY79MG1nshBxe7qT9ZG4AF+2P18y+2U6U+7u/kU5cG9nObu9rEY9fj72uVW1VVQlcdXMyVyugN5l3yjM2RJHO+6VIbrDgj8LgWO42tby01hJf61zp/GAuHAW9lOKbPbS6RyO5aU9aoY+UTTcKoJuFkhCY1CpHM/1gr2fzr6nHg4BcV5u4ehn1xyLTiwtHQjjaWZc9rqi6T/FYYlDEerDDNWclvAQQAMNnkTn4b49THT4dtsfZtg== 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=hVE3Bgw7wZwNM5lQJ8d3jWW/Qm3yJf4BOx9gXGErMF8=; b=dBkg3K3moc6vvAh2ouxMLM489i+yjrQdBmZRoZZaC/h37MTLqILA1FFQt7KgfGJo8vJ/LijZg5GHJYobz0MMkCZraHYiHAZT4fIWOcabmf+wJnW4WIM3KAKTZo6sm3d+YhgqpHTqqu/tmxLaZf5uU6H9ipaAPiWYaKbLMLRj9TKI5Ad6RPGchb11wZKtP3u52XuzaZqJrko1WM7Yg5QQ14gyNeXDOKfPhmkb2Krz2fBQ+X1x2jRmyzf6Mlqo2QQu5kGfCGEwAV7r5V1c4R1Q6Fi21766tZnbA0USdcMmoYcdDzKKawe1xcfwZ41gkAcB+IAfYDXMaHYxLzTnSYF6UA== 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=hVE3Bgw7wZwNM5lQJ8d3jWW/Qm3yJf4BOx9gXGErMF8=; b=XHFA5kesUp7AI1GHkQPebMNOV0vJTb45RiOWyIwXNiOkJczaQRsViEQq5zaXPkxv/S006tbAfjYp1CkSI10g3CmH7yDbCmeBLJiqwFk53mTwMab5qKl04vA9dtATV5QzpobW6stHX8hURVuZMDBVKKnkRgnCDyVKwRw73S2eL6w= Received: from CWLP123CA0195.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:19c::23) by DU0PR08MB8836.eurprd08.prod.outlook.com (2603:10a6:10:47d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.19; Tue, 26 May 2026 16:05:05 +0000 Received: from AMS1EPF0000004C.eurprd04.prod.outlook.com (2603:10a6:400:19c:cafe::34) by CWLP123CA0195.outlook.office365.com (2603:10a6:400:19c::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.48.20 via Frontend Transport; Tue, 26 May 2026 16:05:04 +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 AMS1EPF0000004C.mail.protection.outlook.com (10.167.16.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Tue, 26 May 2026 16:05:04 +0000 Received: from AZ-NEU-EX04.Arm.com (10.240.25.138) by AZ-NEU-EX03.Arm.com (10.240.25.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.29; Tue, 26 May 2026 16:05:00 +0000 Received: from PF4S4363.arm.com (10.57.35.133) by mail.arm.com (10.240.25.138) with Microsoft SMTP Server id 15.2.2562.29 via Frontend Transport; Tue, 26 May 2026 16:05:00 +0000 From: Matthieu Longo To: , Tom Tromey CC: Andrew Burgess , Matthieu Longo Subject: [PATCH v1] gdb/python: fix memory leak in gdb_py_tp_name Date: Tue, 26 May 2026 17:04:59 +0100 Message-ID: <20260526160459.270322-1-matthieu.longo@arm.com> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AMS1EPF0000004C:EE_|DU0PR08MB8836:EE_|AMS0EPF000001AC:EE_|FRZPR08MB11162:EE_ X-MS-Office365-Filtering-Correlation-Id: 1aeb17a4-6b61-4c56-83ff-08debb40b45a x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; ARA:13230040|36860700016|376014|1800799024|82310400026|11063799006|18002099003|56012099006; X-Microsoft-Antispam-Message-Info-Original: /u2uZa+mP361dtZ3j5tM+PbAseFdTCW4yjtiwZZa8mE92uAeM4tbRx0hRwCDNdK0IOLNn9uYat1ralbEhsEoL35wQTJBNh+i4vq2EUCWaN7kuH75d0SvLgaQEEZwqMZnVXHMGd9ir7woTLcJ9m6NA9eSqRqF1iEYpaBJ3DVP9OyN5Uvlx6Tk58EzUbc/9Q33RLspiZFdzi2neUrlNyXeugi1e+Tyo/bR+q329kkmQ8ewU6XmjoaK5vN9hrtRFvTMiqWZYPLxxNOoluQKyUwRESEOtBYm0r9gZH/29sLhfHeX6t/O9uJOCfVk6THQ6RlD/ch0KlFuabEce0XuKlPImdaGdt2k85Et+6AgvlU0fd+XDBCVbvaxcQH8yrtI2hCc7Ndh9O4gYq/6wCzCVZJK/+1ZQHNNTQ8obc70Hbl4tzl0eE9djU4DHtjxgz4ukltp4kbYHSYRJyAf0MFThkXBPg+T5yf16RceG8Zr5SUwEYmr7QtlYQHvVocGz/ewlEMrn7zh04yNTOaaqN65Jmegz8Ak82BtZdHmnDdCwZY+2PfNYn7YIwY1IH9a2Hv3/LSAzS2QXDBU+odMxedlcVMxr7f6oDUYIhks50RnBsoWNYG2D4sn27673usnJ0Gr3Qy++5fnzySw1trZ7/h1cSoAt1A411nVgglwyNONzZ3YFfYbHGZIcazaJeHFm4G+BbLdWW64vPbT3Fw/U38mM/TSEg/dRWJHth9/bVTao/Wbv0w= 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)(36860700016)(376014)(1800799024)(82310400026)(11063799006)(18002099003)(56012099006); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: etZ9E44NV624uKYMXckOoPzpw5CDPQ6mxy5YUXdgJsJQKG8I/FfnczKGH7hSRSg50YQomXgfvOgPy8Tb/3cunVLXnjUYyjZMHv4f26A2HkzxWtwt8Hgw6qQQMvumHSi+ppuKM6vCHf0VDJ0MNP43yJSdGdUZLued+nxnkPEeePsIJjz/l754BrkK1kObi+kFVXA6GJVQ+bAdC8NwFN4RIVA7OHP2EwpxVPZpuzhPOjdseT/4REdyKmUVaebIf/qNvkb6G/eFPpbiHKrvEIrdHt3nKHIQTM5+bw6I7gsglSWU8Je3tybrSmjhZtwho3w37gxh2LY5uXcgre/Hwoz4Fw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8836 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AMS0EPF000001AC.eurprd05.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 28be884d-5a08-44a0-7b40-08debb408cde X-Microsoft-Antispam: BCL:0; ARA:13230040|14060799003|1800799024|376014|82310400026|35042699022|36860700016|11063799006|56012099003|18002099003; X-Microsoft-Antispam-Message-Info: 1or1Ve3SkG0mj9E20CG76IqO8oo9D0U06XNnN+08xVfAXPOZo0wQ0x4NJ6BENLApWEseESfWYYaPpcGZljiu8RSDAADpx/KvFPCzm19itVyvS2cfBTauEkGA0Zwav6ZpUsgZFSc4RzAi92FgfOwbz/IaaDt/9pSruJk/1REoR+kPzeiajfX/PbqDJAYvpEP/pNtbZZ6FoJTTQqO2HMUzSyjUslJz5CX2FEzC1hn2sXXN7pg5hwit7UYhzCYYHP48AI38/d1+UNQF7NgFA0yOqJi0AqyD9UQieo6NMFRqIM0ZSLhGkw2XhyncfONZ9/Gop114yvIYfmsNtmkAnR1AGIPO3msWwERODlx+bs1n7KaygRu+WJl2a+e/kQMgVEiVcVMlgGZo2HgXA4SiPD0S2eHekYZgFk/z/+GXIVzXkCa9XEXep/6OFTTqbAEeKi4WatZOtMlbQDyOMlsaE5Nz0OEozeLTiasKk9UXEH8em3bE/6avPeKOfmEE5CeZS5CwpTBAOyd3r4GGYbO+PoHH2mzc4EjDy/RIAlCCqKYzuIxH17/B3VK3Z7FsE0sKkxSa/zwShfr8PWvWPO9xDUFsnHssH5qZHJt/epzJ3nc2VNhLkNcPfr+rWQ/FpzmgCHbFUZNBeh74KHjUZqzeydXhgtpvkgsoJJnHE6m03k9N+M0dV7ya3SR+FZYb9W3H4XdXrpiEWrI+DsVtUQz+rpdE0zfEDRjgLOZfVNiIhN4g2Do= 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)(14060799003)(1800799024)(376014)(82310400026)(35042699022)(36860700016)(11063799006)(56012099003)(18002099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JqivSi/3sEUon0Cpd+TWXeNbJHYXc2D3aOfqJg7u8ObsbMvVSaNg+O3h/BxifTcop9cDLxcnWVG9QSLftEjy9ADk25fhG39Y1YlNE4XXs7ez7jNmCqDQCsnaN2c55uH0Nczj10NkIXTDeNaUt4EBKxGQIPSvdFNH/uoX+/3wdpPng6aC93/zavNUXXsasoZ2ywVfH2ry4ty3KzQTamtPwP2N2TYqVNPknq3jjbsASzbge/CsGlS/EKhc+1t470zm5aItgVnxki3+ZJ2qeHjHBrd6aXYgNDW9bDgC8ZmiRN3DCUAxr+Vg+YzRZxujtFxt/sICVNSqbPjBMiz/qOLR4l63K0YMTTcYSXmEx+C9bcUXswq5ltvBie93wUn86EfSOYKQrnCQLRRcU+uuKmVZIRCuAJL8HGh1h9V8zEHuBxmXFIApWmaklX1sVy8IfShS X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2026 16:06:11.0253 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1aeb17a4-6b61-4c56-83ff-08debb40b45a 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: AMS0EPF000001AC.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: FRZPR08MB11162 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 The current implementation of gdb_py_tp_name() leaks a reference to the object returned by PyType_GetFullyQualifiedName() for Python >= 3.13, and PyType_GetQualName() for Python >= 3.11. Managing the strong reference on the returned PyObject* with a gdbpy_ref<> fixes the reference count, but also causes the temporary object to be deallocated on function exit. As a consequence, the 'const char *' returned by PyUnicode_AsUTF8AndSize() becomes dangling and can no longer safely be returned. The proposed approach consists in changing gdb_py_tp_name() to return a std::string, and forcing a copy of the 'const char *' value, statically or dynamically allocated, stored in a temporary or non-temporary PyObject, depending on the version of Python it was compiled with. A unfortunate side effect of this fix is that every call sites where the tp_name is printed, must now use `.c_str()' because PyErr_Format() and its siblings cannot handle std::string. --- gdb/python/py-arch.c | 2 +- gdb/python/py-block.c | 2 +- gdb/python/py-breakpoint.c | 6 +++--- gdb/python/py-connection.c | 2 +- gdb/python/py-corefile.c | 2 +- gdb/python/py-disasm.c | 14 +++++++------- gdb/python/py-frame.c | 4 ++-- gdb/python/py-infthread.c | 2 +- gdb/python/py-mi.c | 2 +- gdb/python/py-micmd.c | 4 +++- gdb/python/py-obj-type.c | 12 ++++++------ gdb/python/py-obj-type.h | 4 ++-- gdb/python/py-style.c | 14 +++++++------- gdb/python/py-symbol.c | 2 +- gdb/python/py-type.c | 2 +- gdb/python/py-unwind.c | 8 ++++---- gdb/python/py-utils.c | 5 +++-- gdb/python/python-internal.h | 13 ++++++++----- gdb/python/python.c | 2 +- 19 files changed, 54 insertions(+), 48 deletions(-) diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c index 7a0cb0a2a59..5b3cfbdc876 100644 --- a/gdb/python/py-arch.c +++ b/gdb/python/py-arch.c @@ -343,7 +343,7 @@ archpy_repr (PyObject *self) auto arch_info = gdbarch_bfd_arch_info (gdbarch); return PyUnicode_FromFormat ("<%s arch_name=%s printable_name=%s>", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), arch_info->arch_name, arch_info->printable_name); } diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c index 903f800683a..99c487bc875 100644 --- a/gdb/python/py-block.c +++ b/gdb/python/py-block.c @@ -527,7 +527,7 @@ blpy_repr (PyObject *self) str += ", "; } return PyUnicode_FromFormat ("<%s %s {%s}>", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), name, str.c_str ()); } diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index d1fec6a7700..30d5ea471c2 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -1067,7 +1067,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) static PyObject * bppy_repr (PyObject *self) { - const char *tp_name = gdbpy_py_obj_tp_name (self); + const auto &tp_name = gdbpy_py_obj_tp_name (self); const auto bp = (struct gdbpy_breakpoint_object*) self; if (bp->bp == nullptr) @@ -1083,7 +1083,7 @@ bppy_repr (PyObject *self) str.pop_back (); return PyUnicode_FromFormat ("<%s%s number=%d hits=%d%s>", - tp_name, + tp_name.c_str (), (bp->bp->enable_state == bp_enabled ? "" : " disabled"), bp->bp->number, bp->bp->hit_count, str.c_str ()); @@ -1776,7 +1776,7 @@ bplocpy_repr (PyObject *py_self) } return PyUnicode_FromFormat ("<%s %s>", - gdbpy_py_obj_tp_name (py_self), + gdbpy_py_obj_tp_name (py_self).c_str (), str.c_str ()); } diff --git a/gdb/python/py-connection.c b/gdb/python/py-connection.c index 02330b28068..bc738669b79 100644 --- a/gdb/python/py-connection.c +++ b/gdb/python/py-connection.c @@ -203,7 +203,7 @@ connpy_repr (PyObject *obj) return gdb_py_invalid_object_repr (obj); return PyUnicode_FromFormat ("<%s num=%d, what=\"%s\">", - gdbpy_py_obj_tp_name (obj), + gdbpy_py_obj_tp_name (obj).c_str (), target->connection_number, make_target_connection_string (target).c_str ()); } diff --git a/gdb/python/py-corefile.c b/gdb/python/py-corefile.c index fbefbd267f4..fc5b4889fdc 100644 --- a/gdb/python/py-corefile.c +++ b/gdb/python/py-corefile.c @@ -400,7 +400,7 @@ cfpy_repr (PyObject *self) bfd *core_bfd = get_inferior_core_bfd (obj->inferior); gdb_assert (core_bfd != nullptr); return PyUnicode_FromFormat ("<%s inferior=%d filename='%s'>", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), obj->inferior->num, bfd_get_filename (core_bfd)); } diff --git a/gdb/python/py-disasm.c b/gdb/python/py-disasm.c index e5d7174b7d6..a2abf37a605 100644 --- a/gdb/python/py-disasm.c +++ b/gdb/python/py-disasm.c @@ -312,7 +312,7 @@ disasmpy_info_repr (PyObject *self) const char *arch_name = (gdbarch_bfd_arch_info (obj->gdbarch))->printable_name; return PyUnicode_FromFormat ("<%s address=%s architecture=%s>", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), core_addr_to_string_nz (obj->address), arch_name); } @@ -1003,7 +1003,7 @@ disasmpy_result_init (PyObject *self, PyObject *args, PyObject *kwargs) { PyErr_Format (PyExc_ValueError, _("Cannot use 'string' and 'parts' when creating %s."), - gdbpy_py_obj_tp_name (self)); + gdbpy_py_obj_tp_name (self).c_str ()); return -1; } @@ -1087,7 +1087,7 @@ disasmpy_result_repr (PyObject *self) gdb_assert (obj->parts != nullptr); return PyUnicode_FromFormat ("<%s length=%d string=\"%U\">", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), obj->length, disasmpy_result_str (self)); } @@ -1302,7 +1302,7 @@ gdbpy_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr, PyErr_Format (PyExc_TypeError, _("Result from Disassembler must be gdb.DisassemblerResult, not %s."), - gdbpy_py_obj_tp_name (result.get ())); + gdbpy_py_obj_tp_name (result.get ()).c_str ()); gdbpy_print_stack (); return std::optional (-1); } @@ -1391,7 +1391,7 @@ disasmpy_part_init (PyObject *self, PyObject *args, PyObject *kwargs) { PyErr_Format (PyExc_RuntimeError, _("Cannot create instances of %s."), - gdbpy_py_obj_tp_name (self)); + gdbpy_py_obj_tp_name (self).c_str ()); return -1; } @@ -1428,7 +1428,7 @@ disasmpy_text_part_repr (PyObject *self) gdb_assert (obj->string != nullptr); return PyUnicode_FromFormat ("<%s string='%s', style='%s'>", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), obj->string->c_str (), get_style_name (obj->style)); } @@ -1471,7 +1471,7 @@ disasmpy_addr_part_repr (PyObject *self) disasm_addr_part_object *obj = (disasm_addr_part_object *) self; return PyUnicode_FromFormat ("<%s address='%s'>", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), core_addr_to_string_nz (obj->address)); } diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index 0a1a0dffbf9..859b8bdbb6e 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -97,7 +97,7 @@ frapy_repr (PyObject *self) const frame_id &fid = frame_obj->frame_id; return PyUnicode_FromFormat ("<%s level=%d frame-id=%s>", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), frame_relative_level (f_info), fid.to_string ().c_str ()); } @@ -545,7 +545,7 @@ frapy_read_var (PyObject *self, PyObject *args, PyObject *kw) { PyErr_Format (PyExc_TypeError, _("argument 1 must be gdb.Symbol or str, not %s"), - gdbpy_py_obj_tp_name (sym_obj)); + gdbpy_py_obj_tp_name (sym_obj).c_str ()); return NULL; } diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c index ddb67a284ac..96c736495a8 100644 --- a/gdb/python/py-infthread.c +++ b/gdb/python/py-infthread.c @@ -354,7 +354,7 @@ thpy_repr (PyObject *self) thread_info *thr = thread_obj->thread; return PyUnicode_FromFormat ("<%s id=%s target-id=\"%s\">", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), print_full_thread_id (thr), target_pid_to_str (thr->ptid).c_str ()); } diff --git a/gdb/python/py-mi.c b/gdb/python/py-mi.c index 1bcb276da8a..73daefecb20 100644 --- a/gdb/python/py-mi.c +++ b/gdb/python/py-mi.c @@ -379,7 +379,7 @@ gdbpy_notify_mi (PyObject *self, PyObject *args, PyObject *kwargs) PyErr_Format (PyExc_ValueError, _("MI notification data must be either None or a dictionary, not %s"), - gdbpy_py_obj_tp_name (data)); + gdbpy_py_obj_tp_name (data).c_str ()); return nullptr; } diff --git a/gdb/python/py-micmd.c b/gdb/python/py-micmd.c index 9ae7fc51bee..9f6e664a5f2 100644 --- a/gdb/python/py-micmd.c +++ b/gdb/python/py-micmd.c @@ -511,7 +511,9 @@ micmdpy_set_installed (PyObject *self, PyObject *newvalue, void *closure) { PyErr_Format (PyExc_TypeError, _("gdb.MICommand.installed must be set to a bool, not %s"), - newvalue == Py_None ? "None" : gdbpy_py_obj_tp_name (newvalue)); + (newvalue == Py_None + ? "None" + : gdbpy_py_obj_tp_name (newvalue).c_str ())); return -1; } diff --git a/gdb/python/py-obj-type.c b/gdb/python/py-obj-type.c index ea0b59a8447..6d428b355b8 100644 --- a/gdb/python/py-obj-type.c +++ b/gdb/python/py-obj-type.c @@ -21,17 +21,17 @@ #include "py-obj-type.h" /* Return the type's fully qualified name from a PyTypeObject. */ -const char * +std::string gdb_py_tp_name (PyTypeObject *py_type) noexcept { #if PY_VERSION_HEX >= 0x030d0000 /* Note: PyType_GetFullyQualifiedName() was added in version 3.13, and is part of the stable ABI since version 3.13. */ - PyObject *fully_qualified_name = PyType_GetFullyQualifiedName (py_type); + gdbpy_ref<> fully_qualified_name (PyType_GetFullyQualifiedName (py_type)); if (fully_qualified_name == nullptr) return nullptr; - return PyUnicode_AsUTF8AndSize (fully_qualified_name, nullptr); + return PyUnicode_AsUTF8AndSize (fully_qualified_name.get (), nullptr); #else /* PY_VERSION_HEX < 0x030d0000 && ! defined (Py_LIMITED_API) */ /* For non-heap types, the fully qualified name corresponds to tp_name. */ @@ -44,11 +44,11 @@ gdb_py_tp_name (PyTypeObject *py_type) noexcept # if PY_VERSION_HEX >= 0x030b0000 /* Note: PyType_GetQualName() was added in version 3.11. */ - PyObject *qualname = PyType_GetQualName (py_type); + gdbpy_ref<> qualname (PyType_GetQualName (py_type)); if (qualname == nullptr) return nullptr; - return PyUnicode_AsUTF8AndSize (qualname, nullptr); + return PyUnicode_AsUTF8AndSize (qualname.get (), nullptr); # else /* In the absence of PyType_GetQualName(), fallback on using PyHeapTypeObject @@ -66,7 +66,7 @@ gdb_py_tp_name (PyTypeObject *py_type) noexcept } /* Return the type's fully qualified name from a PyObject. */ -const char * +std::string gdbpy_py_obj_tp_name (PyObject *self) noexcept { /* Note: Py_TYPE () is part of the stable ABI since version 3.14. */ diff --git a/gdb/python/py-obj-type.h b/gdb/python/py-obj-type.h index 293647fabfb..ac6c6aa3296 100644 --- a/gdb/python/py-obj-type.h +++ b/gdb/python/py-obj-type.h @@ -21,9 +21,9 @@ #define GDB_PYTHON_PY_OBJ_TYPE_H /* Return the type's fully qualified name from a PyTypeObject. */ -extern const char *gdb_py_tp_name (PyTypeObject *py_type) noexcept; +extern std::string gdb_py_tp_name (PyTypeObject *py_type) noexcept; /* Return the type's fully qualified name from a PyObject. */ -extern const char *gdbpy_py_obj_tp_name (PyObject *self) noexcept; +extern std::string gdbpy_py_obj_tp_name (PyObject *self) noexcept; #endif /* GDB_PYTHON_PY_OBJ_TYPE_H */ diff --git a/gdb/python/py-style.c b/gdb/python/py-style.c index c45eba60867..a27a1ab75a7 100644 --- a/gdb/python/py-style.c +++ b/gdb/python/py-style.c @@ -269,7 +269,7 @@ stylepy_init_from_parts (PyObject *self, PyObject *fg, PyObject *bg, PyErr_Format (PyExc_TypeError, _("'foreground' argument must be gdb.Color or None, not %s."), - gdbpy_py_obj_tp_name (fg)); + gdbpy_py_obj_tp_name (fg).c_str ()); return -1; } @@ -278,7 +278,7 @@ stylepy_init_from_parts (PyObject *self, PyObject *fg, PyObject *bg, PyErr_Format (PyExc_TypeError, _("'background' argument must be gdb.Color or None, not %s."), - gdbpy_py_obj_tp_name (bg)); + gdbpy_py_obj_tp_name (bg).c_str ()); return -1; } @@ -485,7 +485,7 @@ stylepy_set_foreground (PyObject *self, PyObject *newvalue, void *closure) if (!gdbpy_is_color (newvalue)) { PyErr_Format (PyExc_TypeError, _("value must be gdb.Color, not %s"), - gdbpy_py_obj_tp_name (newvalue)); + gdbpy_py_obj_tp_name (newvalue).c_str ()); return -1; } @@ -543,7 +543,7 @@ stylepy_set_background (PyObject *self, PyObject *newvalue, void *closure) if (!gdbpy_is_color (newvalue)) { PyErr_Format (PyExc_TypeError, _("value must be gdb.Color, not %s"), - gdbpy_py_obj_tp_name (newvalue)); + gdbpy_py_obj_tp_name (newvalue).c_str ()); return -1; } @@ -625,7 +625,7 @@ stylepy_set_intensity (PyObject *self, PyObject *newvalue, void *closure) PyErr_Format (PyExc_TypeError, _("value must be a Long (a gdb.INTENSITY constant), not %s"), - gdbpy_py_obj_tp_name (newvalue)); + gdbpy_py_obj_tp_name (newvalue).c_str ()); return -1; } @@ -735,12 +735,12 @@ stylepy_repr (PyObject *self) if (style_obj->style_name == nullptr) return PyUnicode_FromFormat ("<%s fg=%s, bg=%s, intensity=%s>", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), fg_str.get (), bg_str.get (), intensity_str); else return PyUnicode_FromFormat ("<%s name='%s', fg=%s, bg=%s, intensity=%s>", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), style_obj->style_name, fg_str.get (), bg_str.get (), intensity_str); } diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index 5b1d843a36f..5840a3f5720 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -384,7 +384,7 @@ sympy_repr (PyObject *self) return gdb_py_invalid_object_repr (self); return PyUnicode_FromFormat ("<%s print_name=%s>", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), symbol->print_name ()); } diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index c002d97d0c6..7831e838481 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -1086,7 +1086,7 @@ typy_repr (PyObject *self) host_charset (), NULL); return PyUnicode_FromFormat ("<%s code=%s name=%U>", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), code, py_typename); } diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index 7ec87367d0a..13eced4cecb 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -252,7 +252,7 @@ unwind_infopy_repr (PyObject *self) if (pending_frame->frame_info == nullptr) return PyUnicode_FromFormat ("<%s for an invalid frame>", - gdbpy_py_obj_tp_name (self)); + gdbpy_py_obj_tp_name (self).c_str ()); std::string saved_reg_names; struct gdbarch *gdbarch = pending_frame->gdbarch; @@ -268,7 +268,7 @@ unwind_infopy_repr (PyObject *self) const frame_info_ptr &frame (*pending_frame->frame_info); return PyUnicode_FromFormat ("<%s frame #%d, saved_regs=(%s)>", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), frame_relative_level (frame), saved_reg_names.c_str ()); } @@ -464,7 +464,7 @@ pending_framepy_repr (PyObject *self) } return PyUnicode_FromFormat ("<%s level=%d, sp=%s, pc=%s>", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), frame_relative_level (frame), sp_str, pc_str); @@ -939,7 +939,7 @@ frame_unwind_python::sniff (const frame_info_ptr &this_frame, gdb_assert (pyo_unwind_info != nullptr); if (!PyObject_TypeCheck (pyo_unwind_info, &unwind_info_object_type)) error (_("an Unwinder should return gdb.UnwindInfo, not %s."), - gdbpy_py_obj_tp_name (pyo_unwind_info)); + gdbpy_py_obj_tp_name (pyo_unwind_info).c_str ()); { unwind_info_object *unwind_info = diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 96f1cb1ee31..a831b96eb38 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -362,7 +362,7 @@ gdb_py_generic_getattro (PyObject *self, PyObject *attr) Therefore, we must explicitly raise an AttributeError in this case. */ PyErr_Format (PyExc_AttributeError, "'%s' object has no attribute '%s'", - gdbpy_py_obj_tp_name (self), + gdbpy_py_obj_tp_name (self).c_str (), PyUnicode_AsUTF8AndSize (attr, nullptr)); return nullptr; } @@ -700,5 +700,6 @@ gdbpy_fix_doc_string_indentation (gdb::unique_xmalloc_ptr doc) PyObject * gdb_py_invalid_object_repr (PyObject *self) { - return PyUnicode_FromFormat ("<%s (invalid)>", gdbpy_py_obj_tp_name (self)); + return PyUnicode_FromFormat ("<%s (invalid)>", + gdbpy_py_obj_tp_name (self).c_str ()); } diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 10c984bad4b..0cc5fc4ac06 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -1132,15 +1132,18 @@ gdbpy_type_ready (PyTypeObject *type, PyObject *mod = nullptr) { if (PyType_Ready (type) < 0) return -1; - const char *tp_name = gdb_py_tp_name (type); + const auto &tp_name = gdb_py_tp_name (type); + std::string_view tp_name_s = tp_name; if (mod == nullptr) { - gdb_assert (startswith (tp_name, "gdb.")); + gdb_assert (startswith (tp_name_s, "gdb.")); mod = gdb_module; } - const char *dot = strrchr (tp_name, '.'); - gdb_assert (dot != nullptr); - return gdb_pymodule_addobject (mod, dot + 1, (PyObject *) type); + const auto pos_dot = tp_name_s.find_last_of ('.'); + gdb_assert (pos_dot != tp_name_s.npos); + return gdb_pymodule_addobject (mod, + tp_name_s.substr (pos_dot + 1).data (), + (PyObject *) type); } /* Poison PyType_Ready. Only gdbpy_type_ready should be used, to diff --git a/gdb/python/python.c b/gdb/python/python.c index e6d58f2f16a..2131c4a0648 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1581,7 +1581,7 @@ gdbpy_write (PyObject *self, PyObject *args, PyObject *kw) PyErr_Format (PyExc_TypeError, _("'style' argument must be gdb.Style or None, not %s."), - gdbpy_py_obj_tp_name (style_obj)); + gdbpy_py_obj_tp_name (style_obj).c_str ()); return nullptr; } -- 2.54.0