From patchwork Tue Jul 28 15:16:55 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Longo X-Patchwork-Id: 140096 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A351F4BB3BB1 for ; Tue, 28 Jul 2026 15:19:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A351F4BB3BB1 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=Y1V+VRUi; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=Y1V+VRUi X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from MRWPR03CU001.outbound.protection.outlook.com (mail-francesouthazon11011000.outbound.protection.outlook.com [40.107.130.0]) by sourceware.org (Postfix) with ESMTPS id 2A02F4BB3B9C for ; Tue, 28 Jul 2026 15:18:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2A02F4BB3B9C 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 2A02F4BB3B9C Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=40.107.130.0 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1785251921; cv=pass; b=dNH4BlGvQHveS8sw5mIZrgEdv+i+44XyCvbylt084b+fnZa4QqlOl2ep9b2dqVrYzxZ6bT7O/2F8PLHfAD6K031h16YWzp7HqIZJ0syiCkNfedE+dHsZyxSECJKBhXRs4bS5rGKRcDJ+jBBVw8w0unzJHx8yZD3Uva0PCKX9O24= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1785251921; c=relaxed/simple; bh=VN5Bfap9A+PDIVmMjZpa8M//h8uEcXJsXpdICBAnMLY=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=RnWXquXWKAnuJpkKx/YI0XwZ/tRnU7lzLoA76bSmNXOot0+dgPCV1jOButTUBSI5Rg2mc1cT1mOoQvFqlxXD7kpOtLiV/Q7fhOf1kf9OSLJ1uZLMI1T0YfSQ91dDc461v3C7juKFrsK7UWmpfFLZQgVyL1opkZms/BxxGavdJJw= 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=Y1V+VRUi; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=Y1V+VRUi DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A02F4BB3B9C ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=MmXPScIKC1EQQhT4ONoXEwZK7M+Ygu4BCh/1m2qnNmS7VjcyfvgfQRyUnnfIYsWEuAzfvk01ZPS0j5cPdOp4GsgXiNfN9ESlYsfVTGpgEXu67LCV0U363FwKa4V+A17vktWxlHq1SCUxOlZuj/uZM5K/8x/QEOJ3yGxnirVo5TFiSd3vuaR3mOVp8ITx9y4Gf+piXnpTwXa2fMaOiydXrM5ElL5X7ao0lRZYP4AlONHiHrpRBDWfgYamRa+lwLJsZIm4DgkZGWYGpdKzgoM0uld/C8S93txYneGqbn+CBmR4/KNFiPJzkhtvD00OrTawyutGeC5bKKixzOcASBeQwg== 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=XwkJwd6iEi2G/zmfA059UUGNnQzSccT1X5mdUoQ8t/w=; b=djdKMbGxNcxMlEVAUqEJgYxeWIKiShJKTvOA1+v18Rfi8Fn2WngSRM0PvdWyd2mjii3/DzZmQL0cT2slpMRi55pKUV6qPo+zT/YYfTrFv7SI67tKNg9nLzpgUpsfU381O7US4yrcKEu9ucl6OVJgF5KXjwTHJtwgyKIoB6YlnNRjcVdIXATc2pHuN3cuPVGA5EUffMbz+lJflc7ZLb2gNLGpjTkDKd4tlygef+RUiJGjHtVHGLPBy/4zBujcl1m6hP2BFDfsR4FPyJ2WhhlwdMOIotGAGE1asS8k+qz8O6OP+b/MACs/3ttEXQQkF/C1yuXTpwa0V+i/N859b9IjGw== 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=XwkJwd6iEi2G/zmfA059UUGNnQzSccT1X5mdUoQ8t/w=; b=Y1V+VRUiAsF4rvwGMIL5YMB5EjLIX2AmX0dX6v6bCnI95NXxIaM22mlJ1FHhhDhpV2mLQJjpKHIlwdOJFNVM+J3mXLGcYDL7LK0lmVP62UZ8QgTDUtasyL70/7Y1qhbtQwMpR5RcTvNC3wiTyCMXarcUxILwq4kkm4iVqL6XBHc= Received: from AS4P189CA0026.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:5db::13) by PAVPR08MB9404.eurprd08.prod.outlook.com (2603:10a6:102:30f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.13; Tue, 28 Jul 2026 15:18:27 +0000 Received: from AM2PEPF0001C712.eurprd05.prod.outlook.com (2603:10a6:20b:5db:cafe::2e) by AS4P189CA0026.outlook.office365.com (2603:10a6:20b:5db::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.12 via Frontend Transport; Tue, 28 Jul 2026 15:18:27 +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 AM2PEPF0001C712.mail.protection.outlook.com (10.167.16.182) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Tue, 28 Jul 2026 15:18:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FGyigsKXlByKFnJcfX9C20LLuimCjpsJc/yn6L6gG5rloH4JtaOl2rf3eXQbd/We+wYPJRhhXI6/oBL8GnhQjXq0KsPsENtEHmd+D1J/jv8mfbSTsp5UBEWFTk36yEBa88/Z9qBgze8OTwmddM/rH1TySMCvJv1olE3/ga8TN+/fjJxJEevOOr7BX3sSL2YcspUpBlxM4ekxj42M59maxs91n8gLMQ/R873Hz3JhWcuTij2wvkCoW749oXBrqWH+w4NPdZVinM1GBRusGlo0nC4yZHGFb1nZlQIRtJxlyS2AyagpdY3ngmmH02ohTMlKEkB/4QxCPFVyFTJJIZzV7Q== 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=XwkJwd6iEi2G/zmfA059UUGNnQzSccT1X5mdUoQ8t/w=; b=q/1ArcWEh7GXxiH2C0k4N+QhdDzWD92kBuiJERDlsyQ3gnGnIhVNzycQaQbls8gENDtEghKrTaXaf1DprFg4Qbaij7hapcMCAi0CQOIvtzEeo96fMioQOEwvYJtFWmzpyPCnlko4TSpl/BKYEfZd64A8tAkv/ikmvzwTfr99uXYSgxkl9SVINrXoU6NV/I+ERsVa8U500b/HM+R6pF1ZcuNmUJwSA5OgANG5JINQga5EQRXQSQPwMDRu/Jtqhihvpv9qyjuCWdVxT3qa0jmkc3gs6xF+fSc50+XT0hiVh4lJ3JnFc8x+FUg+0+QvwSnaIymFnQ49vxKLnZ1ZZzxIew== 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=XwkJwd6iEi2G/zmfA059UUGNnQzSccT1X5mdUoQ8t/w=; b=Y1V+VRUiAsF4rvwGMIL5YMB5EjLIX2AmX0dX6v6bCnI95NXxIaM22mlJ1FHhhDhpV2mLQJjpKHIlwdOJFNVM+J3mXLGcYDL7LK0lmVP62UZ8QgTDUtasyL70/7Y1qhbtQwMpR5RcTvNC3wiTyCMXarcUxILwq4kkm4iVqL6XBHc= Received: from DUZPR01CA0321.eurprd01.prod.exchangelabs.com (2603:10a6:10:4ba::15) by DB9PR08MB6395.eurprd08.prod.outlook.com (2603:10a6:10:254::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.13; Tue, 28 Jul 2026 15:17:20 +0000 Received: from DU2PEPF00028D01.eurprd03.prod.outlook.com (2603:10a6:10:4ba:cafe::93) by DUZPR01CA0321.outlook.office365.com (2603:10a6:10:4ba::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.12 via Frontend Transport; Tue, 28 Jul 2026 15:17:20 +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 DU2PEPF00028D01.mail.protection.outlook.com (10.167.242.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Tue, 28 Jul 2026 15:17:20 +0000 Received: from AZ-NEU-EX03.Arm.com (10.240.25.137) 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; Tue, 28 Jul 2026 15:17:16 +0000 Received: from PF4S4363.arm.com (10.57.42.206) by mail.arm.com (10.240.25.137) with Microsoft SMTP Server id 15.2.2562.29 via Frontend Transport; Tue, 28 Jul 2026 15:17:16 +0000 From: Matthieu Longo To: CC: Luis Machado , Luis Machado , Thiago Jung Bauermann , Simon Marchi , "Kevin Buettner" , Christina Schimpe , Christina Joos , Matthieu Longo Subject: [PATCH v1 1/6] target_fileio_read_stralloc: add an optional length parameter Date: Tue, 28 Jul 2026 16:16:55 +0100 Message-ID: <20260728151700.253720-2-matthieu.longo@arm.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260728151700.253720-1-matthieu.longo@arm.com> References: <20260728151700.253720-1-matthieu.longo@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DU2PEPF00028D01:EE_|DB9PR08MB6395:EE_|AM2PEPF0001C712:EE_|PAVPR08MB9404:EE_ X-MS-Office365-Filtering-Correlation-Id: 5cfaf93d-6555-4a9b-aae1-08deecbb795e x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; ARA:13230040|23010399003|36860700016|1800799024|376014|82310400026|3023799007|11063799006|10067099003|56012099006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info-Original: PXMlIJJC9Hr2qxMOzOzyF9iFaK1fC8vJHJHyDNPYioJ9aOVgMoIaUzpzVpjCaOwj1KqIgh29tjESFD/T3pJowhxDJNIBWTk31VvlGPKSJTu7RF2mCS65Fpf80MBPacypJOriC21gQhy7+IlwbE1zzOU8FHgGsuahcPpsWcx9Ye9CURF8VwELea16PMEufasQ73+QQuPomiB9cTJWJG9lyF24BWzf/WA+9NBP5vbsFg7TygkQmgl9LQimhV8OQrpP2g2WMEsJWTwSTEchU5iDv83+oPxZZFvA6cD2V+rDHZQw9FlV4yoGQEr+2T0nUlS0A47mj7v8w1cQ4f1cDEzzLOZ/LSPZnzxadUkjYz9ZMhO08oQcBoiqqX3dREc8Bpl57fUxb9XJmESMSKdcyyLOsM6bf3rHwclRnRHvSbLYPisTRpArqNhlnW8MnpYgNwbWbChENEv5Q91VicI8S4g2I06W2q0hOFoHXBvakgrBghc5TV1a28MomNiqqCb/37s6Yx40GN+AuJ1yKlKOuf0Ifs37Prl14lz9/yozVAKHvrkPzcIryNlOBqogEmBDINa/yQCfZVrKhrMqWvp+r5lLlNTLkKm+fbvBv3ufI2Aiy4mRLOA5QA4Sl6sYT5X2LSpMwJVwVuQigjMy7D35BL+/AoloDko6tbzpSTLQXYncUcPyc7Kw2wXOAKVY9BSeFajmmQsbIoKnS0Phf1yh9vOGMQ== 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)(23010399003)(36860700016)(1800799024)(376014)(82310400026)(3023799007)(11063799006)(10067099003)(56012099006)(22082099003)(18002099003); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: KWPL/PaMStuif9B75wDa2BSeSB+TGwFNDHXQkqcRbj7l+TJv/6Jl/eBKSnB05tbIys2tm1U2aQ5hl76OGBWsMFcF4oRQtUT0ocdCq1lj2rVJSC+e8mAIosoHxZYUmq13vL6O1kG4yzyjE6lk2NouBdsuKBVB7zG/GRS25MCu5FhHi+2zHsue+IxA2rjier3EjmZEyp23oKj4+6Igdc/snmWLVziVomzxFFt7n69BNuFiVjg6G5MKYdfUjWswJRu35MWVtC3LOOaEoIU1bZWQ9sX76yBYhkpWh6gcdxUq12CJejbmh2pDfMns+kk58p0y5aqZzt4vGEZ7dpC5+K8p7A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB6395 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM2PEPF0001C712.eurprd05.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 1ed5202c-1c79-4288-c465-08deecbb51ce X-Microsoft-Antispam: BCL:0; ARA:13230040|35042699022|14060799003|23010399003|1800799024|376014|36860700016|82310400026|10067099003|56012099006|11063799006|18002099003|22082099003|3023799007; X-Microsoft-Antispam-Message-Info: yh+dNR1WK+OGBxRXjZqU/wc4qv0CDPDIlm6WbEF5vMHnLbPfSuXGj/EKiS3sJJkuOWI8ymP6PcoZWABglGPqfHmfxk1veRIob7Hnnne6URz5yRoJ1e/PhAVDQ/ZQqeJfJTuxmShqJlp6q0TTVSO5WjXC9YClqIBoPVmWrb7mkF/i7kPVBCEcRcESvh/EkWpLMuOrv8um8SscGQ9vuzqs0zKc304OD5BOY+gdGlyvMITxw/5VzfMZr8Tyi1Kg4NCLFYvro/iFcryjKgJWjmqzMLvBYIjApMKqdj/Kxbs6UjcmdLUcaDf4TTPF0LRAbTIdX6eSOIcchoVb0lqNRwcGA1/fq9UnWO7KH0D5LDX9gF8BN46JLdpOSiDVfUgoUCCU/HfqXXC3eSzEjz/yi+b3C09gvkLFUyGt6DjCcRIEQGzezjc+uZYGTsdIGHnubc/XfITMCcEGTjBJkwSKvOgjYdV7pWMHBcZa27kVcofjDyzTu9BcLAmqBZKcai9yAXWNy1Dq37P2HF10HCXWdtZw2KroGMDSM0xR3AzKEQIjGDpSKQk9nCxrIF9hMV8Rrw6EXPp88gA1q6oUN8x3xqApX0lfLPmzVXIGV7hud148XEEEJDArKygSuqAgeFo7J035cPHXr3rfqa203jOUojBmvhBdyXlNmUb0PraHAmjhw0HcHnPVNnIJtZtYrSipAhB8NHLHuLckHNdBBwSKpfpacA== 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)(35042699022)(14060799003)(23010399003)(1800799024)(376014)(36860700016)(82310400026)(10067099003)(56012099006)(11063799006)(18002099003)(22082099003)(3023799007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0b1dcEIJfuqzrLdfK2F+jChr1bh+EdjyoLoFUydZgFtjV5XR9kf+tf9Tflth2mVlRM6ZpiSsWtDelYNmLB4qVYpSI6SLJ1tEjdl0OJBCyYZPWhf/+PIhPbExfCv/HMDtY1m/6ABinqr9VAXXnbE1OhyDVmkaWpl4vC37nu2DrYIo53F2Cvr+goQvTCIYM1nj7hR4beTL7MVeYxABtwKMPapu6iuUqoYWbbBvqOIA0WWrH8h3Jy8rBUqvYm90QEtEWXfKlxisvxutOoJ3igRNt8pbquq26omSNryW+5aSY0DTB06b5E9EsMF3X8vUKHiusbhAtqC6n7qD2J5sHvdtN1BBpsaioIe+BwxjDcOIM15haJ3y7gYrQ0dL0kuLP4oY1AYsY+RNJBv5RZdTr7D9pfSjCYGb9OShk3E1hns/xUt+n17Z2fj/DtltzYZuOJup X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2026 15:18:27.1594 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5cfaf93d-6555-4a9b-aae1-08deecbb795e 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: AM2PEPF0001C712.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR08MB9404 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org Extend target_fileio_read_stralloc with an optional output parameter that returns the number of bytes read, excluding the terminating NUL byte. Most callers only need the returned NUL-terminated buffer and can ignore the new parameter, but callers that need the number of bytes read can now obtain it without recomputing it. While updating the function, make a couple of minor cleanups by using '\0' instead of 0 for character literals and clarifying the function documentation. Reviewed-by: Thiago Jung Bauermann --- gdb/target.c | 11 ++++++++--- gdb/target.h | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/gdb/target.c b/gdb/target.c index 5d937f3ae85..ebf0f30092c 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3547,7 +3547,8 @@ target_fileio_read_alloc (struct inferior *inf, const char *filename, /* See target.h. */ gdb::unique_xmalloc_ptr -target_fileio_read_stralloc (struct inferior *inf, const char *filename) +target_fileio_read_stralloc (struct inferior *inf, const char *filename, + LONGEST *len) { gdb_byte *buffer; char *bufstr; @@ -3556,17 +3557,21 @@ target_fileio_read_stralloc (struct inferior *inf, const char *filename) transferred = target_fileio_read_alloc_1 (inf, filename, &buffer, 1); bufstr = (char *) buffer; + /* Note: on failure, target_fileio_read_alloc_1 returns -1. */ + if (len != nullptr) + *len = transferred; + if (transferred < 0) return gdb::unique_xmalloc_ptr (nullptr); if (transferred == 0) return make_unique_xstrdup (""); - bufstr[transferred] = 0; + bufstr[transferred] = '\0'; /* Check for embedded NUL bytes; but allow trailing NULs. */ for (i = strlen (bufstr); i < transferred; i++) - if (bufstr[i] != 0) + if (bufstr[i] != '\0') { warning (_("target file %s " "contained unexpected null characters"), diff --git a/gdb/target.h b/gdb/target.h index 6d1c21f29f6..819279c08fc 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -2327,15 +2327,19 @@ extern LONGEST target_fileio_read_alloc (struct inferior *inf, const char *filename, gdb_byte **buf_p); -/* Read target file FILENAME, in 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). The result is NUL-terminated and - returned as a string, allocated using xmalloc. If an error occurs - or the transfer is unsupported, NULL is returned. Empty objects - are returned as allocated but empty strings. A warning is issued - if the result contains any embedded NUL bytes. */ +/* Read the content of the target file FILENAME 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). + + If LEN is not NULL, store the number of bytes read, excluding the + terminating NUL byte. + + The returned buffer is NUL-terminated and allocated using xmalloc. + On error, or if the transfer is unsupported, return NULL and set + LEN to -1. Empty files are returned as allocated but empty strings. + A warning is issued if the file content contains embedded NUL bytes. */ extern gdb::unique_xmalloc_ptr target_fileio_read_stralloc - (struct inferior *inf, const char *filename); + (struct inferior *inf, const char *filename, LONGEST *len = nullptr); /* Invalidate the target associated with open handles that were open on target TARG, since we're about to close (and maybe destroy) the From patchwork Tue Jul 28 15:16:56 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Longo X-Patchwork-Id: 140098 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 12D1C4BB3BDB for ; Tue, 28 Jul 2026 15:20:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12D1C4BB3BDB 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=dxR6/QcQ; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=dxR6/QcQ X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazlp170120005.outbound.protection.outlook.com [IPv6:2a01:111:f403:c200::5]) by sourceware.org (Postfix) with ESMTPS id 019DE4BB24EF for ; Tue, 28 Jul 2026 15:18:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 019DE4BB24EF 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 019DE4BB24EF Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c200::5 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1785251919; cv=pass; b=pxH5bllJUbtak5rjlH2Sr6GMLpTb01c6OHhEwloRDHJtTYGnEXgWyJJSvVfDrVAnE7wVzTOFHDD5TgISFn2HfluYqr2vEZxeUEqjVmSMn/cBq/5Ar+NN1g3HOxvFmgZ5PBGpUrAfb8I/CMvz3OeCq4FAvT2nnXXkXQzqAHJe2f8= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1785251919; c=relaxed/simple; bh=/xHGvQfyjUl+1j5aztyB7fMK9Rz8sbUJBWGK0f24+g0=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=JL8jcz4RkqhaLcZ7wJO5bDkkCXSoWzjxhCjwtS8a3fEG1LImHsmGUug1LOKTMzSAUpsInzJelPuREe2Nz9VZTbCIVnbWdQ6XVN8LwD3kmLfUdesFuVy25QUdktnOIKi6tp/JwCGBCsjlQXnjlJB++u8HmUTuLRSjynqdpm2BShI= 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=dxR6/QcQ; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=dxR6/QcQ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 019DE4BB24EF ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=Q9awMGQ/OUdb4tFmLgxA5z4Rf99kYUeqAPF6gVG1Y6ePz9Uo5x6pD9M6hSFI8Rhk/B0yChM/+RFoBkzitWSKhdT58JJ71cgeKZbi/iIcTc0GlUA0AuIw+pkF137FZjKAlxM5cIo76TdQ9vUA88uuDvULXeYB7v1W5R5/9NG6h99py6Aa0eXIGnjYzF7W+coOIiDiZvwRY/ZepIYjjzbsw8HhVd9nM6h7ss0azk1y3SGbcKr9rmk7/1WKf26Oko0utDDsyb29ffoeBGzHClIPeg/DG05Xy1S8AEuDllIh+JhPxvBuRiiKutU48VzQ98d31FUL5OPjqwlpkiVYG5Su3A== 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=zJiq5+oja20/JYxemxTuMFF+gcGSDo5goKVaz7dTVq4=; b=nJo0NWgdDJYSekzjjgsDwHQLmVUCcevUnTdeBjRFdUJRoUKyD686cLOlHyCei88M+WK2YGl5eGewMiYFScA2qIfzrlXXstp+LoaGc6dALIc6JET2gmD+eU2u/yXGoH+7JtLclmNF0A9zfkZE+pLxLylxsAI8N1xuH4rGLxPN2nKIAZdJX2d3cFrldhnG4rAg0mwGdownC0mdwplETrpnSHGlxPLsDUo87gHxznX1+PnpCLNh4fUIxrIpXYaW193TvARf2DsefEfuoiovRD7CaHWdljHw6YrJLwsFDK99791+Gb+K/hZhqmEDZHPTl4AhzrCcmXe2QcoTKFF8WPLQgQ== 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=zJiq5+oja20/JYxemxTuMFF+gcGSDo5goKVaz7dTVq4=; b=dxR6/QcQq0U68UlchXXTG4f3vgZ5c5yXmGfwwamzjNOQMJeokakkZ81Eeuv4MW8jEQGzRI2zCBzBBpbg2oDVtGlsDkrcUZjPz+946LZr9oAwhky47bOeBIvCdDpIKpobr7XHFwTZZBsJBE09sbnFdFIHOZLjlhqE2r7u6eelZEk= Received: from DB8P191CA0004.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:130::14) by PA4PR08MB6205.eurprd08.prod.outlook.com (2603:10a6:102:e6::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.13; Tue, 28 Jul 2026 15:18:33 +0000 Received: from DU2PEPF00028D0B.eurprd03.prod.outlook.com (2603:10a6:10:130:cafe::1f) by DB8P191CA0004.outlook.office365.com (2603:10a6:10:130::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.12 via Frontend Transport; Tue, 28 Jul 2026 15:18:33 +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 DU2PEPF00028D0B.mail.protection.outlook.com (10.167.242.171) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.245.5 via Frontend Transport; Tue, 28 Jul 2026 15:18:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=j9f4Gv0tSkOxE+G2EIQ+ElGYwAwfZokhHG9X9wzJcpWUyCvNc3GExBPX0s1xOggRm3SpORsC5PBwDWD8IsFgYnOhwFmsQSfnZglLeOI0Q3ay7DJydWMLfBUMAaaK591XCpt+a8O4KzgFXdzBHjRSSIm8zb2B7HsBOkFmVrk5nVV1R/HfaJ4s0Bgoeqqf3PiOfFyR+Wb+KuOHCpXAkZr68xcl+pegm5oD4edPWHUxcr/MGSqXE/n776e13iGmaPb96Un6Vap0ZAIWfEceFTL/+/J86HmAWW1SboS6nnNPs39aJHDbX+bIULdrbApV4tqGUuXQ6ioK3MRywrH9VqIJZw== 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=zJiq5+oja20/JYxemxTuMFF+gcGSDo5goKVaz7dTVq4=; b=XzIn14xt/LcEH4Pafu455P+J8Cp75ga7yO0yY2F7zJrQ1TVhQzuGua3wsMIlbS2CuspB+wiJSMaGjDoeOBfoWh2mZeJxd6EnY9tbyohXG97/C+TbEW3wq0ipmsgLSktpQwls3j6Wa+q326QKoxG/mYCiOzvY7QKLqjHMRM6s5owqjpmx275hyf0LuubxxpUoNlmDj4dGi/S9W5DMHZHqjD/ECHNKRnvK6+WugL+lxfgglgg6SywoW2KbUnxy4CD9djfiSevEMy7mQUBVvMcc+dS0ovKMSRR0x4TKovGqDE+fdQPrBlA2OUJbreVYTBubY18IiVIHK6uu2obI9Bq7/Q== 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=zJiq5+oja20/JYxemxTuMFF+gcGSDo5goKVaz7dTVq4=; b=dxR6/QcQq0U68UlchXXTG4f3vgZ5c5yXmGfwwamzjNOQMJeokakkZ81Eeuv4MW8jEQGzRI2zCBzBBpbg2oDVtGlsDkrcUZjPz+946LZr9oAwhky47bOeBIvCdDpIKpobr7XHFwTZZBsJBE09sbnFdFIHOZLjlhqE2r7u6eelZEk= Received: from AM8P190CA0010.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:219::15) by DB3PR08MB8916.eurprd08.prod.outlook.com (2603:10a6:10:428::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.13; Tue, 28 Jul 2026 15:17:29 +0000 Received: from AMS0EPF00000193.eurprd05.prod.outlook.com (2603:10a6:20b:219:cafe::7d) by AM8P190CA0010.outlook.office365.com (2603:10a6:20b:219::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.12 via Frontend Transport; Tue, 28 Jul 2026 15:17:29 +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 AMS0EPF00000193.mail.protection.outlook.com (10.167.16.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Tue, 28 Jul 2026 15:17:28 +0000 Received: from AZ-NEU-EX03.Arm.com (10.240.25.137) 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, 28 Jul 2026 15:17:27 +0000 Received: from PF4S4363.arm.com (10.57.42.206) by mail.arm.com (10.240.25.137) with Microsoft SMTP Server id 15.2.2562.29 via Frontend Transport; Tue, 28 Jul 2026 15:17:27 +0000 From: Matthieu Longo To: CC: Luis Machado , Luis Machado , Thiago Jung Bauermann , Simon Marchi , "Kevin Buettner" , Christina Schimpe , Christina Joos , Matthieu Longo Subject: [PATCH v1 2/6] gdb support: add gdb::ranges::replace algorithm Date: Tue, 28 Jul 2026 16:16:56 +0100 Message-ID: <20260728151700.253720-3-matthieu.longo@arm.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260728151700.253720-1-matthieu.longo@arm.com> References: <20260728151700.253720-1-matthieu.longo@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AMS0EPF00000193:EE_|DB3PR08MB8916:EE_|DU2PEPF00028D0B:EE_|PA4PR08MB6205:EE_ X-MS-Office365-Filtering-Correlation-Id: 2711955c-59e7-4e86-0c77-08deecbb7ccb x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; ARA:13230040|23010399003|1800799024|36860700016|376014|82310400026|10067099003|11063799006|56012099006|18002099003|22082099003|13003099007; X-Microsoft-Antispam-Message-Info-Original: iLK1GA+HawDWGi+wC8G1yhgw3kND7P4nkAzH7yLfxGNpmy+iuAomc7WNf/GYJEhpINqzHp3QaBiIRK7dgjnjof3wXkomrmqvasszCwLUrmMPDv0c+qiTnKuM0n6yOD7v09+1BtGnJEKsoJshSqKyHmBbwPKObZyuXMjZTitTqQ6aSaydQGxoz/rayCaQvno6CxCnnxcwrV2K0fTBEW418R+aE0HxN/LsxxA+7QWkHpi7FmjD4rI/LnGYmjuZXmaMY9iiE4CJ/neAflJgM2L3ALhg/eRsNLQBiqjC3qI7WclMS6vi9JVZa0926oq2KBeK/6/tlOS6aaSiVmLwNW1j7x22fSyMONcGIjgkvBwiQvHAe2UVMheC9Gg4s4H+whgJ6AJScMGEBGRov6JhWbY2za4LinrThHtDph9hNNL5TEG/Rw/z31ZGtObb3+z/d/iDPfAxXFKHYcCXUVMM3aehAGXccMX09SiU73sUy98sjfqoH8LXlFKx//X+TjLT9QRaS8PHWCQSF2q3p7mV1ElALRUoCUHf4C78gGsi0dAJRI7PFWAAEgRFZrFJL5jJJWJlpk/5eNdFxTx0outmSMIzbtGwf/UAtek2E7yw2b4TLa/y+q8LYpkZzv1WELqTGwJVZ6Pc52q9xCxbU2thXT+nYJo1y22Mnc2Fu7UGCLlBEoIVSIhe0I5VTfsLGbSLOuMFVjO43UwvSZclAUBhGQggOQ== 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)(23010399003)(1800799024)(36860700016)(376014)(82310400026)(10067099003)(11063799006)(56012099006)(18002099003)(22082099003)(13003099007); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: RifDksW4muLiXF6nDLdKLeqK6+QrnujFCQ+4CClkJtU5IGglktlfO8V9Kip6ZbQxPGRkYty/GmQnyH+3nlFTmY3e3Y3GHG8aI5Hy2+/PLKnL0vLVm0vqsUq2FVdRgLMosD0651iCyM7Q//6EEkPPD0DBdlcFJEhgVXGTvg0/LLc7Z6aqQy2wyFW3si8SLzFytsiwzJMYJog3IyT0p5vt0SzcS91NJLrOPnAqqCXU5ffxrlmANkiY2FQ47pFEKUSI0Zwm28H5qTTQDz4/D6QfOC/VCLU6GiatsvvfFixovEjiD9uJyt+CiDcqRB2Q+mqLl55VWexk7wLAXp9vGdS4uw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR08MB8916 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DU2PEPF00028D0B.eurprd03.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 2300aedd-7ed3-4197-8dd1-08deecbb562d X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|14060799003|23010399003|35042699022|36860700016|376014|82310400026|11063799006|56012099006|10067099003|18002099003|22082099003|13003099007; X-Microsoft-Antispam-Message-Info: oPTaqDIsJ/QM3mhpo1ymlQzrSu0W5rBaT/cL2CWgeNaoXbmgrzf8EOQzN6BMIpj8DEt2dnu036UOVqkzOa65YsmKNJBTyEXYLoR+g7uZPTEX+KGMRSA1qnyO1QEPz5GDCyww19/7+RWbgMGskedxBIsKBcdEMUoL6SvIu43hQOZ+ulvL36GI70T+fiC5WMxM/dDcRU5Pyx1IiFjNTHIsOhKX/LQNNleDK/ChHxp9GXbCe8OLR7UX+fvuSrPtZlAE3WC3a2W1jCk/JKtP5fRFRgouHsBJA1uEP+bihqBzqHPg1rhsdNnkGmQedUneEe8VktpHdE38qyJQBqaLZWcyS4r7vd8aY+x6WJBTg4D4+IROkQ9QwknAQtY6Y5Kd+/6bh3mpOG7TYbXaapR8tTIVGDWPGCF2MAomwKUhTkdNHt5CxWvmrdJxKcbPCwv3YjCXCNRo7UwwljGEzYdPVZO837OTK9lXvkmTfJN+rf8AgegwCgMAGplV92EMtZVtM3a0hbRpL2FVnua8/0o7VraCmEe7iODBD6b1DwKHDww8TezdSJx4qssTiallPbVspYwbtWlnTsTMk+ah/fV5vCgHDTMe7/b+wW9uoc9A8I1XaRueRw3doEASgOCoI7CKATwyKL5Wh21xt9NcAEbMQB2bRBO6gULIiFFBueYXRlsDTKo3FcNVtdIG5YiK2DPE/uiP9PMsW+fKQ6UF1F9m1rsJPg== 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)(23010399003)(35042699022)(36860700016)(376014)(82310400026)(11063799006)(56012099006)(10067099003)(18002099003)(22082099003)(13003099007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yB64VHJhSO0SQgJYSVCI0MEdtX4StzQbFEDSqIigpEoRmiIcQ4dNZ7u7cwAX8ziriODZTpoHmV42QY+Z9o+MAEvbBEJjCU5GR7lNiwH0FQX8kQ76SwQrb72cPq4u4I3sNb1fwJzsC8TArdk+gE1sQo5koo9H90iCybJZrJxBfJ+9hZEH3Vxctz4GJx3ozeWfhwkN8uDHcuwfOH5EwLAJOfUxTl1grFoCXN3niPRWp3L1KO4Dkgle+1rkgmVim0VvdRLImTUE9SMis+FvGpo041W29DtzjRwb2S3oeoSpzqsd63t+o2vdQeWceny5kNsserLfztjjX2pOch32aIxK9mmRNHJ/Xyqv4nm3OcV8qp8GHYdtk07lQoTohgdrs5VNSFOXve8+tgpE0npb+pRiRzRuiX9BmabZiCuFc7kRNqKdxqtHH8BxFnGWobes57rs X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2026 15:18:32.8933 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2711955c-59e7-4e86-0c77-08deecbb7ccb 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: DU2PEPF00028D0B.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6205 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org Provide a C++17-compatible replacement for the C++20 std::ranges::replace algorithm, allowing callers to use a consistent interface until GDB transitions to C++20. The helper should be removed once the C++ standard library implementation become available. https://en.cppreference.com/cpp/algorithm/ranges/replace --- gdbsupport/array-view.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gdbsupport/array-view.h b/gdbsupport/array-view.h index 8431d7f5add..f9842ecff30 100644 --- a/gdbsupport/array-view.h +++ b/gdbsupport/array-view.h @@ -225,6 +225,22 @@ void copy (gdb::array_view src, gdb::array_view dest) std::copy_backward (src.begin (), src.end (), dest.end ()); } +namespace ranges { + +/* Replace all occurrences of a value in the provided range. + + Note: this helper is a reimplementation of std::ranges::replace, only + available from C++20 onwards, and consequently, should be replaced by + std::ranges::replace once GDB switches to C++20. */ + +template +void replace (Range r, const T &old_value, const T &new_value) +{ + std::replace (r.begin (), r.end (), old_value, new_value); +} + +} /* namespace ranges */ + /* Compare LHS and RHS for (deep) equality. That is, whether LHS and RHS have the same sizes, and whether each pair of elements of LHS and RHS at the same position compares equal. */ From patchwork Tue Jul 28 15:16:57 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Longo X-Patchwork-Id: 140097 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 45F444BB24FE for ; Tue, 28 Jul 2026 15:19:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45F444BB24FE 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=m2b1HSC3; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=m2b1HSC3 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from OSPPR02CU001.outbound.protection.outlook.com (mail-norwayeastazlp170130007.outbound.protection.outlook.com [IPv6:2a01:111:f403:c20f::7]) by sourceware.org (Postfix) with ESMTPS id 033574BB24EB for ; Tue, 28 Jul 2026 15:19:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 033574BB24EB 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 033574BB24EB Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c20f::7 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1785251951; cv=pass; b=vcL/Did1yH4rum7dvDUoeFxEvXEm7TS/aps4+TtnidBqCZ2f7fd5hhoSh1EcRLUaXsS8IDRudG0avV6aYMh82L0OvOolnWN1zIAtwq7TLaxNEgCiL+NsovLGDFMZRWupy2VAPGsJBD77ICwPaOlPlWjIl6H4y6Ik/vJTx8PtJr0= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1785251951; c=relaxed/simple; bh=0i7x7dwjL5y2rlwu8JSmAa/tqS49YTdwQA5yGIJGCzQ=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=cbskv4hyXsHCPTzQNHsBOiFPTH12xUaB8rLt//Z95L8Z/OhTS2RkIOT26kIcNf6R2K0XeZ4P28+PmFZ8NlA2iUrZET3+LzZaKWF4ogEIy7vnYrrtl46HbTBXwMsIr2F1+Ej6j1P01r8VEi1UaBKTP0Nhae9MteGEmrRuzMCpnsQ= 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=m2b1HSC3; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=m2b1HSC3 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 033574BB24EB ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=MlXcXPPiRnfEoduRfi/w3O4p1dVqK+MWfQSlQXoQNovA0yINOHgsu0u5ruv+b9wHUs6S9MC2bU5TIUQWCLLRJvW4TOmqd9HyI33UFkAUeLFK45Bu8iKaZsUfbCvmDZKjw4IesciFDdHKPrVlJN2e/Ggyu4BaFtCwaFINlXKp1q+zH1l3rAZ3gLQl6CfGq+/nOWpJcCKfIIUR7ut3SlH/6fKOGDOUqXAZlR0XgAQvyaFKgvrXGcpRaygnj7/H5kR6H1WYcUVmnGGP+lx3U9RNqw7eGB1aliq6yOEx2oq3Yq+Ylh1ZTwVEDIFPltC2PPnrNd1RZKlS0feSgr76PulrLg== 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=7TGUiLRwkyy3NNruNPiFtWf0VNi8GqYiCEgvS/3sNt0=; b=x6g1fueOERaARjuoaiQiG2sYpjjktlAZyosu+3tt2n9FsXrszDuOYTQ25vQbjn+Pgp2BZL82TlM4tdPgpz/x7y1UQ++LavteUNorE3V/vtrBrgM+3OIOF6i1Z4uHbjpABgM+sIH31ExyrZtl2TdKE5qJ3pH079tzk8G6zVxl0z/H2LwDSVUx55vccCIfBz8zxV/J8XR9ol5cA3Kn/mMdqYLnTSmbUJItBHfyn0af/ErCeGeBLMxv+lXuAsjcY+9UiKqsc/KF95a7XU0w2kgxTwecEVIoxZZtmN9gkUV+XkjJaZeA6N//lGqZEJfgJ9XgWn8tyLOVDorwFw3V8DjfMA== 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=7TGUiLRwkyy3NNruNPiFtWf0VNi8GqYiCEgvS/3sNt0=; b=m2b1HSC3eNw43py5iOwFYfAx7yxo90PAgxDQmJ+wkwS93uFLx/cCXU4LJ4ABsSaSIkVwX+gDP7WqtAujUXBauFqxyvkCm0TEpVPd1GRJJsrIRd+IfXN0gdj327b6rw8lBWl4PSX0pdRcXKR+d1cMYQxiENdUfrzeqRoJyZrjNvo= Received: from DU6P191CA0029.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:53f::28) by AM8PR08MB5859.eurprd08.prod.outlook.com (2603:10a6:20b:1c6::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.13; Tue, 28 Jul 2026 15:19:03 +0000 Received: from DB1PEPF000509FE.eurprd03.prod.outlook.com (2603:10a6:10:53f:cafe::87) by DU6P191CA0029.outlook.office365.com (2603:10a6:10:53f::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.245.13 via Frontend Transport; Tue, 28 Jul 2026 15:19:03 +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 DB1PEPF000509FE.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Tue, 28 Jul 2026 15:19:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QNI+KV+ux43sjCRMCfh3k9AGnuI5HhA6DnzetFOyMzSCGdAdNmSXrPf0NVdsWe165SB/gcHJ+CHqJlNaeuXQ96Ole4DL3VrmpqjU3km0c53hjATdvoghtVOdc7g1ymfDziP9gv8jNTt+i76rsCGLS+GO6Ca4bBPjAg4lwS250M3eKva6qMjNUU86fzFEk7g5QApCPjZXIPyK1TDdwoUQbncrUagHyCUHD+qtegDQsvVujiKfNg+woaMNZxostXnmIhOhF/iNHG8ALaK+wNWueS9i3iWal3OVkAb9INfDXm74Viw0xXabvD16RTDdcT3XZjWCrG2jFIk1pH/v0D8zcw== 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=7TGUiLRwkyy3NNruNPiFtWf0VNi8GqYiCEgvS/3sNt0=; b=hLa1oaG7D4KFsN3JHCiiMA0uBPvwgtvFyjzxzH6DF14EZA7bagqwhvIO7zTZeUPPwdT/0OeoIeeugOFTYzFLcc8PblHdq/FYJJW43MByj1bqnUylQIX+Z9MhpKzpbBSpIcryTOehLXNYLFyy5HYV+cei5GdlSP0z8n51p1OzccjHPf9IbUGWoEeXdFQ0Fol3b31bDqb5dTkC8Pzhvn5kuZeS1HWyZv8e3sr/+mJmoRVpBTLbThoeqKIl+BbAoc3mvjSYqOOzep6zKToobyz8M8rAoc+Jocca7eoV8QQbTvWRWP3q75V/WNiYVNjKBKy0uQQxbuEAH6THrAbB/g+T2g== 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=7TGUiLRwkyy3NNruNPiFtWf0VNi8GqYiCEgvS/3sNt0=; b=m2b1HSC3eNw43py5iOwFYfAx7yxo90PAgxDQmJ+wkwS93uFLx/cCXU4LJ4ABsSaSIkVwX+gDP7WqtAujUXBauFqxyvkCm0TEpVPd1GRJJsrIRd+IfXN0gdj327b6rw8lBWl4PSX0pdRcXKR+d1cMYQxiENdUfrzeqRoJyZrjNvo= Received: from AM8P189CA0025.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:218::30) by DU4PR08MB11150.eurprd08.prod.outlook.com (2603:10a6:10:577::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.12; Tue, 28 Jul 2026 15:17:57 +0000 Received: from AMS0EPF00000191.eurprd05.prod.outlook.com (2603:10a6:20b:218:cafe::4d) by AM8P189CA0025.outlook.office365.com (2603:10a6:20b:218::30) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.12 via Frontend Transport; Tue, 28 Jul 2026 15:17:55 +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 AMS0EPF00000191.mail.protection.outlook.com (10.167.16.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Tue, 28 Jul 2026 15:17:55 +0000 Received: from AZ-NEU-EXJ02.Arm.com (10.240.25.139) 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, 28 Jul 2026 15:17:38 +0000 Received: from AZ-NEU-EX03.Arm.com (10.240.25.137) by AZ-NEU-EXJ02.Arm.com (10.240.25.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.29; Tue, 28 Jul 2026 15:17:38 +0000 Received: from PF4S4363.arm.com (10.57.42.206) by mail.arm.com (10.240.25.137) with Microsoft SMTP Server id 15.2.2562.29 via Frontend Transport; Tue, 28 Jul 2026 15:17:37 +0000 From: Matthieu Longo To: CC: Luis Machado , Luis Machado , Thiago Jung Bauermann , Simon Marchi , "Kevin Buettner" , Christina Schimpe , Christina Joos , Matthieu Longo Subject: [PATCH v1 3/6] gdb: introduce helper class file_reader_t Date: Tue, 28 Jul 2026 16:16:57 +0100 Message-ID: <20260728151700.253720-4-matthieu.longo@arm.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260728151700.253720-1-matthieu.longo@arm.com> References: <20260728151700.253720-1-matthieu.longo@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AMS0EPF00000191:EE_|DU4PR08MB11150:EE_|DB1PEPF000509FE:EE_|AM8PR08MB5859:EE_ X-MS-Office365-Filtering-Correlation-Id: f871eba2-d806-4b46-8199-08deecbb8ee0 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; ARA:13230040|82310400026|36860700016|23010399003|1800799024|376014|11063799006|10067099003|56012099006|6133799003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info-Original: NV2IGyBt8cZiDtslgZwPYpFonBgPdgXIQuVTwDh50dsDq6jxYZrBGpdMFWBBEcC9Pv6f2N1cX3kN4oK9oxV2inlD6oUpjF+H3iNxb16oEZaWs64b+GTGf4nos7fNzrWbtepJRmzCW1vdu5yxK/CWY6bWOxKcnLgoQZHKE+M02Tsn55qG+46rahRNQeqFnsszIJ2MUsb9KC7w59YlKp5JWiNUbMG998l81c4qh5WEvmNdUqqtqwGXalM8lajAF2gs+u9ORpFChA7Wj9Nj4PR/ah0pXVMYbSGkICk/yW600c3zRF5bSVQhPX8KVaWm/uerAymIhrLi4x1LmBxb8KDRzTSw58tVP9VPozXNmHQCDsJyK8f4UWRAMQKte/LcmZ1Ujnr/Oh0XOVGQ9CzA3hS7tWKOQqack8NBssiCTjYfqj6pA+mM2xwj0hWdtS9WlqZJ3TcAq6zAOwfgvFnv/Q7nK/q3dBPdjLPBV0/d0RPQFlAII2mJ47TXwHwOff+691jp6XtEAPla83X/pjm0U7zHaImroluRejEq4lJNc63LEUPD5wGQ8VZf8w+E024bqO2KTiFfo0AI5xvUjRtsQcsIVy8rM6aO119ENb3YgBaidBvyfG+35tYHpelL0s/2lngg/wzXc82FAerCNQrYithmd4SaPDoNADO17ybPDv2mqG7qnLC1g0ZLLlpVkp6FebyFB8mue2uFvY2RKrIosDVtKQ== 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)(82310400026)(36860700016)(23010399003)(1800799024)(376014)(11063799006)(10067099003)(56012099006)(6133799003)(22082099003)(18002099003); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: Z24MXiNt2MsdrNl/zpEcWVEsfa8bYCm0c2odK88GcxlQWLzCt9IaDBsZ5M6XeFIXQoB1NIPw3lnM5oERDtvhK0VOS+91QjLEmVB+Wga0FAm9RrYlTzDUz/LlhA1qhuDm0EwkExGoxzXEVV6SMLINw0vwxPvFCdW5wxP/yWWQeZe3d4/Hi7ooq4vFXJtwK2W6+fJ94vuPlKyOZQMnLvOUCRuXYNIFo/9iHRj19Oq3CqZfK4XuuV5oO3exotL/xBGaCrYm/iR0V6fotc/bwI0Pwkq3h/+kOfWmroVdF2foSH6m3ynRpFVRCOLQz+a8UwY1GDIJVhujOu7o/Le32s/fuA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU4PR08MB11150 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB1PEPF000509FE.eurprd03.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 71252e9f-889a-408e-90e4-08deecbb6683 X-Microsoft-Antispam: BCL:0; ARA:13230040|23010399003|36860700016|1800799024|14060799003|376014|82310400026|35042699022|11063799006|10067099003|56012099006|6133799003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: Efg9XuNTkWyu2/T0cBIqVWTJLua57bBPqEba0KZLwhrzzh/5Y2X676bncwB+XUZNLKmfpI5cXOeI8Iy30LS9QynQ+SvexowGSHdDTD6jybKPJGZIxUFNTEVzvKRHoFI1aEz/P4NFcB0HDT7TzakEX6zfaK0LQCYbi5XtHse3eQKDSzXg7547hXeIegwM9YDYtYRgA16z/D9uvDvfh1sNSZoffMjn2HoASg2lyxwZjrow53eOCtxn4EFP+1Ayen/8iQHhp64zqNas2qew6SvFUvbgHTvveOPWptSAQwPn+JcKcTawNy7EDUJC50DvbNTjQIW2HzBpNIh0yFjwLDsn7w3+0JG2JzD9dvy4ygjYuOLv/oUKKMU07+hUHvz4m/D7g1LG7S5dOW4z7IjByXqrQn9ze8vuEoQWW8VFu9B9PfR6uUsFb5j/ITlaYt2MtXzhlv6ahCo2GUT4cH4xP6AZXaaW4o1swCLF2wAAx/IkI/Jsg7yWpKsblBEyrHh+iq4Lh9mKlV9z9CjW++v4HmVhLjhIBF210FKndDs520hZsghPF4uA/1NYgDSZERULE0/o+SPKR0JiKiCyI+CtDFu45iCTT5vLNwIiFlTjIYEa0QY2z5iRep14uMZzsyALLq3+9qaFq3NJ3fqxzkY6RC5+d36U4B+0Xzp2ZhlX6byTpQl/49wrVef0Rh1oN8jCbJn6WwlxPsUtCsOC5YEDVTrA9A== 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)(23010399003)(36860700016)(1800799024)(14060799003)(376014)(82310400026)(35042699022)(11063799006)(10067099003)(56012099006)(6133799003)(22082099003)(18002099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qnyd5WD7mj3D65ntUQ4ZrxxOtnCi2RwYQzk37gRysNmzTJu+ixyCs291wu0W3Xc6Gl9iaxQzFsor8WTpbptitPmABOYSKxJVriOfNGEvBiJe77f/QTVzw9StAUe7XLV33OUmxWWegRcNyJGrim/bO28ZVuB7ZXn/vDOaYz4NbzU4VJ7mZHKpFTTiSM88BFnxnU5XZ2szUbBbmkMxWe9sfNSN6sNuVQxTGMyetIXjMJjrT8hIgEP+OXJuuyru5ROFQiNyIBra88BJ/oxivyR2304V5BNuHgItP/NIZTipg+WuLosIqswwn1RNASaaRH47SnfIaSfUcTylWDW2EkUTFrtqLEPZOKGiLztzMullHVdwLrrCrtAot42W6UJjPZI+KidPa53GKd5uSfrLGGbXh5lrMLakQh919X23xCTgzbMtq39a0l5ctUqj+jszPGMn X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2026 15:19:03.2225 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f871eba2-d806-4b46-8199-08deecbb8ee0 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: DB1PEPF000509FE.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5859 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org Wrap all the boilerplate code required to read a file in a new helper class: file_reader_t. 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, remove 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 file_reader_t. Reviewed-by: Thiago Jung Bauermann --- gdb/amd64-linux-tdep.c | 12 ++--- gdb/linux-tdep.c | 109 ++++++++++++++++++----------------------- gdb/sparc64-tdep.c | 13 +++-- gdb/target.h | 79 +++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+), 76 deletions(-) diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c index 9b23db72bbe..52f16c953d1 100644 --- a/gdb/amd64-linux-tdep.c +++ b/gdb/amd64-linux-tdep.c @@ -1848,14 +1848,11 @@ 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) + file_reader_t proc_status (string_printf ("/proc/%d/status", inf->pid)); + if (!proc_status) 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 +1864,8 @@ 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_filepath ())); return result; } diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 9bdcc55a0e1..11f0a6952ea 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1698,6 +1698,12 @@ parse_smaps_data (const char *data, return smaps; } +static std::vector +parse_smaps_data (const file_reader_t &freader) +{ + return parse_smaps_data (freader.data (), freader.filepath ()); +} + /* Helper that checks if an address is in a memory tag page for a live process. */ @@ -1709,17 +1715,13 @@ linux_process_address_in_memtag_page (CORE_ADDR address) ptid_t ptid = get_process_reference_ptid (); - std::string smaps_file = string_printf ("/proc/%ld/smaps", ptid.lwp ()); - - gdb::unique_xmalloc_ptr data - = target_fileio_read_stralloc (NULL, smaps_file.c_str ()); - - if (data == nullptr) + file_reader_t smaps_freader + (string_printf ("/proc/%ld/smaps", ptid.lwp ())); + if (!smaps_freader) return false; /* Parse the contents of smaps into a vector. */ - std::vector smaps - = parse_smaps_data (data.get (), smaps_file); + std::vector smaps = parse_smaps_data (smaps_freader); for (const smaps_data &map : smaps) { @@ -1783,17 +1785,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) + file_reader_t coredump_filter_freader + (string_printf ("/proc/%ld/coredump_filter", ptid.lwp ())); + if (coredump_filter_freader) { unsigned int flags; - sscanf (coredumpfilterdata.get (), "%x", &flags); + sscanf (coredump_filter_freader.data (), "%x", &flags); filterflags = (enum filter_flag) flags; } } @@ -2296,9 +2294,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. */ @@ -2320,24 +2315,27 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) gdb_assert (p != nullptr); - /* Obtaining PID and filename. */ - xsnprintf (filename, sizeof (filename), "/proc/%ld/cmdline", 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); + file_reader_t cmdline_freader + (string_printf ("/proc/%ld/cmdline", ptid.lwp ())); + if (!cmdline_freader) + 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); + cmdline_freader.c_filepath ()); return false; } @@ -2347,27 +2345,24 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) p->pr_pid = ptid.pid (); /* 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/%ld/stat", ptid.lwp ()); - /* 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') + file_reader_t stat_freader + (string_printf ("/proc/%ld/stat", ptid.lwp ())); + const char *proc_stat = stat_freader.data (); + if (!stat_freader || *proc_stat == '\0') { /* Despite being unable to read more information about the process, we return true here because at least we have its @@ -2439,13 +2434,10 @@ 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/%ld/status", ptid.lwp ()); - /* 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') + file_reader_t status_freader + (string_printf ("/proc/%ld/status", ptid.lwp ())); + char *proc_status = status_freader.data (); + if (!status_freader || *proc_status == '\0') { /* Returning true since we already have a bunch of information. */ return true; @@ -2838,9 +2830,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; @@ -2878,7 +2867,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 @@ -2888,15 +2877,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) + file_reader_t task_maps_freader + (string_printf ("/proc/%ld/task/%ld/maps", pid, pid)); + if (!task_maps_freader.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)) { @@ -2915,7 +2903,8 @@ linux_vsyscall_range_raw (struct gdbarch *gdbarch, struct mem_range *range) } } else - warning (_("unable to open /proc file '%s'"), filename); + warning (_("unable to open /proc file '%s'"), + task_maps_freader.c_filepath ()); return false; } @@ -3242,16 +3231,12 @@ linux_address_in_shadow_stack_mem_range ptid_t ptid = get_process_reference_ptid (); - std::string smaps_file = string_printf ("/proc/%ld/smaps", ptid.lwp ()); - - gdb::unique_xmalloc_ptr data - = target_fileio_read_stralloc (nullptr, smaps_file.c_str ()); - - if (data == nullptr) + file_reader_t smaps_freader + (string_printf ("/proc/%ld/smaps", ptid.lwp ())); + if (!smaps_freader) return false; - const std::vector smaps - = parse_smaps_data (data.get (), 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..955631b87df 100644 --- a/gdb/sparc64-tdep.c +++ b/gdb/sparc64-tdep.c @@ -301,18 +301,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) + file_reader_t adi_maps_freader + (string_printf ("/proc/%d/adi/maps", pid)); + if (adi_maps_freader.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)) { @@ -329,7 +327,8 @@ adi_is_addr_mapped (CORE_ADDR vaddr, size_t cnt) } } else - warning (_("unable to open /proc file '%s'"), filename); + warning (_("unable to open /proc file '%s'"), + adi_maps_freader.c_filepath ()); return false; } diff --git a/gdb/target.h b/gdb/target.h index 819279c08fc..09830dfe3a9 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -2341,6 +2341,85 @@ 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 file_reader_t +{ + /* The filepath of the file being read. */ + std::string m_filepath; + /* Smart pointer to the data. */ + gdb::unique_xmalloc_ptr m_data; + /* Number of bytes read. */ + LONGEST m_size; + +public: + file_reader_t (const std::string &filepath) + : m_filepath (filepath) + , m_size (0) + { + if constexpr (std::is_same_v) + m_data = target_fileio_read_stralloc (nullptr, m_filepath.c_str (), + &m_size); + else + { + gdb_byte *buf = nullptr; + m_size = target_fileio_read_alloc (nullptr, m_filepath.c_str (), &buf); + m_data = gdb::unique_xmalloc_ptr (reinterpret_cast(buf)); + } + } + + file_reader_t (file_reader_t &&other) + : m_filepath (std::move (other.m_filepath)) + , m_data (std::move (other.m_data)) + , m_size (other.m_size) + {} + + /* Return true if the file was read successfully but contained no data. */ + bool empty () const noexcept + { return m_data != nullptr && m_size == 0; } + + /* Return true if the file could not be read. */ + bool error () const noexcept + { return m_data == nullptr || m_size < 0; } + + /* Return true if the file was read successfully and is non-empty. */ + explicit operator bool () const noexcept + { return !(error () || empty ()); } + + /* Return a pointer to the data. */ + T *data () const noexcept + { return m_data.get (); } + + /* Return the number of bytes read. */ + LONGEST size () const noexcept + { + /* 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 span of the data. */ + gdb::array_view view () const noexcept + { return gdb::array_view (m_data.get (), size ()); } + + /* Return a span of the data, reinterpreted as U objects. */ + template + gdb::array_view cast_view () const noexcept + { + return gdb::array_view (reinterpret_cast (m_data.get ()), + size () * sizeof (T) / sizeof (U)); + } + + /* Return the path of the file that was read. */ + const std::string &filepath () const noexcept + { return m_filepath; } + + /* Return the path of the file that was read as a C string. */ + const char *c_filepath () const noexcept + { return m_filepath.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 From patchwork Tue Jul 28 15:16:58 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Longo X-Patchwork-Id: 140101 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 57C354BB3BE5 for ; Tue, 28 Jul 2026 15:20:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57C354BB3BE5 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=r154+F5E; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=r154+F5E X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazlp170100001.outbound.protection.outlook.com [IPv6:2a01:111:f403:c201::1]) by sourceware.org (Postfix) with ESMTPS id 0C75D4BA9000 for ; Tue, 28 Jul 2026 15:19:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C75D4BA9000 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 0C75D4BA9000 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c201::1 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1785251945; cv=pass; b=ERVJFLvdUatO7w4hxQG5vytOoUSLFPmDXJeJNdJ3JZrAmfAXuId3NqpR68oAi2tJu/h81ZjgKvzjhvhPUq6T7gFWkh1dZo2dlKLGD+977NCjfpwkKhtSCHEr3xhZrJLX4vbv1vytI92wqsGAibAfxP5doO7b5YBA7uWBoMkQbwM= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1785251945; c=relaxed/simple; bh=FjMBEiRDXUCRXxXokiIkTxPwQDXjf+qpD4yZ4gJ66yY=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=BfVHEuAtGOG6RrN8rPelwGAaIEjP13WhCdeApe4RVLHpIesolVMwYfF2UsWtKRRtVgJP4rMhiqo8Mx6MUNBQM3h5eSY8e8cHFOrK75GnAIBIXSerUDhO3C2/zRnG1SFV+Mx5qS0dc3GpSaFRBXS0liBbl/tli9Gk3pjyBjWhQco= 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=r154+F5E; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=r154+F5E DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C75D4BA9000 ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=NZkwaEh8fYC0oJThXxcHD+VPvxgirwGELbfhsExzygbexQcAg1mRyHejcS9diI+kM3isBlXiAgiVFA78ZeLVceuat2upLp6kH/haJhyai7InPi+OPRgjJ1xiXtdGj6+LmyOaoZrrTxrqJ9N6tU/aVqebcMeZB5YoAkWEj5/fiUhMqEeW4qyyyGuO04qtLTdFB4ZCvOvA8ZaLwZ2vmKSTPCusgN1cQybqknN5TOyQKu1icfZBYPWVZPk6DrqsKK2WfcechR18BAvK/uvWmnWmVSiAl0q9XfKNWo8yO98afdRz7Z+GDZoNpfXjtDa9pT06fR8vZdgfPRNxDy15VJrc6A== 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=WyKFFVesH5dTckpAjULEyoA7HQiROgi2KJxAC2kBoqQ=; b=pLjh3vCAHRRZzFNEwj8CFVfzSU/7fC0RhOY2oZ2WG9OsQVwPHxc0m/3yC8PJ38f8PxbkrXBQqEBU6217Smj6YX26sEc5qc3AYZG0vAWKke1dU9EjVThHks9EDRWfXTYDmTgvauPUZ3jcNDnyEnT3vohX35Ht9PCVIpoFyRbJCnSqSVDq+lGEFvfmUVAWDP4LXGK7NJZrm5DqrpSCcCflgfeipBKdzGSXTCVyZXl+8qVULjR7U5ns7gG7pi/YMjhdk8Z7ycPmmRYiCBTeY/Nw8Or9C2sqK//2XlLqVxbsWkDGzeY/ThhxS4alE6QVoJQk1PKl+wci1HKHtlART+fuCQ== 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=WyKFFVesH5dTckpAjULEyoA7HQiROgi2KJxAC2kBoqQ=; b=r154+F5EaWHXsnBAZvePnzVaJSWDAaAEMkGwoHsmCjz1Xw2/a9boXd3Axzjgk4R9FZJzd4cFp7J+S45zxdUcFXg9kf33gfMIsywEtLVquU2iRD/wwrCuISYxRZugyCSgFzfZE0dYMb9OZYIokEKrpmRS0IZI6y0YR63aWO/pnr8= Received: from DU6P191CA0065.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:53e::27) by AS8PR08MB7324.eurprd08.prod.outlook.com (2603:10a6:20b:443::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.12; Tue, 28 Jul 2026 15:18:59 +0000 Received: from DB5PEPF00014B90.eurprd02.prod.outlook.com (2603:10a6:10:53e:cafe::75) by DU6P191CA0065.outlook.office365.com (2603:10a6:10:53e::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.12 via Frontend Transport; Tue, 28 Jul 2026 15:18:59 +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 DB5PEPF00014B90.mail.protection.outlook.com (10.167.8.228) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Tue, 28 Jul 2026 15:18:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GYRnKD+6FYlSjflqud165fhCX8sdeiVIgbkDsgF8oUUx3ocNj2+17Jzgo5Qski4cyF4uhK1P9VrIy3KCPOza/+vCn3E96rLpxcMv0AFT8WJURyqFnRbBSinYzJFvw3aoZ72XYdnQLr56yubVlFUjiO4jN4V5MwkJ5ZWEP8ecySKIuG8kktm6a6+hZ8u8ubJy7B0eQO7wN1bOIt3K3P/D+IVK9+41zoBEcfL9oCtJ4bl5LlMfGMXwcZlIU+hwGFtFDLp0QjTn9o83Esrn+SiNF+8Mn0sfF0uDJpn9AXSQLCnluyUpcTX7CoH3oRBeD5Y/uToeFR3FqIwYh+IzKx/ylw== 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=WyKFFVesH5dTckpAjULEyoA7HQiROgi2KJxAC2kBoqQ=; b=SvKd4DcTqP3YjmrsKRRiVVua+k/Mh6CaqpIWQ4I7bkgRpl3pClfo1XJkBetWlyZa7OKMvyS3X6u1KSFPdmo9jKKDoe89pNY//iRv7d2bOv/tmk49RnspqoVLUlMmncfy3AaO50wAx2+scmKHPqubQ4QuGlTrUAfxyO/jQXA2aC+kl9yb37JZGCB46q0aIAWu2z4Qp4OjBl6xUXwkIwXd7CXsdRLTG5MjrVd7K0kngEgH0aXt+k1SCWdJBAkNke+XaViVBjWFdkFIzPLl0Qgxvf7io7SuwxMGQ7KZchXInn1AM8wlXzFGeqJJfHeKJDBcDaX0KI30weknpKn8E0+EFQ== 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=WyKFFVesH5dTckpAjULEyoA7HQiROgi2KJxAC2kBoqQ=; b=r154+F5EaWHXsnBAZvePnzVaJSWDAaAEMkGwoHsmCjz1Xw2/a9boXd3Axzjgk4R9FZJzd4cFp7J+S45zxdUcFXg9kf33gfMIsywEtLVquU2iRD/wwrCuISYxRZugyCSgFzfZE0dYMb9OZYIokEKrpmRS0IZI6y0YR63aWO/pnr8= Received: from DU2P251CA0021.EURP251.PROD.OUTLOOK.COM (2603:10a6:10:230::24) by PR3PR08MB5563.eurprd08.prod.outlook.com (2603:10a6:102:89::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.13; Tue, 28 Jul 2026 15:17:51 +0000 Received: from DU2PEPF00028D03.eurprd03.prod.outlook.com (2603:10a6:10:230:cafe::1b) by DU2P251CA0021.outlook.office365.com (2603:10a6:10:230::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.245.13 via Frontend Transport; Tue, 28 Jul 2026 15:17:51 +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 DU2PEPF00028D03.mail.protection.outlook.com (10.167.242.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.5 via Frontend Transport; Tue, 28 Jul 2026 15:17:51 +0000 Received: from AZ-NEU-EX03.Arm.com (10.240.25.137) 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; Tue, 28 Jul 2026 15:17:49 +0000 Received: from PF4S4363.arm.com (10.57.42.206) by mail.arm.com (10.240.25.137) with Microsoft SMTP Server id 15.2.2562.29 via Frontend Transport; Tue, 28 Jul 2026 15:17:48 +0000 From: Matthieu Longo To: CC: Luis Machado , Luis Machado , Thiago Jung Bauermann , Simon Marchi , "Kevin Buettner" , Christina Schimpe , Christina Joos , Matthieu Longo Subject: [PATCH v1 4/6] gdb/linux-tdep: migrate linux_info_proc to file_reader_t Date: Tue, 28 Jul 2026 16:16:58 +0100 Message-ID: <20260728151700.253720-5-matthieu.longo@arm.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260728151700.253720-1-matthieu.longo@arm.com> References: <20260728151700.253720-1-matthieu.longo@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DU2PEPF00028D03:EE_|PR3PR08MB5563:EE_|DB5PEPF00014B90:EE_|AS8PR08MB7324:EE_ X-MS-Office365-Filtering-Correlation-Id: bd07c561-6c9b-42a5-1b8b-08deecbb8bb8 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; ARA:13230040|23010399003|82310400026|1800799024|376014|36860700016|56012099006|11063799006|10067099003|6133799003|8126099003|18002099003|22082099003|3023799007; X-Microsoft-Antispam-Message-Info-Original: 87ICgHSZkv5/wVhe6kF45UKNktgiZh7XMTxdFg8tE+yGfBOqgUaiEwlVKLkmhjulnTNBCy/P5hS0oIVOBs3l4vOYnT1/oFNPcnT8GEG/tTgS+JgWYur55WM8/IFnSwfxSiAtwhWWYIPXzW/eev388ubaW/x6cCuzwyGNRWGucUxwvcQXBvk7I58An0mqBiTjqhJ48OXZ7qO4KUtsPhRqqTdvSz556WDTKdFKBzH1di0HA8Q96v6+1GxxZjpvVePxJbo581c/xTX69S636RlvF36BtQ86DBYD1+5fV0Ap0mw3XM66X9ObkwBXo/z2hY8iiK3LCouNYrOQLX9WxtV+o92VaZyu6cDHMnTYjaeJpWzEXRNZqKu5g4pC71+S/RVn8hvRsGowYJ5OPIfvg67mhtDVTaHZrxCTfvvqCbKt176sm2+SwPMgogADYGh6xi8NKE84S9D92KpWEqYfboxo75n0zZXDc+bYPIg13yDEo/FreGzGssAtV64CtO8zwVNTaWfAwdj1kYvlhzfOWxgGDd2w7jTD/UBQxRIbzvlTOkqkTuDz7lrRLrpcagkqeuJYm8jwTpnTx9LEg0pUXtp0W2fUsCeNeDe9F9L0K5rPEyaGudrEWgJnwPZPU3Sc9h9XIHhWLWjqAPQLzwVD0pFIJsM1iCBPtgvHr9fMOLWxaEMYvj1kKV6x33jjhfFMd55esY/MgG1QNUyp9gFplwa3rQ== 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)(23010399003)(82310400026)(1800799024)(376014)(36860700016)(56012099006)(11063799006)(10067099003)(6133799003)(8126099003)(18002099003)(22082099003)(3023799007); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: eOsoAiWWHK7tECo/hgQSV8PDN3gXiI4c6SP+5ytchnXe30BxTqRY3+xrGY5w1/zjtCeP20C/N1w88Sh33EJsptf/vSYJQh2SzAsD+wG6qmbftHHADIOSre2RrsGnvZQDFTG+KCP2sfHQNtqQUPLAc6m4wjT3A+DnBXfKRAW2ZMSf/oKqhviYj04jlUdc+xeQ1mhianuiCcX+xnp7vXebediSF5oV2ohVsiRgWSBoe09iU8z2UgQKxQSDKM6mnNXa4jLeqXvn1D9JpnB1GaI3y6RswxFyYMRmcTBrQH8muTHipnO0C1cifmkTaTloi2WM4hnxenke3O3RWrOu6ibCog== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR08MB5563 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5PEPF00014B90.eurprd02.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 8aebe758-8c53-43ee-8433-08deecbb63d9 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|35042699022|376014|1800799024|36860700016|23010399003|14060799003|8126099003|18002099003|22082099003|6133799003|3023799007|11063799006|56012099006|10067099003; X-Microsoft-Antispam-Message-Info: OqJ8KbTKIF8r9SX5XTg77DaBZ7CtLNjP819QxIN9XoFLiAl+zoIMsmkQDeSERhdpoGS36Rb72nkHqGrlYzYfJms0KkBP7Con9TQPXq2tbQ6BqPn7fkE2uXN0JmUH4QWZntIBA96YicB5HNf5KiG5siJSZTfB8FFBfIXbjroIvQzkvLD+8JMwZDclf6psLanQZyzjEGF+4QFGJingAVnm3gPwnZNtecpLUUMWu+fRElhvb2bydfm3vrtEgIOAGME4n4HpQkzuqExfPmEzc9pTD5IY6Ngty6bWjBPNQ41Br2/4VigvkaFOxc86ARYBYy7Eoz9Ev513F1e8Du+gvzTd69H/cReCsdGMAovcYU1u/cgaLYB7H9AoZJOWn+LQcAVIbPtJkBkSDxS/03tped56UA1lLwD9UMtG9PM4jRmRtwQs6jicFCJj+4JjHHEaLsT2mBwB6c9tulQVVtsXnUUtbM/KRJh9Nco9WcM6revfgveDUdmQWXyW68rUT2bngsolOsr5k78K0s7kMeW6mzCkOFgqfuYOWemnlaAH/L/KxeS9aLR4qnQTQmOqDhKquAdFrMp0PCS0MYeBj3j+Mi9L1Iwi3AB2HUgiCx8e3mRE5kazVVXZ3Dcm6N3eoLX5gL2ylwjcHoPr3QVHSdDdC+fhwYhrhVN6Al07ZD78dimhXtqZ7vs5WrNlCBds1KRJtJAfDY9bST49vcOYsa4+Q6hhKQ== 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)(82310400026)(35042699022)(376014)(1800799024)(36860700016)(23010399003)(14060799003)(8126099003)(18002099003)(22082099003)(6133799003)(3023799007)(11063799006)(56012099006)(10067099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xaLXzPFIIIox63RHMxI0WcXuXp52ayJzlfv/hnJUuQt+9Ds0OKZYcGsm3k/jwqZgtB7cQahYUDjN/l6DGvwiXL78/+UZ54YwhEpqV6LgBqm7pPVAe80zdxGQIX7aFS3M1WM+dqJsxaOF8nAOeR8k5WiMI/CO8ZuVaLAwzytp726G8ex3P44aGXnm7hh7tIRRqoW10gThsx38H1iasl2A5JMjo54kN4ic2a/AhXPIujRqFRa/F/9Lpl8mu+R6st4iNG04RKiSPuV0rhBnkVxRHnsioIN5Q6ca/HzPfU7hZ2hsSyj9hnPcubIG9cFwOyyDhoBDXmx2eqdTd5EfiDSgAMbcZnY7spjpV/mFCe9lwXTfK/hrD1UMj0hiP1jo5GoMnzj1owx5F5MTjIkOoQw92eMW62mxRlOf1T0HxIKKIiMubZv0R3w4E9HvQohuz5QB X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2026 15:18:57.9236 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bd07c561-6c9b-42a5-1b8b-08deecbb8bb8 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: DB5PEPF00014B90.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB7324 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org The patch migrates the code of linux_info_proc to use file_reader_t to read the procfs files. The availability of array_views allows to also simplify the logic in several places, where null-terminating characters are replaced by spaces, or where the file content is iterated line by line. In the last case, a new helper function, extract_string_view_from_buffer, encapsulates the logic for such iterations where string are separated by tokens. Reviewed-by: Thiago Jung Bauermann --- gdb/linux-tdep.c | 135 +++++++++++++++++++++++++++++------------------ 1 file changed, 84 insertions(+), 51 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 11f0a6952ea..a8dab0d6d5e 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -874,6 +874,39 @@ dump_note_entry_p (filter_flags filterflags, const smaps_data &map) return true; } +/* Extract a string view from BUFFER starting at START and ending at the + first occurrence of SEPARATOR. + Return the extracted view together with an iterator to the beginning of + the next entry, skipping any successive separators. If no separator + is found, return the remainder of BUFFER starting at START. If there is + no following entry, the returned iterator is BUFFER.end (). */ + +static std::pair, gdb::array_view::iterator> +extract_string_view_from_buffer (gdb::array_view &buffer, + gdb::array_view::iterator start, + char separator = '\0') +{ + auto next_start = buffer.end (); + + /* Reject a START iterator that does not point into BUFFER. */ + if (start < buffer.begin () || start >= buffer.end ()) + return {gdb::array_view (), next_start}; + + auto it = std::find (start, buffer.end (), separator); + + /* If no separator is found, the remainder of BUFFER is the final string. */ + if (it != buffer.end ()) + { + /* Otherwise, skip successive separators so that NEXT_START points to + the beginning of the next string, if any. */ + for (next_start = std::next (it); + next_start != buffer.end () && *next_start == separator; + next_start = std::next (next_start)); + } + + return {gdb::array_view (start, it), next_start}; +} + /* Implement the "info proc" command. */ static void @@ -915,25 +948,23 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, if (cmdline_f) { - xsnprintf (filename, sizeof filename, "/proc/%ld/cmdline", ptid.lwp ()); - gdb_byte *buffer; - LONGEST len = target_fileio_read_alloc (nullptr, filename, &buffer); - - if (len > 0) + file_reader_t cmdline_freader + (string_printf ("/proc/%ld/cmdline", ptid.lwp ())); + if (cmdline_freader) { - gdb::unique_xmalloc_ptr cmdline ((char *) buffer); - ssize_t pos; - - for (pos = 0; pos < len - 1; pos++) - { - if (buffer[pos] == '\0') - buffer[pos] = ' '; - } - buffer[len - 1] = '\0'; - gdb_printf ("cmdline = '%s'\n", buffer); + /* /proc//cmdline stores the command-line arguments as a + sequence of NUL-separated strings. */ + gdb::array_view cmdline = cmdline_freader.cast_view (); + gdb_assert (cmdline[cmdline.size () - 1] == '\0'); + /* Replace null characters splitting the arguments in the command + line by spaces, except for the last one. */ + gdb::ranges::replace + (cmdline.slice (0, cmdline.size () - 1), '\0', ' '); + gdb_printf ("cmdline = '%s'\n", cmdline.data ()); } else - warning (_("unable to open /proc file '%s'"), filename); + warning (_("unable to open /proc file '%s'"), + cmdline_freader.c_filepath ()); } if (cwd_f) { @@ -947,27 +978,25 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, } if (environ_f) { - xsnprintf (filename, sizeof filename, "/proc/%ld/environ", ptid.lwp ()); - gdb_byte *buffer; - LONGEST len = target_fileio_read_alloc (nullptr, filename, &buffer); - - if (len > 0) + file_reader_t environ_freader + (string_printf ("/proc/%ld/environ", ptid.lwp ())); + if (environ_freader) { - gdb::unique_xmalloc_ptr dealloc ((char *) buffer); gdb_printf (_("Environment variables:\n\n")); - + gdb::array_view buffer = environ_freader.cast_view (); /* Entries are separated by the null character. Print each environment variable, line by line. */ - gdb_byte *buffer_end = buffer + len; - while (buffer < buffer_end) + for (auto it = buffer.begin (); it != buffer.end ();) { - gdb_printf (" %s\n", buffer); - /* +1 for the null character. */ - buffer += strlen ((char *) buffer) + 1; + auto [ntbs, next_start] + = extract_string_view_from_buffer (buffer, it, '\0'); + gdb_printf (" %s\n", ntbs.data ()); + it = next_start; } } else - warning (_("unable to open /proc file '%s'"), filename); + warning (_("unable to open /proc file '%s'"), + environ_freader.c_filepath ()); } if (exe_f) { @@ -981,10 +1010,9 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, } if (mappings_f) { - xsnprintf (filename, sizeof filename, "/proc/%ld/maps", ptid.lwp ()); - gdb::unique_xmalloc_ptr map - = target_fileio_read_stralloc (NULL, filename); - if (map != NULL) + file_reader_t map_freader + (string_printf ("/proc/%ld/maps", ptid.lwp ())); + if (map_freader) { gdb_printf (_("Mapped address spaces:\n\n")); ui_out_emit_table emitter (current_uiout, 6, -1, "ProcMappings"); @@ -998,12 +1026,16 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, current_uiout->table_header (0, ui_left, "objfile", "File"); current_uiout->table_body (); - char *saveptr; - for (const char *line = strtok_r (map.get (), "\n", &saveptr); - line != nullptr; - line = strtok_r (nullptr, "\n", &saveptr)) + auto content = map_freader.view (); + for (auto it = content.begin (); it != content.end ();) { - struct mapping m = read_mapping (line); + auto [line, next_line_begin] + = extract_string_view_from_buffer (content, it, '\n'); + it = next_line_begin; + + /* read_mapping() expects a null-terminated string. */ + *std::prev (it) = '\0'; + struct mapping m = read_mapping (line.data ()); ui_out_emit_tuple tuple_emitter (current_uiout, nullptr); current_uiout->field_core_addr ("start", gdbarch, m.addr); @@ -1022,26 +1054,26 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, } } else - warning (_("unable to open /proc file '%s'"), filename); + warning (_("unable to open /proc file '%s'"), + map_freader.c_filepath ()); } if (status_f) { - xsnprintf (filename, sizeof filename, "/proc/%ld/status", ptid.lwp ()); - gdb::unique_xmalloc_ptr status - = target_fileio_read_stralloc (NULL, filename); - if (status) - gdb_puts (status.get ()); + file_reader_t status_freader + (string_printf ("/proc/%ld/status", ptid.lwp ())); + if (status_freader) + gdb_puts (status_freader.data ()); else - warning (_("unable to open /proc file '%s'"), filename); + warning (_("unable to open /proc file '%s'"), + status_freader.c_filepath ()); } if (stat_f) { - xsnprintf (filename, sizeof filename, "/proc/%ld/stat", ptid.lwp ()); - gdb::unique_xmalloc_ptr statstr - = target_fileio_read_stralloc (NULL, filename); - if (statstr) + file_reader_t stat_freader + (string_printf ("/proc/%ld/stat", ptid.lwp ())); + if (stat_freader) { - const char *p = statstr.get (); + const char *p = stat_freader.data (); gdb_printf (_("Process: %s\n"), pulongest (strtoulst (p, &p, 10))); @@ -1168,7 +1200,8 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, #endif } else - warning (_("unable to open /proc file '%s'"), filename); + warning (_("unable to open /proc file '%s'"), + stat_freader.c_filepath ()); } } From patchwork Tue Jul 28 15:16:59 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Longo X-Patchwork-Id: 140099 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4873C4BB3BE5 for ; Tue, 28 Jul 2026 15:20:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4873C4BB3BE5 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=c3JcpUnL; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=c3JcpUnL X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11012064.outbound.protection.outlook.com [52.101.66.64]) by sourceware.org (Postfix) with ESMTPS id DAB4B4BB3BC2 for ; Tue, 28 Jul 2026 15:19:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DAB4B4BB3BC2 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 DAB4B4BB3BC2 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=52.101.66.64 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1785251966; cv=pass; b=HUK2MZlwWfse3Jt7jXX8n9dhSJM/Q+ow+XpCmI6mYQduP28v3c+3Rq93qM2iugm8Zw5HrUQfUn157HadavG7cVpStNeKq0zNg972pEemHTCXM6yjETOKo4dL0VxU5/AXaZVNHAPCJbRd4BjWo987qmAZ5VM+Y++1ocMaK8VUwig= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1785251966; c=relaxed/simple; bh=rrUNjH/p92JbcwIyAeKFhQ2tmt4fxAQ2hAxfpAxs9kE=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=TL9l2iq2GCt9JDsEvdS7D0uOLxWeEJls9Ku8gqHu4UNOm/uDzYNAcQjbWXzI6wFMP+iYdZFTkJ1rHzJ8axv3h6EUaXHvO4KW4+fUkrHlfvcc8Uq1RC9beX+FRXe2hZpOG2PHoEXGo5sYJJJoekYzHAD9c8oUEUd+7m3j0F+PsEI= 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=c3JcpUnL; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=c3JcpUnL DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAB4B4BB3BC2 ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=M/tZMJZhJQ2IqfLHNXOIezJu6qCpHlrWucp2gmVA6Ifamf6/NsEixr1qyLeRGmctXTKemMsz1U/o1WRJ+8qVM/0oMnmddwDNN5xnxu37maIyMm3cLBnG2poy3JLHhVilDxXgbkH6yEscCbrG68cJS5hUi/bFZ8uSNsuoBw5KdyA9RZNVR4f8weBP/hE/0z9TIEis3yIGNTPb99AQKVLsCyBk08bjhLlXZH9pUspfxcOJ1bPDLtHY590r1kpShQ/8xmYKAqru36XNcaBNRpq1kKw/E8/64pf3MIRfTJTvwadT3jYewoxCS58FkRjwTb0i/eXeuuu5YLof+v/4miqK4Q== 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=slmPtIgal0OcCq24X40AoQahgUdLTk8r9ggGEUh4hWs=; b=Mjruq8TQQdGlKTdcfWkvYSzrehFH78eJRHAljDywdNm9i1/2ZdXoUyXBX8yR2Anl9GbBryCK4giZijFQyHYV0ZzrB6+QzuIYTBUR8/mOcXo9TbsaRqf1qqIVrxZdNOkQG+mcAK+Yg+VvCis9ZQZbUlU8239sWVruVMMOtdFc1wsIpiEKjlAaU9qu6UKmmhWC7f/1TJOCqFVgRUNReYGzHHaMxa+A1L7Nij5D7dnQn0+jCoZXsl2mveTRBsC0/zn9YjGi5oMAEC4OLVXDEfNCsvEMmq1z71V0RhO/hlxFNQKet6CcrDK4uJH0r3+IbzYWFYjSgP600djyyHkXhCps3A== 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=slmPtIgal0OcCq24X40AoQahgUdLTk8r9ggGEUh4hWs=; b=c3JcpUnLm9/kuosDFxw6LCEQQguSw6cBL8KSJULyS+1xEhKFGj15mPP3uyqGnUd5MJE+V0poGKPo5tXIB0MtcLNETuIgWL1ZunjgZg09yVCLOWgLx1S3ipAXi2/cxFNHVDj8Hwqk2jiKwRpIfMq71yceXypdiSGwKY84dG7/E+I= Received: from AS8P251CA0019.EURP251.PROD.OUTLOOK.COM (2603:10a6:20b:2f2::22) by GVXPR08MB10714.eurprd08.prod.outlook.com (2603:10a6:150:159::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.13; Tue, 28 Jul 2026 15:19:18 +0000 Received: from AMS0EPF000001A6.eurprd05.prod.outlook.com (2603:10a6:20b:2f2:cafe::15) by AS8P251CA0019.outlook.office365.com (2603:10a6:20b:2f2::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.245.13 via Frontend Transport; Tue, 28 Jul 2026 15:19:18 +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 AMS0EPF000001A6.mail.protection.outlook.com (10.167.16.233) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Tue, 28 Jul 2026 15:19:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=glbFt16lrYwWQ7MZgHZxETkGzJ4M9+ae4xgYF7DI4N8gF6gWmcwpLnM8FcQ2bZ4bmnsOPE/O1zVopHIzrTW+u7+uoAk2QagDQKa8it/1aBea8FQz01zWVn23w8BYMn7IE1/n34BBddeHUYEEfCBmaZz6vOSIqVvUQEhjIBgZzQLpLra7sa7ovQkrvNoeTVNONEZkempB6CB1Mu+BiFrkJ86g/SX80BbQbNtIzkvm056ovfDBLhEzMQY21xyuW5M/ihP3kLsTQIfbWS9pEyZnXUnCjDsr8weT2roorV1wlJGbcGHQMzRcenczhKBWzE8yAnZiP8s/wFQ0g1kB/lV/oQ== 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=slmPtIgal0OcCq24X40AoQahgUdLTk8r9ggGEUh4hWs=; b=wdF8MphAJs5yD7MoWbfttsuvvm8qcDTR94RT3Xwwe8WDSyRv3ZFkadzmko2NZNJkBP74rV8ror8UXxVdZkOMBw1gi4fF2o9FK65dWV5NeKyg/5I1M8cyGx1YznRl307Q6QNNYyHL7EU7jscKOhQyu+sfq9AdzxcXM/RvBsC8MQVxu0sXNbnYQUBZ/EM4M/thR5lrSpT4AYl2uU4yk6FU19PNuCIoC6rdJjW3Po5Jt9nE36zsp6z7649ZV3izYCgUImDAe9XAFBMamUvZJJ8h6W/mpf0XHrDigoVh5ZhjzXCJZlVToiA5VnlkXyNvGCF2eGRQiu/TDxnUa8/ZalBAfQ== 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=slmPtIgal0OcCq24X40AoQahgUdLTk8r9ggGEUh4hWs=; b=c3JcpUnLm9/kuosDFxw6LCEQQguSw6cBL8KSJULyS+1xEhKFGj15mPP3uyqGnUd5MJE+V0poGKPo5tXIB0MtcLNETuIgWL1ZunjgZg09yVCLOWgLx1S3ipAXi2/cxFNHVDj8Hwqk2jiKwRpIfMq71yceXypdiSGwKY84dG7/E+I= Received: from DUZPR01CA0312.eurprd01.prod.exchangelabs.com (2603:10a6:10:4ba::8) by AS4PR08MB8219.eurprd08.prod.outlook.com (2603:10a6:20b:51e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.12; Tue, 28 Jul 2026 15:18:11 +0000 Received: from DU2PEPF00028D01.eurprd03.prod.outlook.com (2603:10a6:10:4ba:cafe::ad) by DUZPR01CA0312.outlook.office365.com (2603:10a6:10:4ba::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.245.13 via Frontend Transport; Tue, 28 Jul 2026 15:18:11 +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 DU2PEPF00028D01.mail.protection.outlook.com (10.167.242.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Tue, 28 Jul 2026 15:18:11 +0000 Received: from AZ-NEU-EX03.Arm.com (10.240.25.137) 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; Tue, 28 Jul 2026 15:18:00 +0000 Received: from PF4S4363.arm.com (10.57.42.206) by mail.arm.com (10.240.25.137) with Microsoft SMTP Server id 15.2.2562.29 via Frontend Transport; Tue, 28 Jul 2026 15:17:59 +0000 From: Matthieu Longo To: CC: Luis Machado , Luis Machado , Thiago Jung Bauermann , Simon Marchi , "Kevin Buettner" , Christina Schimpe , Christina Joos , Matthieu Longo Subject: [PATCH v1 5/6] gdb/linux-tdep: migrate linux_find_memory_regions_full to file_reader_t Date: Tue, 28 Jul 2026 16:16:59 +0100 Message-ID: <20260728151700.253720-6-matthieu.longo@arm.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260728151700.253720-1-matthieu.longo@arm.com> References: <20260728151700.253720-1-matthieu.longo@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DU2PEPF00028D01:EE_|AS4PR08MB8219:EE_|AMS0EPF000001A6:EE_|GVXPR08MB10714:EE_ X-MS-Office365-Filtering-Correlation-Id: 185725fa-7455-4ff3-de45-08deecbb97d8 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|82310400026|36860700016|30052699003|23010399003|376014|10067099003|6133799003|11063799006|5023799004|56012099006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info-Original: RmPfGAt6J7i1z/6pF+d7/LwRfVn5YsASQOcF5+MrDhbTffr6JuXGowsi9zwLpYz9+tuoDSVwm/3Am25CCOttWzhkf7iLbAsantv942wApGk/qoydA5WUyp+pqaZBnJ06+XOvPZY8G3MvIGeBT3Fwok1WjMBHJPg/0lXPE8kb/4gpEeHhBSJLjjNzB6jkO6SjKVAigeZTdhYrRX/idJSSQtz9B0GFixmboPdDllVRVrEAJvti5AEDkgtaru1O6DoSiWHepyvgWfCYLJez2pwzP3A011FqihQTDd2X+h96yKT3aEpLJ6c0GYDJvMqOcmqvTiRrK5WrgJy9rYVne8YQc20il8IVotcI+y5wpbuhxIgC9Prns/EveVSafS89MSNbamugecM2o9PoJ6WK0osUW0GsRAM4wvPEM+svhIls7caDXdzz1gIHlgEr5FqH4LMrYSaNMftMIz3T0Yf4hyoBL3gvjRECdlX7+RIfeGAQnE1W9sOagF/qPN0SiUcr3YMnW+6foPIe0hpRckmNUtpkQO6fL9veTwZwr/PHPDsbBbsgD6AFqyXiO/qtVZZgNFU3mmFTOGeUr+5ZJ3MJm/LEK0pNZOVm+rb87ofG0UWUBtzkNO58ZlCEjzMvc//1V2snO97LBv6DDiCg7CnjKXeUDfqLspzCygO9vD6fdgFvzvKoC0oHqbdL2MWP8FDnmfUBQFJRo9cM7O6j7Fxrxw6yZw== 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)(82310400026)(36860700016)(30052699003)(23010399003)(376014)(10067099003)(6133799003)(11063799006)(5023799004)(56012099006)(22082099003)(18002099003); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: BoEpGU6RsOGRW13M6FwgsFrCIigDrmSnu3RZ4sxc5n+PX4gehzhFTx3bNl/w279nLPIWxmUG3+QIT12BBTVKlM6AsOGcgHQp/2x7SE5f3aiQgmBVC4l11yObaGGGIh/0Q6Mj68NnUubkjHoNKQjlpf8ozoW0av2WmGc5HhWDxcoY0/A39B8THK8O7kY/wm/kW1j45lZnVjx0pCKAC4sGaCZBsWStHK0tyjcSEW1DRmSJ4N+EzzH0Yiq/J0rmY0CI9oyJgBUkBfVYeSuOB8rI9IopH5RxVZ9CB2AMNSrgUskmp/kZ/erYcg4Hgmg3L9c0TaUeqLgb0f8/7/jDOQRUVQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR08MB8219 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AMS0EPF000001A6.eurprd05.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 1cd77eab-e919-43d2-92a8-08deecbb701d X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700016|23010399003|14060799003|376014|35042699022|1800799024|30052699003|82310400026|10067099003|5023799004|56012099006|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: 1EzLtCqW3DGKC4FmoMHoObGqhUXoVIprjG6m6f6V7ISae3SZmJPwBsRj5jpwLjdiZ6R28YnEuQJ1ZlUYQTNAy+/OSuGDKMisMDLXyH+Q9f/oszHJY29eAf4C9A0KhIILBEF2cqlmx1XJx0ORm4OcyUVmTLgEh4zyFQG8u7cJXfry7cIt5sbJzsPCYExAmBomOL6sKCnwhVflayyjaUzIXzvqz+FPC3AS5wTiVVta0AMGYE/7S5mS8CB1OUJbzYtBoTEJ/7AxvVCStMjIHZ7/gbFyt+/iycrA4ljBRTCsU7z0pAQ74XRb9CXA9tWiB59cuivTtTPsHn2H74sVIedN3/56Ko8/XkQinnYQNzjrDsWL4HQYkP/aisRJ8xer4AdIX70n8GsK89Ss+nXT0BGXjRWHWkagnwsoBFTVDo33MjtA+aBVKu1Qck+X6PGFpj+riSt1e93W5aH4thKmV2dceWs+1NB754NghWXylB9AJ17Vo4Tc9I6KJoGUsBtYwyuAYNGNKiekxO1+8W612QUDr/ZNyrPtePuE5iApR0/ZStureZG6zIV3ZzYn8Y/M8UIM3wrmPfQKf0GkjRCHY2T0n6ij4zhw9e8xi7P+y5Vegh84B5KCc6J5JObRtrolykGu8BC9ONnK15rEhbNx+SuZJqbzfB8G5hlRsHRbRBy3zIqIce6Xo6iT2BYz/bPQwJ7F/P6GjBjf8qS0kK3xAXCl1A== 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)(36860700016)(23010399003)(14060799003)(376014)(35042699022)(1800799024)(30052699003)(82310400026)(10067099003)(5023799004)(56012099006)(11063799006)(6133799003)(18002099003)(22082099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FP/He8V5jvVbxhJYrdtCqyo5exDspqbR2h6N6/DTG6zhVF+ZdL6Pyh4vUkmojMxeVzdqS6aBICAaFil+pnYoMRZp3PJZ1h1HvK4/+5bgJcveKereMRRMu0us1zbHG7e2csGOFRkSsgxsd0WpICtDoReNKSW9J16xTdFbBsSRCNj2nSrTo9uZCidwCBXrZdBfMI+Kgwc2o3dxQE9UA5LRFt/CqBdLPEu1Y20Q4iwjDiJZEyEgCkTG71LrG47cs5N+yXklWi17w12z54bA0YrHtgQwFjfs0ncPCDNJ2bageWCyEEzZgJgD+WmIV2CjCEsACJoFmb6mcQksw8Ka5OhBXJv79qbfviDcnz9AmFN5GDbCVOdeWbbkkZIzJJfFdzmTgWVyU3gEmjpVDxynrpyAVXYLkf9RnSVbm/Xi0bCFyop297c0EcXjMpFlNPGFG+ZV X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2026 15:19:18.2870 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 185725fa-7455-4ff3-de45-08deecbb97d8 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: AMS0EPF000001A6.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR08MB10714 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org The previous implementation of linux_find_memory_regions_full could still return success even when none of the /proc/PID/[s]maps files existed, or all reads returned 0 bytes (this last case can happen on Linux when the thread-group leader has exited). As a result, the function could incorrectly succeed, allowing core dump generation via the gcore command. This logical defect was allowing, by chance, the function to return success and hence, allowing fortuitously the coredump generation via gcore command (see gcore-stale-thread test for more details). A previous patch in this patch series fixed this issue by using the first LWP ID of the current inferior instead of relying on the PID. This patch adapts the code to use file_reader_t and makes the function return an error if reading any of the procfs files fails. Reviewed-by: Thiago Jung Bauermann --- gdb/linux-tdep.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index a8dab0d6d5e..628f73969d3 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1829,25 +1829,22 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, } } - std::string maps_filename = string_printf ("/proc/%ld/smaps", ptid.lwp ()); - - gdb::unique_xmalloc_ptr data - = target_fileio_read_stralloc (NULL, maps_filename.c_str ()); + std::vector smaps; - if (data == NULL) + file_reader_t smaps_freader + (string_printf ("/proc/%ld/smaps", ptid.lwp ())); + if (smaps_freader) + smaps = parse_smaps_data (smaps_freader); + else { /* Older Linux kernels did not support /proc/PID/smaps. */ - maps_filename = string_printf ("/proc/%ld/maps", ptid.lwp ()); - data = target_fileio_read_stralloc (NULL, maps_filename.c_str ()); - - if (data == nullptr) + file_reader_t maps_freader + (string_printf ("/proc/%ld/maps", ptid.lwp ())); + if (!maps_freader) return false; + smaps = parse_smaps_data (maps_freader); } - /* Parse the contents of smaps into a vector. */ - std::vector smaps - = parse_smaps_data (data.get (), maps_filename); - for (const struct smaps_data &map : smaps) { /* Invoke the callback function to create the corefile segment. */ From patchwork Tue Jul 28 15:17:00 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Longo X-Patchwork-Id: 140100 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 461F44BB3BD5 for ; Tue, 28 Jul 2026 15:20:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 461F44BB3BD5 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=BXx8PeyA; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=BXx8PeyA X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010068.outbound.protection.outlook.com [52.101.69.68]) by sourceware.org (Postfix) with ESMTPS id 0E3BA4BB3BD0 for ; Tue, 28 Jul 2026 15:19:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E3BA4BB3BD0 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 0E3BA4BB3BD0 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=52.101.69.68 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1785251970; cv=pass; b=U6ra2QLD3rOm4P4yQ1uSr49Mrqfve2bvk8IeBrKJ58B2MsFhUcSozHQ4t57Qodi4zBXIG4s9t2JcqNvhuaInlU9tP500kgVCYx/b9lsQE++zjCfl0mj1wn+4gCjDsvQo2uby8pBYC2QMg9oLQf61Be+ZPHqpbBNmoaNY0YZ5MC0= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1785251970; c=relaxed/simple; bh=TFiN/QAjz7qq1oAraSvb+H7Dkry73rSPkbX8k+4/Mdg=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=dgkNWh2pna5PsbRkIHSkx0h8EZ9+JNbompPlBA69QknvYeGhXZMObNtX7fXXI5CTZX+eM9jf7irH/cmohEGoiDU1XvWsPd1YpV1IXgnqHWqTg9say7xheKI2IIemEtGzQKOyV2vsHVy9x8Tn4ilbjKLwmwmNT+ucp7q9KTMnApY= 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=BXx8PeyA; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=BXx8PeyA DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E3BA4BB3BD0 ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=teXq/UbO/bw2pkAJ8iL2VQvgiC3sfe783Znyb+xerC57iuILPPrH4hNDw9MILBZfY3MeWFnbsP+qCD5mpFM7Ur9YNupnanXXSfNHUV3YbjjCtqFLGWPfSnRy3Sdl6LnbKGFyykMC9MLBplsWMNzPtqsBZl6JQlvtxdAVGRhvTV8FzG00Ng+b+UuhnOD+1PTcTLCZNnKXJZH64FRk0AcZVeDiamk3Pq2bSSVHSIpZsa3tnxJGly+gbUWDh9LriOK/4VhNCO+Q4N/QjI0Y0aTHpQpiYWJEbB6YS1bgu8x9gZKWNS4+qkrxDVE9ZBGTWJqHtYGbvezn9KJeGoYmMLQzaA== 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=caL19bQUtA769uO1p1HCfJ5Djj2+yKIkeznfThPrBls=; b=SZL9fRo7YzvMXc+ZckmChzwxh6FgMYP7iH/Qx8exwqLllbWVq5VZa9/Skn+nRXZiuboxB4tY5VuxE0BE2VxY89ioqvK9Qhn2NhBMg7uuZh9CQcw3xZxEjrQw7kA43+ju1UPgOLaPgihnjsRib4x7LpLLyQ2+PP3xEEVFaPp0GwhgWqzUFvVZmbNfg6TITh0T65Mxp4vlVeh2+h4kAipRfiZVyx/UsbldRZauAKhx/ox/sa36KMCags1ah1RoOY1bQU/kE1kOFyOOTFQ9tCWMpmSy6M9nb+I1qWrk79qdjmPmP+aeR0iL5bDzXfvxz6fLFB0ecrqRWr17PlfotkAMvg== 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=caL19bQUtA769uO1p1HCfJ5Djj2+yKIkeznfThPrBls=; b=BXx8PeyAPVGSlicVzeMSJIOkUkdXFvIS8DJd1hwfnhAw4zz1dCRejAlEwgQAWlS7umbFn0f+bMJgB1JOOIux/CrrpUN+F0NKTpkuRdxOFH4vAzMruYchnv4ihlYORG8Og3eEopZkSxqeuDXa053DA79qHMBQIe+hVoCakEt9k7s= Received: from AS4P190CA0051.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:656::25) by DB4PR08MB9359.eurprd08.prod.outlook.com (2603:10a6:10:3f1::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.13; Tue, 28 Jul 2026 15:19:20 +0000 Received: from AM4PEPF00027A69.eurprd04.prod.outlook.com (2603:10a6:20b:656:cafe::12) by AS4P190CA0051.outlook.office365.com (2603:10a6:20b:656::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.12 via Frontend Transport; Tue, 28 Jul 2026 15:19:20 +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 AM4PEPF00027A69.mail.protection.outlook.com (10.167.16.87) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Tue, 28 Jul 2026 15:19:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VtPMqZG0fjJZ5a3M9BhJGvc88rUC870fDljjrUUXIIth3/KuvuzclaHBrZXOgXrn2uP/AVh04IP9UPOddKptAeoqdbeh9qz8dRaWZcQmSYW6Q2DysyxM3ij8Apm/fvmlXIBFG8XCcUAA479gjlG55bUqTmdooEOO94oRHsp98/EYd+Y+TwI4PNkMpX0NrM/aMge7fo8F/U/hCOBG8JX9Wt1+FY906b/FbFrIELvUJ/4CUGs9xRsn91WDti76Ovv22YIqZjE28RFD+TzN2DJIfA0LY6T1eQ34BXLRT7YKe61TABMwYXPW6ijyMdo87snrRSsKOHPZ456saFocwqGgNA== 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=caL19bQUtA769uO1p1HCfJ5Djj2+yKIkeznfThPrBls=; b=ClgMuLBZnu7LwSNB5KYa/8cMx3SAIbk5feegEuupyma8QCJ1RQtvzAHmBGvkpRos3ajEyCjOCd4m9A84vNiPmeELdlrpxqlAyxtv6SH2TT2GvUssm6rTkGfHjdinfLj4FXe4RQoLCe2gtEZB0nCEewtYgg+qYs+u4oyKGbffw0w3rlpiAYeij65S6FH8PA+5fjTPwSnJmsAf+GIXnHerli04b56E5bbpGCuapT9YmnsRU1Yfb8781rFcss/P5lKZZ7CxVseSzScJl0ija6RIG6ff0HEaucx5KUiPurN2cUuFFZJ288bpFYQHRTljr3PWmTdb4dFzeV4hB2eEP+QTMw== 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=caL19bQUtA769uO1p1HCfJ5Djj2+yKIkeznfThPrBls=; b=BXx8PeyAPVGSlicVzeMSJIOkUkdXFvIS8DJd1hwfnhAw4zz1dCRejAlEwgQAWlS7umbFn0f+bMJgB1JOOIux/CrrpUN+F0NKTpkuRdxOFH4vAzMruYchnv4ihlYORG8Og3eEopZkSxqeuDXa053DA79qHMBQIe+hVoCakEt9k7s= Received: from DUZPR01CA0314.eurprd01.prod.exchangelabs.com (2603:10a6:10:4ba::21) by PAVPR08MB9308.eurprd08.prod.outlook.com (2603:10a6:102:303::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.12; Tue, 28 Jul 2026 15:18:17 +0000 Received: from DU2PEPF00028D01.eurprd03.prod.outlook.com (2603:10a6:10:4ba:cafe::ab) by DUZPR01CA0314.outlook.office365.com (2603:10a6:10:4ba::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.245.13 via Frontend Transport; Tue, 28 Jul 2026 15:18:17 +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 DU2PEPF00028D01.mail.protection.outlook.com (10.167.242.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Tue, 28 Jul 2026 15:18:17 +0000 Received: from AZ-NEU-EX03.Arm.com (10.240.25.137) 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; Tue, 28 Jul 2026 15:18:11 +0000 Received: from PF4S4363.arm.com (10.57.42.206) by mail.arm.com (10.240.25.137) with Microsoft SMTP Server id 15.2.2562.29 via Frontend Transport; Tue, 28 Jul 2026 15:18:10 +0000 From: Matthieu Longo To: CC: Luis Machado , Luis Machado , Thiago Jung Bauermann , Simon Marchi , "Kevin Buettner" , Christina Schimpe , Christina Joos , Matthieu Longo Subject: [PATCH v1 6/6] gdb/linux-tdep: remove legacy parse_smaps_data overload Date: Tue, 28 Jul 2026 16:17:00 +0100 Message-ID: <20260728151700.253720-7-matthieu.longo@arm.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260728151700.253720-1-matthieu.longo@arm.com> References: <20260728151700.253720-1-matthieu.longo@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DU2PEPF00028D01:EE_|PAVPR08MB9308:EE_|AM4PEPF00027A69:EE_|DB4PR08MB9359:EE_ X-MS-Office365-Filtering-Correlation-Id: 2bc35d75-0b2f-41b1-061c-08deecbb992f x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; ARA:13230040|376014|36860700016|23010399003|82310400026|1800799024|56012099006|11063799006|10067099003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info-Original: 39hH2wc72KQ3O2kbjTVneGtvT2pID8SRyLe7F1ZqZveTauKQwuAi6ZC82crmmOlvFnH9sAwrZrijqagqWsCCEBkkJa/io8Now9vdwVX/cAz33gQCjEBLNhyfpa1xiWtpfnzh4bK2/XnTVxvwV8IdK+UPctteUSfDrRC8UqbSZDa6bvAdjDmvNwbVC3pJGyW6cRRHlApVbZjQet1Y+F/Tfzz49MvuhN1EeP5qubdo6CdkMYX5hCf4PJ/bn/eeE+rZDwLP1CBnBE5T7O1sxDUgU/EQnDKymCAAefPeJ7pMXhU1IPi3mAurX/ijrvgCU+20b9LTT359xe/o14K8yi7zW0WvLo0Fm4dLWDH0S57nguLJjLjUoovVTP/qfkZdwFn+msVtcxP3rf/X2VmB4qqqD3lb+NEJbhvXdCnqe9NJZoK3nS19i1Bu6nNMySPFJF44zn8eyDTDzd5R6742ZNh97isLymaebI6op6387wfKdQPrQ9LaVI5VjHfZKDGHjo6mdqccH/MdTNMSQBYNXepJLVzLWnB/cA+DJ85VTZUs7VTaxhUTnOXiocZmwGoZNdBebgFnQDy+oY5jyCSvvRQQD9wnTsOrDXANPIx7GTSn07F6YyXd4ICJY5sEthipKCK/JpxsicBWhHDDn3nJYwZo3Qf4sd7TkYC78lf6WBzNhk+SGTb96gnTxZQrWKwmeYvoaBck7PMWMT+h2E8Qh2cZog== 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)(376014)(36860700016)(23010399003)(82310400026)(1800799024)(56012099006)(11063799006)(10067099003)(18002099003)(22082099003); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: q5GxQNgHKMxANI3nlTGsUdcGZ6xkptQTWeNYatd73BJppxfEYxxCnBs+luP+AW0u27s4LFxwjWxM7WvyTfygtE8uT54uOVkL7poaSdw2lghTjaMwPd1ITYIifLi5ZlvkL9p7hqI8fF6u6Fbh6O9jxkovewj2Me3X8dlyUw1D5M8xyyABkPc8F79uNLFZ1nzewzssUQAIxFQ/ExwJilDyHMIJzaG6DeAfqUZwTf2Y8Ic3kF/UiEwE3sQkRnhlKpICp66YHqwSwXb1YKsMv4JjmjAL50Ai0DOIFK4XQxpvivMfLaVbB/Iwrd48tumMjz2CeohIJ2II3FBl+cEtL2NB+A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR08MB9308 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM4PEPF00027A69.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: dace2330-948a-4356-024f-08deecbb7379 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|14060799003|1800799024|23010399003|35042699022|36860700016|82310400026|18002099003|56012099006|22082099003|10067099003|11063799006; X-Microsoft-Antispam-Message-Info: SyrMSizX2vn1aJS90nxROkyQahpB7/Q2tF/MdlUn3UkbxW8HFQL4rIF7wLpxv7q/aBxnmReTelBIT8Uh4Tjf8V5aRhVb0WiNWBbJpL/X7pfRqbpCAB86nAbmF/wKKLc2dcJ/zdvI2EEuJkqYpfs5JYbztBuJgG8ZqCP5Y2Uy4qrc9naQNzIhPtuHitlDHdZmK4xwPmlhxbFzEnvJPQ+gX8cT9EbS+Twyns9mqfBL831UiRsyt9heaPoFmL1EwYACsLeyxcjoqgl2WEC7e6E/K2VrNlCivOqi5ujeRnHNgekUgb8STUqaWV9TBO1rjvDeBJGeXRz6sZiyXlM4k7pD5A+dtXUqsjbl7X3XSJ74RgkErpkbOXGcWZ9A/hl7FtFhDZCktTqnTNSnxuNvI8x8j3y+l2EVWFtV2Im/iUWtU5VM+66SDOlNafPvY9L72DTwnBWbT3ehUkuu65NS4yC3UM0RC9R8Jh+Ob692hdsxtPlGEzGiAIdGPrMh2xNGhTD++n6ZBKYnC9oQRrqD9KvlmnYNiZFDLC+3joYWk/rM7uld/bIilEzkUhkNasYo72x6N+MqYoIaqiO68fMT6HVjQVo9w5vLT8arB+rblxJthwjabisGSUT8mx+8kaVuHv82saPpUhKMi98jk/RZDsmNfmkOXz1cz7AqfwXUaazGawrcKlrxJq6OiRIU9ApqTTHWHeoKwAlYTdqLDJUv2Ok7vg== 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)(376014)(14060799003)(1800799024)(23010399003)(35042699022)(36860700016)(82310400026)(18002099003)(56012099006)(22082099003)(10067099003)(11063799006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: T+zMZq0yD2LiqTOHSGQuiT3EKL2ciNeGXLXHCpip0QzUlpcoc6A97bZUIAhqhIJzE2m9zbWxhZYcXk1d8xu1Ea/CamaRsNLaanlhSIkn3tn1dnQQf1YLQ2oVdjNn7LUc7Qq3HhmDYVEpuCO5ZrpClZ3TtiFRG4jG1Vk5Aue2bJd/fjkjw/oN7+9W5tk9V9buc45g8k43RR8QWWgzDvyq13agVpxlPrhpFjp1SPkoIdVtW0soS7aIPAIK0RAdM1BtZDIGt+pAzUEMFJBMHdkQWJpo/tAk+/hunHRw51UkoCnoFE1Ip9e4M7QLMBIoMfouruH5Lv7N7Fuqh7wzUqoLtGNbpBCToIhwyQ5SCwq+9MvmQH4hjjfXujYIbXBeuH3165w14SzY8Ty+ZwBYV7smBz1XNORsSVz038eVJ6ZLduKOFwWDTgwHOLgEShFTSus8 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2026 15:19:20.5299 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2bc35d75-0b2f-41b1-061c-08deecbb992f 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: AM4PEPF00027A69.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR08MB9359 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org Now that all callers use the file_reader_t overload of parse_smaps_data, the legacy interface taking a raw buffer and filename separately is no longer needed. Fold its implementation into the file_reader_t version and remove the obsolete wrapper. This also simplifies the implementation by using the file_reader_t accessors directly. Reviewed-By: Thiago Jung Bauermann Reviewed-By: Luis Machado --- gdb/linux-tdep.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 628f73969d3..2e9cb14d5bf 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1582,18 +1582,17 @@ parse_smaps_key_value (const char *keyword, const char *line, /* Helper function to parse the contents of /proc//smaps into a data structure, for easy access. - DATA is the contents of the smaps file. The parsed contents are stored - into the SMAPS vector. */ + FREADER is a wrapper around the contents of the smaps file. + The parsed contents are stored into the SMAPS vector. */ static std::vector -parse_smaps_data (const char *data, - const std::string &maps_filename) +parse_smaps_data (const file_reader_t &freader) { char *line, *t; - gdb_assert (data != nullptr); + gdb_assert (freader); - line = strtok_r ((char *) data, "\n", &t); + line = strtok_r (freader.data (), "\n", &t); std::vector smaps; @@ -1649,8 +1648,8 @@ parse_smaps_data (const char *data, if (sscanf (line, "%64s", keyword) != 1) { - warning (_("Error parsing {s,}maps file '%s'"), - maps_filename.c_str ()); + warning (_("Error parsing keyword in {s,}maps file '%s'"), + freader.c_filepath ()); break; } @@ -1664,12 +1663,12 @@ parse_smaps_data (const char *data, decode_vmflags (line, &v); if (parse_smaps_key_value (keyword, line, "Rss:", - maps_filename, + freader.filepath (), &rss)) continue; if (parse_smaps_key_value (keyword, line, "Swap:", - maps_filename, + freader.filepath (), &swap)) continue; @@ -1680,8 +1679,9 @@ parse_smaps_data (const char *data, if (sscanf (line, "%*s%lu", &number) != 1) { - warning (_("Error parsing {s,}maps file '%s' number"), - maps_filename.c_str ()); + warning (_("Error parsing numeric value associated with " + "key '%s' in {s,}maps file '%s'"), + keyword, freader.c_filepath ()); break; } if (number > 0) @@ -1731,12 +1731,6 @@ parse_smaps_data (const char *data, return smaps; } -static std::vector -parse_smaps_data (const file_reader_t &freader) -{ - return parse_smaps_data (freader.data (), freader.filepath ()); -} - /* Helper that checks if an address is in a memory tag page for a live process. */