From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +QrIJVyIsmqY9DIAWB0awg (envelope-from ) for ; Tue, 22 Sep 2026 09:53:32 -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=ZAQcZSNF; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=ZAQcZSNF; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8BB481E06B; Tue, 22 Sep 2026 09:53:32 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 5D88E1E01F for ; Tue, 22 Sep 2026 09:53:30 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A2EB24BB1C27 for ; Tue, 22 Sep 2026 13:53:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2EB24BB1C27 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=ZAQcZSNF; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=ZAQcZSNF Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11010068.outbound.protection.outlook.com [52.101.84.68]) by sourceware.org (Postfix) with ESMTPS id 84DAB4BAE7C4 for ; Tue, 22 Sep 2026 13:52:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 84DAB4BAE7C4 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 84DAB4BAE7C4 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=52.101.84.68 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1790085173; cv=pass; b=bJX4eSxDTyOGotQ2+CU12OttePLXZ0B/F0ErBwJ8b1Y8asRDOEv+tWcz48U3lKSlkHiukadYrRbrTZm9ARLAqbp1SLsfiIaMqwLHfewA6rJOFbY/ANyeku0/H/M4/KbhJmlXtMjbC0PfsY6AC2OkcoWXzF1UUQMNn34LCHox+Wg= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1790085173; c=relaxed/simple; bh=E4wsfhxuKmuU+bBB0t1pBaXQJEG95fTPHtZawXC9wbU=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=gfNa0TuZGVyTV/Y0USyFI8NwzwEsAO59cQg6bY35jpbuigZAKQUYJWp1KApb5vjuerymrVkCI4gB+NJnv/yyrEWp7eyZkEuYCXTxbA916HbZgDw4CUMp08KXUPqXAF5Sgor+GpC4qwD+5uU2MK9TzA4fTZNktA+FsMMehgI630Q= ARC-Authentication-Results: i=3; 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=ZAQcZSNF; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=ZAQcZSNF DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 84DAB4BAE7C4 ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=ENoQOFbQ5DTrWV5N451RD0XO2lFwj6hkA6iomaprsSGxX+nPqaPJzJ2Llc1lcNibhfnwaGs0iBGpoh8MrgUuDUqNOgTkZN0UgaTsk+VqY8mQVJJsBk+V9Rt7l2SvC4IlvC7/p1KfiGnNKXZoRu6fRRRogvnwpuiO26Henem3f+TxCgjI9qrD0k8a6PK9vp59BFV9shPhS8572pPtNic2bOhm1jfle4GOYJLLUuyNGwUalz8DBSaviQj4A6kz0OSe9oM+R/ojnO3FCNioW4P81sZ2nlC4gOxbxRC66pfgxxmqa06PnAcQ9nM27jdyJQ0pf+8kiydD0Thk41Wtt6Khww== 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=amB8E/I1WO2wVd89gi6oQQ/ZxmEtRFnoV1Usqcjx+6Q=; b=Zxy1Le4Sehk+AKM8D85VTfOSVyC1W/22sLmh7qB9kx14JYUyI8+rNl5wFFUFhKAlPXnG7UKFAYr0o/tbYVD8j5ti7JBG7qEd8kXPBm9pDymISrhVd9L8ONkGnsWFff4o0Fg9HR5o3esMpf9e8vfnmP/MJkhFBFtm6cAMjC+SwIKygY2bOIXSFXdWUsD+XUmJbS8Yyke0OaZKNspp/MW1xc7MBAkaFygwKh/RclkkKj5awiM/5fKhQolr95nc2RRp1iRAxLEO0a29CyCDLhbfWeXbkN8aB/LxhAdlgFtOrkCQpUGn7zO7BIj7GLZTiCZQwlIpqx7Mf45U5GQK8heC8Q== 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=amB8E/I1WO2wVd89gi6oQQ/ZxmEtRFnoV1Usqcjx+6Q=; b=ZAQcZSNF2BFnpHYyhPD+BjF5GCRjWWcNtC6R/HMFPeKaJVPemSD7qCNglTvkeS+U7Ydz9jSma0o4qbD73L6jMGTYkstwpgi1MfTwh7IhIX54SCpr2KC5xmvTn7rMrEsYoi8pSbPJysQMDdxdg7doaLTdmjsqOQhcuKMQbre646g= Received: from PAZP264CA0014.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:21::19) by AS2PR08MB9367.eurprd08.prod.outlook.com (2603:10a6:20b:595::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.13; Tue, 22 Sep 2026 13:52:39 +0000 Received: from ZR1PEPF0000E6B7.eurprd07.prod.outlook.com (2603:10a6:102:21:cafe::22) by PAZP264CA0014.outlook.office365.com (2603:10a6:102:21::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.16 via Frontend Transport; Tue, 22 Sep 2026 13:52:39 +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 ZR1PEPF0000E6B7.mail.protection.outlook.com (10.167.241.70) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.451.8 via Frontend Transport; Tue, 22 Sep 2026 13:52:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=or0aYeN2Tzus9WBRrGB9UJWnLuY7FNiubRvBI2d/T77diMEBKfvbVzwoPekhFDrc9oy9a5bolr5CnE/uo7iw1UIV6rlEoGOsPvYQcPjAicM8C0JWB1AqeQiH7USknQbPA7Eqnw3g/JIObmUaGmSFWI2wDbLLcRMBOw3PthxggEiPF889X4YAnX0wdlHLMTDpijYh0PpO8CriH9pwCB7hhV4gWaK8qB5BDQEE69GvZkcK5SjwVcrtD0G3kqKzBUGyMs9UKzSJHps9vZbs0v7yXvw948x9cV4pLly+fDwHt9XrG+N4jrdJysl4de+JD0LMqf9zuNj2LNvGt2I7LS/bdA== 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=amB8E/I1WO2wVd89gi6oQQ/ZxmEtRFnoV1Usqcjx+6Q=; b=YWCR1wguzuqlnw9DDUr73l/gjP7bk4tVzxCIIrSDMJcPQMC5JE+XTOmAuB8bwNFsXDYOal1bCu4ZJ9BMNhiJsQ9vht0cd+qSb+c31d26zuY7HfEmFyILtSb5Gcu/er39jV1BxZKq5B+fiWCtxLXMPYR+ByGZ+p4qFIUo2aOTRkMXcsoky3xfhwHaLXUd9XtkCNv7osEgqkZ9Md9Z7aPm0pEM2loGLZDfvOG2MnPTBWWAWQaYZKjACRjUOtq44CeAr1WzSj0zSfpI+q0rq8zKFt58RPVfQhOKTuKu9t9b7zwU1HJoDxmtU6U4HorM+fx7ZP/Ws6KOkr82sZDs89BBNw== 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=amB8E/I1WO2wVd89gi6oQQ/ZxmEtRFnoV1Usqcjx+6Q=; b=ZAQcZSNF2BFnpHYyhPD+BjF5GCRjWWcNtC6R/HMFPeKaJVPemSD7qCNglTvkeS+U7Ydz9jSma0o4qbD73L6jMGTYkstwpgi1MfTwh7IhIX54SCpr2KC5xmvTn7rMrEsYoi8pSbPJysQMDdxdg7doaLTdmjsqOQhcuKMQbre646g= Received: from DUZPR01CA0083.eurprd01.prod.exchangelabs.com (2603:10a6:10:46a::19) by PAWPR08MB8935.eurprd08.prod.outlook.com (2603:10a6:102:33f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.13; Tue, 22 Sep 2026 13:52:01 +0000 Received: from MA3PEPF00000404.eurprd04.prod.outlook.com (2603:10a6:10:46a:cafe::86) by DUZPR01CA0083.outlook.office365.com (2603:10a6:10:46a::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.451.14 via Frontend Transport; Tue, 22 Sep 2026 13:52:01 +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 MA3PEPF00000404.mail.protection.outlook.com (10.167.241.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.8 via Frontend Transport; Tue, 22 Sep 2026 13:52:00 +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, 22 Sep 2026 13:52:00 +0000 Received: from PF4S4363.arm.com (10.0.144.159) by mail.arm.com (10.240.25.138) with Microsoft SMTP Server id 15.2.2562.29 via Frontend Transport; Tue, 22 Sep 2026 13:51:59 +0000 From: Matthieu Longo To: CC: Andrew Burgess , Tom Tromey , Matthieu Longo , Thiago Jung Bauermann , Christina Joos Subject: [PATCH v3 6/8] gdb: introduce helper class target_file_reader Date: Tue, 22 Sep 2026 14:50:48 +0100 Message-ID: <20260922135050.236941-7-matthieu.longo@arm.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260922135050.236941-1-matthieu.longo@arm.com> References: <20260922135050.236941-1-matthieu.longo@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: MA3PEPF00000404:EE_|PAWPR08MB8935:EE_|ZR1PEPF0000E6B7:EE_|AS2PR08MB9367:EE_ X-MS-Office365-Filtering-Correlation-Id: 195ecc8d-b6e4-4a1f-d9e5-08df18b0c364 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|23010399003|376014|82310400026|36860700016|6133799003|10067099003|5023799004|56012099006|11063799006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info-Original: +q0gJhCi3EAC99nKtxufPCC7g30tJf4m8imiLFu9HdQsC3uvWRfVHsIpVxtcDVV/E6PtN5ieCz23w2O3PwPxNpi1sQ4GODoaLiACHnifYHmVctCAT+1eTjl/cl68WvjZhq0GuxdwNWmL7cu80mkMaO7JJwDPk4UfwGgyp7neaUYqgrUbNOlntV1MFrOOggymbc4yN4mSSFzLGGjpADvEBfsog+O7K0gz4bKnGIEKvRKABDfY4rLPhKbyJTX3wOTOKLUCe+/MAODto5/64SxG7lwzHNHaWVkSL55FcryzIKWhJrOrjD8kA69JkkZZ8Lqf96VFlb4ZOML/3smNWwav2e5GQmEviU3EKPRNT0/uXbPvIsA+lo3+QF72jl8o/85B9c4+W5/G5s3yk5vz9xossoa+lqXWel91AzxMICobF11GUq0oH3y8/QVhmu61Jce3r6q3M8doXlH6qJWeJXYy4DAH5RxJfvJwhsHW+C2gslH9sQeDs4dMMnaD+1hs7bZpeYx6rXfaJNpWVxd+WfystrsSe1yh/LbskOyHSdzmsMuYUVg3aLqUcQ8xfQLF3CR9Owt5p2lYkD1szWIHXGUqjU2333GxGtjpNVHnlCgqL28FGzctY8iAJbU+h2wdFeB8NSeN3EzQk8gnHp8Cm2ePiesHqvG/+YGqKYMBvtcI8+bYrTKQ4RNPWH5DGdIrsOF6AwV7V5JyQtPTae+IItUUKA== 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)(23010399003)(376014)(82310400026)(36860700016)(6133799003)(10067099003)(5023799004)(56012099006)(11063799006)(22082099003)(18002099003); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: 05PaAR5g1/7zNumidDQ5ZcSm1bIJOpQ29ggHzjCLRn1U+hRisDHsuk33kTYKcKw9XVMgjpfvS9my+soQxdcnIrsaV1Z4//JT45WZ4WeZ3xZqmuKow9UYoazI/rxBZiz8q1GN7gITHcjKGhS9octWmqKwOy/jOt1D96NMMbT2kTG8KP7b3dUg+B4sRgIswVGV+RTyLQlgDjXyNB3T23BjiUjuHmfbNT/CcXeBLFjqywMdCLtltDXStgqa1th7DvJ6sS272YPAEFs/uelWiFpVYK9zsojsqmTDxwgKQpjPsvqcRbMigTu58OxK/h4AO2ln6EYXT14ghK3BrH1ebVRRyA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB8935 X-MS-Exchange-Transport-CrossTenantHeadersStripped: ZR1PEPF0000E6B7.eurprd07.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 30f00f29-aae5-442c-7780-08df18b0ad3a X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|14060799003|376014|35042699022|23010399003|82310400026|36860700016|6133799003|5023799004|10067099003|11063799006|56012099006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: vhTohWjEY75IxkwV/NQ5Y/oc6lQi5zyUD/Mwi7vfFB0ERiTxeBWkKNCgF/tNEappZVf9NINqglLsUooyicl6vIsKJF4VmS7f04u1cIPmF/mnICbKS8WMcNWLd/Bkp5UsocFHivVJKfzQCIkfCWGSQCmwydom8mnq50BQBpnv236025XlTBJ6daRAF+yvxjDkr/wYiNkC4hkc2LY3JLLIvhcBhfzWLKQvMgyUvcckhVKdY4zYhgtoxwLIFmh/uCcL6+RxRKgE58mvbzYPe47zJk4A22cNMANDIgBSNZyHl9j/U+70cfwrbLQJd56Z8sSAxJBlqs/3m6Lw6by689VuKdLO3mXdKl1wGwcCOXv4GtbtmfKLwmVRwgGmIF4nHUOUzZJ4DV0za7zYn+hZH7CBYIKGh+zQ+lmxXcFmv1Q1k6x2E4EDHRrLpbdM5DAJE/VaFGfZzzDIdZKdiCKKC8o09ws3FReldPa5thTHybT7ntZZQCX+CoGAhBNb2awUnabmCkcRP/02BWUe2GFWE9A75RwaH1q18hpxcgQxNWd6xUsBxV6KKBZGwuWmyYuAMYpAg8Cc0PkyFoiHqOhgWI/Kl7/JSARoBzizpdO5rpf4QaxGqIJGTbTVC89F3cheP8jGarONWH6PPg+Ve9lMKqK4oxejT63KQf72xsw9hdUnp5LtUpWE90UGezc7SIRar/l5ODUGhAHtOG4uYTWHMYbXxQ== 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)(14060799003)(376014)(35042699022)(23010399003)(82310400026)(36860700016)(6133799003)(5023799004)(10067099003)(11063799006)(56012099006)(22082099003)(18002099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YpGX3v2zOS5eM+EMc6mMn2M8aPPRXgdXdej/z2mN2BnZkjsvZNdWjI1GNjCWWdPRhZnWn3m7UmALVbXjBuUjY+VNXBcIPJfI1O9nlFc36s0kT9t95FYBFDQ+Rclm1V8zv6JeAh9aX96YoB/KkvOTQH9Vd2lv70y9cZwJO/b4njZOtipu5amwkCkAkRyyIqcoioTnxnjcD05fz16qTrWTIoqtTSAeHenxXOhfdLTTrVkEntrp+F858Huy82+Z5FKeeS6O1Pefgn7DVFvYdSfBmJtLXBhOPrZqt0UBZt/RXaopf2DM+sNzUW1FzlWIW5nkuQoYqTvYapPWFols+nIrKpFAJyC5FbRL7LLJBvzfaeys2onOWDj+9tLLaGNU1QVNZt74KsLoanXoy0MPOJPnzNBqlspzI6SsXtzAIzmdqVBSgLSpK7Fh3wdvPjOPQN+e X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2026 13:52:37.9565 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 195ecc8d-b6e4-4a1f-d9e5-08df18b0c364 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: ZR1PEPF0000E6B7.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB9367 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 Wrap all the boilerplate code required to read a file in a new helper class: target_file_reader. The class owns the file contents together with the file path, and provides convenient accessors for the data, size and typed views. It supports both null-terminated text files and binary files. This helper eliminates repeated calls to target_fileio_read_stralloc and target_fileio_read_alloc, removes explicit memory management with gdb::unique_xmalloc_ptr, and simplifies the casting logic when working with binary data. The patch converts some of the existing Linux, AMD64, and SPARC code that reads files from /proc to use target_file_reader. As a side effect, amd64_linux_lam_untag_mask and linux_process_address_in_memtag_page may now return earlier in case the file is empty. Reviewed-By: Thiago Jung Bauermann Reviewed-By: Christina Joos --- gdb/amd64-linux-tdep.c | 12 ++-- gdb/linux-tdep.c | 121 ++++++++++++++++++----------------------- gdb/sparc64-tdep.c | 17 +++--- gdb/target.h | 116 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 83 deletions(-) diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c index 9b23db72bbe..f8d48084403 100644 --- a/gdb/amd64-linux-tdep.c +++ b/gdb/amd64-linux-tdep.c @@ -1848,14 +1848,12 @@ amd64_linux_lam_untag_mask () if (inf->fake_pid_p) return DEFAULT_TAG_MASK; - const std::string filename = string_printf ("/proc/%d/status", inf->pid); - gdb::unique_xmalloc_ptr status_file - = target_fileio_read_stralloc (nullptr, filename.c_str ()); - - if (status_file == nullptr) + target_file_reader proc_status + (string_printf ("/proc/%d/status", inf->pid)); + if (proc_status.empty_or_error ()) return DEFAULT_TAG_MASK; - std::string_view status_file_view (status_file.get ()); + std::string_view status_file_view (proc_status.data ()); constexpr std::string_view untag_mask_str = "untag_mask:\t"; const size_t found = status_file_view.find (untag_mask_str); if (found != std::string::npos) @@ -1867,7 +1865,7 @@ amd64_linux_lam_untag_mask () unsigned long long result = std::strtoul (start, &endptr, 0); if (errno != 0 || endptr == start) error (_("Failed to parse untag_mask from file %ps."), - styled_string (file_name_style.style (), filename.c_str ())); + styled_string (file_name_style.style (), proc_status.c_path ())); return result; } diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 772b561eb96..0582e5eee64 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1737,6 +1737,12 @@ parse_smaps_data (gdb::array_view data, return smaps; } +static std::vector +parse_smaps_data (const target_file_reader &freader) +{ + return parse_smaps_data (freader.view (), freader.path ()); +} + /* Helper that checks if an address is in a memory tag page for a live process. */ @@ -1747,19 +1753,14 @@ linux_process_address_in_memtag_page (CORE_ADDR address) return false; ptid_t ptid = get_ptid_for_slash_proc (); - std::string smaps_file = string_printf ("/proc/%ld/smaps", ptid.lwp ()); - - LONGEST len = 0; - gdb::unique_xmalloc_ptr data - = target_fileio_read_stralloc (NULL, smaps_file.c_str (), &len); - if (data == nullptr) + target_file_reader smaps_freader + (string_printf ("/proc/%ld/smaps", ptid.lwp ())); + if (smaps_freader.empty_or_error ()) return false; /* Parse the contents of smaps into a vector. */ - gdb::array_view content (data.get (), len); - std::vector smaps - = parse_smaps_data (content, smaps_file); + std::vector smaps = parse_smaps_data (smaps_freader); for (const smaps_data &map : smaps) { @@ -1823,17 +1824,13 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, if (use_coredump_filter) { - std::string core_dump_filter_name - = string_printf ("/proc/%ld/coredump_filter", ptid.lwp ()); - - gdb::unique_xmalloc_ptr coredumpfilterdata - = target_fileio_read_stralloc (NULL, core_dump_filter_name.c_str ()); - - if (coredumpfilterdata != NULL) + target_file_reader coredump_filter_freader + (string_printf ("/proc/%ld/coredump_filter", ptid.lwp ())); + if (!coredump_filter_freader.empty_or_error ()) { unsigned int flags; - sscanf (coredumpfilterdata.get (), "%x", &flags); + sscanf (coredump_filter_freader.data (), "%x", &flags); filterflags = (enum filter_flag) flags; } } @@ -1859,7 +1856,7 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, std::vector smaps = parse_smaps_data (content, maps_filename); - for (const smaps_data &map : smaps) + for (const smaps_data &map: smaps) { /* Invoke the callback function to create the corefile segment. */ if (should_dump_mapping_p (filterflags, map)) @@ -2338,9 +2335,6 @@ linux_corefile_parse_exec_context (struct gdbarch *gdbarch, bfd *cbfd) static bool linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) { - /* The filename which we will use to obtain some info about the process. - We will basically use this to store the `/proc/PID/FILENAME' file. */ - char filename[100]; /* The basename of the executable. */ const char *basename; /* Temporary buffer. */ @@ -2371,25 +2365,28 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) const int leader_id = current_inferior ()->pid; const ptid_t live_ptid = get_ptid_for_slash_proc (); - /* Obtaining PID and filename. */ - xsnprintf (filename, sizeof (filename), "/proc/%ld/cmdline", - live_ptid.lwp ()); /* The full name of the program which generated the corefile. */ - gdb_byte *buf = nullptr; - LONGEST buf_len = target_fileio_read_alloc (nullptr, filename, &buf); - gdb::unique_xmalloc_ptr fname ((char *)buf); + target_file_reader cmdline_freader + (string_printf ("/proc/%ld/cmdline", live_ptid.lwp ())); + if (cmdline_freader.empty_or_error ()) + return false; - if (buf_len < 1 || fname.get () == nullptr || fname.get ()[0] == '\0') + /* /proc//cmdline stores the command-line arguments as a sequence of + NUL-separated strings. */ + gdb::array_view cmdline = cmdline_freader.cast_view (); + /* The buffer points to the full name of the program which generated the + corefile. */ + if (cmdline.size () < 1 || cmdline[0] == '\0') { /* No program name was read, so we won't be able to retrieve more information about the process. */ return false; } - if (fname.get ()[buf_len - 1] != '\0') + if (cmdline[cmdline.size () - 1] != '\0') { - warning (_("target file %s " - "does not contain a trailing null character"), - filename); + warning (_("target file %ps does not contain a trailing null character"), + styled_string (file_name_style.style (), + cmdline_freader.c_path ())); return false; } @@ -2399,27 +2396,26 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) p->pr_pid = leader_id; /* Copying the program name. Only the basename matters. */ - basename = lbasename (fname.get ()); + basename = lbasename (cmdline.data ()); strncpy (p->pr_fname, basename, sizeof (p->pr_fname) - 1); p->pr_fname[sizeof (p->pr_fname) - 1] = '\0'; const std::string &infargs = current_inferior ()->args (); /* The arguments of the program. */ - std::string psargs = fname.get (); + std::string psargs = cmdline.data (); if (!infargs.empty ()) psargs += ' ' + infargs; strncpy (p->pr_psargs, psargs.c_str (), sizeof (p->pr_psargs) - 1); p->pr_psargs[sizeof (p->pr_psargs) - 1] = '\0'; - xsnprintf (filename, sizeof (filename), "/proc/%d/stat", leader_id); /* The contents of `/proc/PID/stat'. */ - gdb::unique_xmalloc_ptr proc_stat_contents - = target_fileio_read_stralloc (NULL, filename); - char *proc_stat = proc_stat_contents.get (); - - if (proc_stat == NULL || *proc_stat == '\0') + const char *proc_stat = nullptr; + target_file_reader stat_freader + (string_printf ("/proc/%d/stat", leader_id)); + if (stat_freader.empty_or_error () + || *(proc_stat = stat_freader.data ()) == '\0') { /* Despite being unable to read more information about the process, we return true here because at least we have its @@ -2491,13 +2487,11 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) /* Finally, obtaining the UID and GID. For that, we read and parse the contents of the `/proc/PID/status' file. */ - xsnprintf (filename, sizeof (filename), "/proc/%d/status", leader_id); - /* The contents of `/proc/PID/status'. */ - gdb::unique_xmalloc_ptr proc_status_contents - = target_fileio_read_stralloc (NULL, filename); - char *proc_status = proc_status_contents.get (); - - if (proc_status == NULL || *proc_status == '\0') + char *proc_status = nullptr; + target_file_reader status_freader + (string_printf ("/proc/%d/status", leader_id)); + if (status_freader.empty_or_error () + || *(proc_status = status_freader.data ()) == '\0') { /* Returning true since we already have a bunch of information. */ return true; @@ -2890,9 +2884,6 @@ linux_gdb_signal_to_target (struct gdbarch *gdbarch, static bool linux_vsyscall_range_raw (struct gdbarch *gdbarch, struct mem_range *range) { - char filename[100]; - long pid; - if (target_auxv_search (AT_SYSINFO_EHDR, &range->start) <= 0) return false; @@ -2930,7 +2921,7 @@ linux_vsyscall_range_raw (struct gdbarch *gdbarch, struct mem_range *range) if (current_inferior ()->fake_pid_p) return false; - pid = current_inferior ()->pid; + long pid = current_inferior ()->pid; /* Note that reading /proc/PID/task/PID/maps (1) is much faster than reading /proc/PID/maps (2). The later identifies thread stacks @@ -2940,15 +2931,14 @@ linux_vsyscall_range_raw (struct gdbarch *gdbarch, struct mem_range *range) a few thousand threads, (1) takes a few milliseconds, while (2) takes several seconds. Also note that "smaps", what we read for determining core dump mappings, is even slower than "maps". */ - xsnprintf (filename, sizeof filename, "/proc/%ld/task/%ld/maps", pid, pid); - gdb::unique_xmalloc_ptr data - = target_fileio_read_stralloc (NULL, filename); - if (data != NULL) + target_file_reader task_maps_freader + (string_printf ("/proc/%ld/task/%ld/maps", pid, pid)); + if (!task_maps_freader.empty_or_error ()) { char *line; char *saveptr = NULL; - for (line = strtok_r (data.get (), "\n", &saveptr); + for (line = strtok_r (task_maps_freader.data (), "\n", &saveptr); line != NULL; line = strtok_r (NULL, "\n", &saveptr)) { @@ -2966,9 +2956,10 @@ linux_vsyscall_range_raw (struct gdbarch *gdbarch, struct mem_range *range) } } } - else + else if (task_maps_freader.error ()) warning (_("unable to open /proc file '%ps'"), - styled_string (file_name_style.style (), filename)); + styled_string (file_name_style.style (), + task_maps_freader.c_path ())); return false; } @@ -3298,18 +3289,12 @@ linux_address_in_shadow_stack_mem_range return false; ptid_t ptid = get_ptid_for_slash_proc (); - std::string smaps_file = string_printf ("/proc/%ld/smaps", ptid.lwp ()); - - LONGEST len = 0; - gdb::unique_xmalloc_ptr data - = target_fileio_read_stralloc (nullptr, smaps_file.c_str (), &len); - - if (data == nullptr) + target_file_reader smaps_freader + (string_printf ("/proc/%ld/smaps", ptid.lwp ())); + if (smaps_freader.empty_or_error ()) return false; - gdb::array_view content (data.get (), len); - const std::vector smaps - = parse_smaps_data (content, smaps_file); + const std::vector smaps = parse_smaps_data (smaps_freader); auto find_addr_mem_range = [&addr] (const smaps_data &map) { diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c index 93db3417a2a..5ed45809949 100644 --- a/gdb/sparc64-tdep.c +++ b/gdb/sparc64-tdep.c @@ -68,6 +68,7 @@ #include #include "cli/cli-utils.h" #include "cli/cli-cmds.h" +#include "cli/cli-style.h" #include "auxv.h" #define MAX_PROC_NAME_SIZE sizeof("/proc/99999/lwp/9999/adi/lstatus") @@ -301,18 +302,16 @@ adi_tag_fd () static bool adi_is_addr_mapped (CORE_ADDR vaddr, size_t cnt) { - char filename[MAX_PROC_NAME_SIZE]; size_t i = 0; pid_t pid = inferior_ptid.pid (); - snprintf (filename, sizeof filename, "/proc/%ld/adi/maps", (long) pid); - gdb::unique_xmalloc_ptr data - = target_fileio_read_stralloc (NULL, filename); - if (data) + target_file_reader adi_maps_freader + (string_printf ("/proc/%d/adi/maps", pid)); + if (!adi_maps_freader.empty_or_error ()) { adi_stat_t adi_stat = get_adi_info (pid); char *saveptr; - for (char *line = strtok_r (data.get (), "\n", &saveptr); + for (char *line = strtok_r (adi_maps_freader.data (), "\n", &saveptr); line; line = strtok_r (NULL, "\n", &saveptr)) { @@ -328,8 +327,10 @@ adi_is_addr_mapped (CORE_ADDR vaddr, size_t cnt) } } } - else - warning (_("unable to open /proc file '%s'"), filename); + else if (adi_maps_freader.error ()) + warning (_("unable to open /proc file '%ps'"), + styled_string (file_name_style.style (), + adi_maps_freader.c_path ())); return false; } diff --git a/gdb/target.h b/gdb/target.h index 38bdc68f6a3..923e5c400b7 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -2341,6 +2341,122 @@ extern LONGEST target_fileio_read_alloc (struct inferior *inf, extern gdb::unique_xmalloc_ptr target_fileio_read_stralloc (struct inferior *inf, const char *filename, LONGEST *len = nullptr); +/* Helper class for reading the content of a file on the target. */ +template +class target_file_reader +{ + /* The path of the file being read. */ + std::string m_path; + + /* Smart pointer to the data. */ + gdb::unique_xmalloc_ptr m_data; + + /* Number of bytes read. */ + LONGEST m_size; + +public: + /* Read the content of the file associated to PATH from the filesystem as + seen by INF. If INF is NULL, use the filesystem seen by the debugger + (GDB or, for remote targets, the remote stub). */ + target_file_reader (const std::string &path, struct inferior *inf = nullptr) + : m_path (path) + , m_size (0) + { + /* The interface of target_fileio_read_stralloc and target_fileio_read_alloc + may appear inconsistent, but the difference is intentional. + + On error, both functions return nullptr and set the size to a negative + value. For a successful read of an empty file, however, the size is zero + and their return values differ: + - target_fileio_read_stralloc returns an allocated empty string rather + than nullptr. The allocation contains the terminating '\0'. + - target_fileio_read_alloc simply returns nullptr. + + Hence, an assert in .data(), .view () and .cast_view () enforcing no + error but a valid buffer address. + gdb_assert (!error () && m_data != nullptr); */ + if constexpr (std::is_same_v) + m_data = target_fileio_read_stralloc (inf, m_path.c_str (), &m_size); + else + { + gdb_byte *buf = nullptr; + m_size = target_fileio_read_alloc (inf, m_path.c_str (), &buf); + m_data = gdb::unique_xmalloc_ptr (reinterpret_cast(buf)); + } + } + + target_file_reader (target_file_reader &&) = default; + target_file_reader &operator= (target_file_reader &&) = default; + + DISABLE_COPY_AND_ASSIGN (target_file_reader); + + /* Return true if the file was read successfully but contained no data. */ + bool empty () const noexcept + { return m_size == 0; } + + /* Return true if the file could not be read. */ + bool error () const noexcept + { return m_size < 0; } + + /* Return true if an error occurred or the file was read successfully + but is empty. */ + bool empty_or_error () const noexcept + { return empty () || error (); } + + /* Return a pointer to the data. */ + T *data () const noexcept + { + gdb_assert (!error () && m_data != nullptr); + return m_data.get (); + } + + /* Return the number of bytes read. */ + LONGEST size () const noexcept + { + gdb_assert (!error ()); + /* For char buffers, size() corresponds to the size of the read data. Some + null-terminator characters are possibly scattered throughout the data. + Consequently, strlen() might not reflect the actual size. */ + return m_size; + } + + /* Return a view of the data. */ + gdb::array_view view () const noexcept + { + gdb_assert (!error () && m_data != nullptr); + return gdb::array_view (m_data.get (), size ()); + } + + /* Return a view of the data, reinterpreted as objects of type U. + The size of the underlying storage must be an exact multiple of sizeof (U), + and the storage must be suitably aligned for U. */ + template + gdb::array_view cast_view () const noexcept + { + gdb_assert (!error () && m_data != nullptr); + + size_t nbytes = size () * sizeof (T); + + /* The number of bytes must be a multiple of sizeof(U). + Do not silently discard trailing bytes. */ + gdb_assert (nbytes % sizeof (U) == 0); + + /* The underlying storage must satisfy U's alignment requirement. */ + gdb_assert (reinterpret_cast (m_data.get ()) % alignof (U) == 0); + + return gdb::array_view (reinterpret_cast (m_data.get ()), + nbytes / sizeof (U)); + } + + /* Return the path of the file that was read. */ + const std::string &path () const noexcept + { return m_path; } + + /* Return the path of the file that was read as a C string. */ + const char *c_path () const noexcept + { return m_path.c_str (); } +}; + /* Invalidate the target associated with open handles that were open on target TARG, since we're about to close (and maybe destroy) the target. The handles remain open from the client's perspective, but -- 2.55.0