From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id cebGNy++aGqt1TEAWB0awg (envelope-from ) for ; Tue, 28 Jul 2026 10:35:27 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=doBTxqIW; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=doBTxqIW; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id DFAE51E09E; Tue, 28 Jul 2026 10:35:27 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id AD68B1E099 for ; Tue, 28 Jul 2026 10:35:26 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 776F44BB3BB1 for ; Tue, 28 Jul 2026 14:35:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 776F44BB3BB1 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=doBTxqIW; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=doBTxqIW Received: from GVXPR05CU001.outbound.protection.outlook.com (mail-swedencentralazlp170130007.outbound.protection.outlook.com [IPv6:2a01:111:f403:c202::7]) by sourceware.org (Postfix) with ESMTPS id 587034BB3B93 for ; Tue, 28 Jul 2026 14:34:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 587034BB3B93 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 587034BB3B93 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c202::7 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1785249294; cv=pass; b=m0bwghHwNyHnuMcwQfxtEavWDfldp90XKfZiXBeIPSBa4N2jWN6+cdZL++8XWSvup8CXgNpPA/i/Hz2glPlFtb0wEgBbNiUtrRFJKE7T9LDN588i/WTmQ1VwFLazxz8Gn8eXsLZXrBotvC61/5j0FnTuXEv42eIvqwQPs0IT7Fw= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1785249294; c=relaxed/simple; bh=mLZurhV8JbEe1EqQdYo1SUJ79VD9ElxMG2W+GRkDf/Q=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=f53zkHfgpe12e6ThLwfVTYjJSLAygOMuzm9nWpjJeZCWdTUg28dNmevxzdZL+MhHwS7wyPYcGTY7ptqu8ssBaw0IEpitq2P7VNMhsy8o13lRacdqN4wT8SXesxJc/F68xP489ixwffeW0eGSavR2Dcg7khB3+Hb6eA6LQ7zN0As= 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=doBTxqIW; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=doBTxqIW DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 587034BB3B93 ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=EWAb1yLPD9d5BytNJ/XuACmlhrMu4De0mSfK+nvvNgBwcuyuJ/3vr4biLXCZWDWZHb15ulc3RuxWYGZDnIRsGvdu9aTU7WaIoyNhaIdXkD5l/guYtmbOOMoiFkelHVm+FM0ubW//qZbxw0sQFvCSrDRDVMEMCCLqOGSWi6R8ryzJPORi+TSrntvVXE07gdnR6NqlPFz/346Pu/6ot9Sv228nORGkFcrWzN3z8VDuNMomxpaAVZKNxGoV8b/VYs84ZxrYPZQMfuu649ZWwluyI+rlq+i0NPyBgglYMjCr0wcNanRN4VQJLXCxK6f/OwVwU6dsG33yFRTTX7bAjFvT0A== 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=31wv7WMN3crYVwSQ/znipdg9TrvTV9qig3raWiFYfYU=; b=DQ3tvb0w3YJYOJZgOBzZswxPBXhjHtYpuSA1OumTxffycQGp2GkJbQO2INBmcL19Q0s54mCPpVI+8j9Lad2VqE68+ByqiW0nEk7zrCStwrINb9UZ7q3PWkvRmMIyReKY7bYgSneYTtc1bTJxlBPfDgcLEyzy2pWvx9KBR47nX9Z8r7IltwGnhBSfOGjp7VOUDFCdP29lr5kAb6JdZdw+NT5qqb6fjJNzRDx5IpDJL2OuYrEQrgLpJ49RLYXcBc5n4nqHNQDDcXANsvVMBsIGSOVtagp4d5+wCBFVQLIw2kSio8CCcoFditxEiWMbzZBMeDDA7zuW5IHZAjuy+IQWCA== 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=31wv7WMN3crYVwSQ/znipdg9TrvTV9qig3raWiFYfYU=; b=doBTxqIWf/GdRjuGI1abq1QcoZoOIhYeXi4i40fR27GITNI37MI9ifzSUDmfFD8Shvw+sCL4K87a1bBdg3lj3aOd3eFPc6jMNFl7xRD9zfJl3ZI74VmxgOvj29sWI3aNumZJQiYwwTgrz9GJ3Nt5QioZvgH2/UUkB8XdaPVUfaU= Received: from DU7P190CA0020.EURP190.PROD.OUTLOOK.COM (2603:10a6:10:550::34) by AM9PR08MB6068.eurprd08.prod.outlook.com (2603:10a6:20b:2dc::23) 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 14:34:51 +0000 Received: from DU2PEPF00028D05.eurprd03.prod.outlook.com (2603:10a6:10:550:cafe::2a) by DU7P190CA0020.outlook.office365.com (2603:10a6:10:550::34) 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 14:34:51 +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 DU2PEPF00028D05.mail.protection.outlook.com (10.167.242.165) 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 14:34:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CQjja2luVYKASEvLxw1WaGEZhV50UCYN8nbudaHeZxHkzgWJeJJJTHb+zJWreVDwxO2+2fYGjLT73Yfcc7GirXE+mTeLn7mVV0LYE8ZUX3uZNowmN2zXVKfDj8ZodY/Y7h3gdhP+ui8V/eelAfMu9cuKHGZeYqmJWe5uDQg8Du1qmR7gtle+14AemAGGOwLc9Q0kGAQmevPisXBXjO/LA74Ybrzc6E1/YWF9izQNt7pCAWin/X66zNbVTfpZl/FeqfLG0cwHxmnzmI+vx3kBfpxN95CPrkhSctmUZwUWmCwVgVCcmAoPszQdrB5VDPRZ3DrhF8moE80UeQFG+JMGrQ== 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=31wv7WMN3crYVwSQ/znipdg9TrvTV9qig3raWiFYfYU=; b=K69jmgDqihjM7Y9Cdx78LlZOWImgKKczokCup41uDgcyaUbFtNSFx+AgMwurEm9KeZM4WxfvyhDNmY7IIcEMUjD92wg1UIO9jHqpZdKanV81k25bqfzbyQJN98sMeRKhTwKwLgn/hZrZXRdVJOwOYFf0nBIdDtcTqz+vMjEzfpyFvtU9scCYTAO2lS8M5U0CPPkiAsiCd6GCdA+eBZyvk9wQJezeV8Ux6/lmwCs67MvUL4ZuaK9YjITl0xm2o0OIkGjOXLGeKJDxRHVLUrtrmEpG4mweEXN8MxxO19Ux3VJF+4MKLju4EMTyAtJtO7vkosPufG7DxXc8ITbmLhlF1Q== 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=31wv7WMN3crYVwSQ/znipdg9TrvTV9qig3raWiFYfYU=; b=doBTxqIWf/GdRjuGI1abq1QcoZoOIhYeXi4i40fR27GITNI37MI9ifzSUDmfFD8Shvw+sCL4K87a1bBdg3lj3aOd3eFPc6jMNFl7xRD9zfJl3ZI74VmxgOvj29sWI3aNumZJQiYwwTgrz9GJ3Nt5QioZvgH2/UUkB8XdaPVUfaU= Received: from DU7PR01CA0040.eurprd01.prod.exchangelabs.com (2603:10a6:10:50e::23) by AS8PR08MB6662.eurprd08.prod.outlook.com (2603:10a6:20b:397::19) 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 14:33:45 +0000 Received: from DB1PEPF00039233.eurprd03.prod.outlook.com (2603:10a6:10:50e:cafe::50) by DU7PR01CA0040.outlook.office365.com (2603:10a6:10:50e::23) 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 14:33:45 +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 DB1PEPF00039233.mail.protection.outlook.com (10.167.8.106) 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 14:33:45 +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 14:33:44 +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 14:33:44 +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 14:33:44 +0000 From: Matthieu Longo To: CC: Luis Machado , Luis Machado , Simon Marchi , "Thiago Jung Bauermann" , Matthieu Longo Subject: [PATCH v1 2/2] gdb: rely on the first non-exited thread TPID when reading Linux procfs files Date: Tue, 28 Jul 2026 15:33:17 +0100 Message-ID: <20260728143317.245389-3-matthieu.longo@arm.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260728143317.245389-1-matthieu.longo@arm.com> References: <20260728143317.245389-1-matthieu.longo@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DB1PEPF00039233:EE_|AS8PR08MB6662:EE_|DU2PEPF00028D05:EE_|AM9PR08MB6068:EE_ X-MS-Office365-Filtering-Correlation-Id: b403b60d-d7db-436b-aea4-08deecb561e7 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|23010399003|376014|10067099003|6133799003|5023799004|11063799006|56012099006|18002099003|3023799007|22082099003|13003099007; X-Microsoft-Antispam-Message-Info-Original: YHDPCZx86bP3JHVGufDYrrTTVOrDiLta0HrJ0WAvgKMyBa3myz98o+nN0416gkR7P8VC4MSPPwtpNy6vPz54GDiOtUtIwatXGM8xuXgmlYmQtGOdz8/bzVE9TnJ9WRomBcP6hs6hKySJEnfBs0O7xj2q/sN5N4XdLTlTK/lly5GGl/gbqojjK/uycrIWdrRsiT1tIG01PLLQMEhqPoXiDdEErhX8nVuD0e1bVHg4iN3U6I03X/hNCWD9WFCXEpVFIIxSB/JbU7uzRQcjw71M+jSzeL569q0jRRNdDERr9hM7VQahvYKzGJ7yRrhpoT5V8Jd6XLEGbRDNKMkKqBUHKcWXLE768C/nW26uRWOkIiCA2HTTb+PRcGdswyRRjcIRkyox1sEI+uZnZ43RcUPYHnAToiotexWF9/aOjXPkyyYh+XA7bzGZLoEkNc6PsrqzOJN4PHuXtKaNSLQ/WJzI7bXTC1buerI3y/4WirYIsAyDx8B4cuv5cHV3lBVbxi5rSpy9shbdbU/6/cMrwyJ7qcB2RZf22lXFIa0A3g8spvFfmHnFihSfpPvywg+Ea8P62kBEzwEGlyBO6TFoVn4/hJxkkenXfgfpUC+0UEe1sj8bW7xgPqAxumhyp0skS4+SLVBHGbCRyXUvqR2ELQpO3lBeHLItVVHsV87dx41i2HKkR+0nu3Jpmc2C2wIMkpm6N3/sEA8TNjjcOBMxYCg5ZQ== 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)(23010399003)(376014)(10067099003)(6133799003)(5023799004)(11063799006)(56012099006)(18002099003)(3023799007)(22082099003)(13003099007); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: WoXd4t6H7cN4t4hDJ1zRHIMD3P1Hpim14ZUmjQjio5N/MNj35FXJVDbbs7+cdOO2Je+0BblGRy7hgVCH0rLs7BRxInsjl2vxWmdm0PLOaJGBv9xoPJhIHFdlg6z84b86/Tmvynf6XYUQi/8kHDVt6EVfzYjPvHgU61SMnQsVkAGB+kS6MtdCNC0gl1NhHTmGid8rHUhZhj+QPznRkKoZs67Yk/Tc8f2qN1mL8f5UnIKaH2DKlANz7IUx8DnpH7CfylcjbvvEjuJxachhQkeJEx2V5Uf1Yq7XWCuyDoPVBikBpGMXjORzC0kCBCEa+lKBlz+IGGVmO88x3kb32UW4Ew== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6662 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DU2PEPF00028D05.eurprd03.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 0396d468-5630-4a43-2343-08deecb53aff X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|14060799003|23010399003|82310400026|35042699022|36860700016|13003099007|6133799003|22082099003|18002099003|5023799004|11063799006|56012099006|3023799007|10067099003; X-Microsoft-Antispam-Message-Info: UY3QKNeo6JntmlVnKYZWTsPHzUWIte0DzknIqPdoIWQVxb5727VBgNEZtK7Qe4M/gNjPfayqYVkn87XBrFz24oudaxIzGYwc3lFVV4Ri6he9gQfzpXs8uhpb2HgEffJPOMyOgKS4PUz19f4s0ckyAlbBJ8JwoiwNVhPQs0beE0ADup1ywERoYRkb7A9/EgvUbP9V+/neR9WrMNtUNbhSaW8xy7PRsVQvE9meRctCSln/PfUfXKvmzCGCdjbxRtfTNHh7wA2r3fWLC06IiYdp2jowLloE8GHRq/96VPh+okgemxyqEHmG+UI3R39cRaL600K/xFXLIwTjhLeE9M9ekRKBeMGp3Lx0ZhUCHh3cAwXhbZgiHV2FQQElvV3lDCyVeK3dJwvK+yqdcKHWyENpUrKOPuhnRHBRiBKd/Zj0gS71pxsGjaB6Z+LRb7arpqkD6FslUde8hBpsyh1PgVu8MeCV9aVfzraX2Yhiq19UYSUZ68jITUuR4DdrsomWnCZxdQA8HgcPJP66lJLH0qzK9ZcPoAz90Kv2Eg/RRygGFv2ul1SDk1W3fdNiSqbS7c5oGznOOhRwUbVMA9lPQoL4lzAr7AM1f8jjXKLLJpEf/pDaa6NGZfSAKMTtB+Xblhi7+rjg9EvNbPHd5tcVXlrXGHHwMg46yfBmgiGG7Nrx6anwsNZyDGgKUi6i17Fb2p/YoVZMcMlBNH5JuqH/Fjke9g== 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)(376014)(14060799003)(23010399003)(82310400026)(35042699022)(36860700016)(13003099007)(6133799003)(22082099003)(18002099003)(5023799004)(11063799006)(56012099006)(3023799007)(10067099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: amjlC4uHxCBB3x1w8llZmoKIJ6J+7BaI9vi1b57DP5EA4yScKklnTw64wiIP0PMx1cqrRy2NJvYIcfZaLjyrobw3lab2aVpBAZEHuKaouYtYkmDlYT/1W0/HG216NwURQcnij46X+68uTSwgq2SNUEJcYpLL4UNbT80c8CGHLsY+u7ygXcgPW0pXWbxoIgzqDSApJyfKATKPWmNDrrUkXXQdH7HpjuGIH8c2foG4MFPRWBh9LSh4PD+VYux0B7IyuX48lYmfeqF1Tjly45M1qoSK2/oV5ly2t0jIBnte7Wbbfootp2vAiPELyfo1zF2R5b5hJojs3D/yEyuwrmZMt6NqCxRgrjWBpdr45CYkhvDMPFnR72HRwP/AfKXtw8OKzGZ4C7F5mUiokwFgvbKBikAqxZnOkK2zxpUolPADAcJg537djYnlGmX8Aq2tVapL X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2026 14:34:50.7932 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b403b60d-d7db-436b-aea4-08deecb561e7 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: DU2PEPF00028D05.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6068 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On Linux, /proc/ is keyed by the thread-group leader PID. When the leader has exited, some /proc//... entries become unavailable even though another thread is still alive. This can happen, for instance, when the main thread calls pthread_exit() and another thread continues the execution (existing test: gcore-stale-thread). This causes GDB to fail to read procfs entries such as cmdline, cwd, exe, maps, and smaps when it uses 'current_inferior ()->pid' after the thread-group leader has exited. Fix this by adding inferior::first_non_exited_thread(), which returns the PTID of the first non-exited thread of the inferior. Use its LWP ID when accessing procfs entries that only need a representative live LWP belonging to the process. This is a best-effort choice of a thread that is expected to still exist in the target. Since GDB's view of the threads list may be stale, the selected thread may already have exited by the time it is accessed. Callers must therefore still be prepared to handle that case. Update the following functions: - linux_info_proc - linux_process_address_in_memtag_page - linux_find_memory_regions_full - linux_fill_prpsinfo - linux_address_in_shadow_stack_mem_range to use the first non-exited thread's LWP ID instead of the inferior PID when constructing procfs paths. Add a new test in gdb.threads. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31207 --- gdb/inferior.c | 12 +++ gdb/inferior.h | 11 +++ gdb/linux-tdep.c | 90 +++++++++++++------ ...access-procfs-while-thread-leader-exited.c | 48 ++++++++++ ...cess-procfs-while-thread-leader-exited.exp | 78 ++++++++++++++++ 5 files changed, 211 insertions(+), 28 deletions(-) create mode 100644 gdb/testsuite/gdb.threads/access-procfs-while-thread-leader-exited.c create mode 100644 gdb/testsuite/gdb.threads/access-procfs-while-thread-leader-exited.exp diff --git a/gdb/inferior.c b/gdb/inferior.c index ac8c4354b71..b4a9de51e5f 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -250,6 +250,18 @@ inferior::find_thread (ptid_t ptid) /* See inferior.h. */ +ptid_t +inferior::first_non_exited_thread () const +{ + auto it = this->ptid_thread_map.cbegin (); + if (it != this->ptid_thread_map.cend ()) + return it->first; + else + return ptid_t::make_null (); +} + +/* See inferior.h. */ + void inferior::clear_thread_list () { diff --git a/gdb/inferior.h b/gdb/inferior.h index 5c7a52319e7..91dc4e636fd 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -513,6 +513,17 @@ class inferior : public refcounted_object, /* Find (non-exited) thread PTID of this inferior. */ thread_info *find_thread (ptid_t ptid); + /* Return the first non-exited thread of this inferior. + + This is only a best-effort choice of a thread that is expected to still + exist in the target. A thread may have exited after GDB last updated its + thread list, or GDB/gdbserver may have observed the exit but not yet + propagated it through all layers. Therefore the returned thread is not + guaranteed to still be alive when it is later accessed. This avoids the + common case where the current thread has exited, but callers must still be + prepared for the selected thread to no longer exist. */ + ptid_t first_non_exited_thread () const; + /* Delete all threads in the thread list, silently. */ void clear_thread_list (); diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 8c53ffd5e89..9bdcc55a0e1 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -457,6 +457,44 @@ linux_has_shared_address_space (struct gdbarch *gdbarch) return linux_is_uclinux (); } +/* Return a PTID that identifies the current process and can be used to + access procfs safely. + + The returned PTID is that of the thread-group leader whenever it is + still alive. If the leader has already exited, the PTID of the first + non-exited thread in the current inferior is returned instead. + This ensures that the returned PTID always refers to a live thread + whose procfs entries are present and populated. */ +static ptid_t +get_process_reference_ptid (bool verbose = false) +{ + /* Get the current thread. */ + thread_info *thr = inferior_thread (); + + /* Construct the PTID of the thread-group leader. On Linux, + the leader's LWP ID is equal to the process ID. */ + ptid_t leader_ptid (thr->ptid.pid (), thr->ptid.pid ()); + + /* Use the thread-group leader if it is still alive. Otherwise, use + the first thread that has not exited. */ + thread_info *leader_thr + = current_inferior ()->find_thread (leader_ptid); + ptid_t ptid = (leader_thr == nullptr + ? current_inferior ()->first_non_exited_thread () + : leader_ptid); + + if (!verbose) + return ptid; + + if (leader_thr != nullptr) + gdb_printf (_("process %d\n"), leader_ptid.pid ()); + else + gdb_printf (_("process %d [Note: information where gathered from LWP %ld " \ + "as the thread-group leader (LWP=%ld) already exited.]\n"), + ptid.pid (), ptid.lwp (), leader_ptid.lwp ()); + return ptid; +} + /* This is how we want PTIDs from core files to be printed. */ static std::string @@ -842,9 +880,7 @@ static void linux_info_proc (struct gdbarch *gdbarch, const char *args, enum info_proc_what what) { - /* A long is used for pid instead of an int to avoid a loss of precision - compiler warning from the output of strtoul. */ - long pid; + ptid_t ptid; int cmdline_f = (what == IP_MINIMAL || what == IP_CMDLINE || what == IP_ALL); int cwd_f = (what == IP_MINIMAL || what == IP_CWD || what == IP_ALL); int environ_f = (what == IP_ENVIRON || what == IP_ALL); @@ -859,7 +895,8 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, { char *tem; - pid = strtoul (args, &tem, 10); + long pid = strtoul (args, &tem, 10); + ptid = ptid_t (pid, pid); args = tem; } else @@ -869,17 +906,16 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, if (current_inferior ()->fake_pid_p) error (_("Can't determine the current process's PID: you must name one.")); - pid = current_inferior ()->pid; + ptid = get_process_reference_ptid (true); } args = skip_spaces (args); if (args && args[0]) error (_("Too many parameters: %s"), args); - gdb_printf (_("process %ld\n"), pid); if (cmdline_f) { - xsnprintf (filename, sizeof filename, "/proc/%ld/cmdline", pid); + xsnprintf (filename, sizeof filename, "/proc/%ld/cmdline", ptid.lwp ()); gdb_byte *buffer; LONGEST len = target_fileio_read_alloc (nullptr, filename, &buffer); @@ -901,7 +937,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, } if (cwd_f) { - xsnprintf (filename, sizeof filename, "/proc/%ld/cwd", pid); + xsnprintf (filename, sizeof filename, "/proc/%ld/cwd", ptid.lwp ()); std::optional contents = target_fileio_readlink (NULL, filename, &target_errno); if (contents.has_value ()) @@ -911,7 +947,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, } if (environ_f) { - xsnprintf (filename, sizeof filename, "/proc/%ld/environ", pid); + xsnprintf (filename, sizeof filename, "/proc/%ld/environ", ptid.lwp ()); gdb_byte *buffer; LONGEST len = target_fileio_read_alloc (nullptr, filename, &buffer); @@ -935,7 +971,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, } if (exe_f) { - xsnprintf (filename, sizeof filename, "/proc/%ld/exe", pid); + xsnprintf (filename, sizeof filename, "/proc/%ld/exe", ptid.lwp ()); std::optional contents = target_fileio_readlink (NULL, filename, &target_errno); if (contents.has_value ()) @@ -945,7 +981,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, } if (mappings_f) { - xsnprintf (filename, sizeof filename, "/proc/%ld/maps", pid); + xsnprintf (filename, sizeof filename, "/proc/%ld/maps", ptid.lwp ()); gdb::unique_xmalloc_ptr map = target_fileio_read_stralloc (NULL, filename); if (map != NULL) @@ -990,7 +1026,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, } if (status_f) { - xsnprintf (filename, sizeof filename, "/proc/%ld/status", pid); + xsnprintf (filename, sizeof filename, "/proc/%ld/status", ptid.lwp ()); gdb::unique_xmalloc_ptr status = target_fileio_read_stralloc (NULL, filename); if (status) @@ -1000,7 +1036,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, } if (stat_f) { - xsnprintf (filename, sizeof filename, "/proc/%ld/stat", pid); + xsnprintf (filename, sizeof filename, "/proc/%ld/stat", ptid.lwp ()); gdb::unique_xmalloc_ptr statstr = target_fileio_read_stralloc (NULL, filename); if (statstr) @@ -1671,9 +1707,9 @@ linux_process_address_in_memtag_page (CORE_ADDR address) if (current_inferior ()->fake_pid_p) return false; - pid_t pid = current_inferior ()->pid; + ptid_t ptid = get_process_reference_ptid (); - std::string smaps_file = string_printf ("/proc/%d/smaps", pid); + 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 ()); @@ -1731,7 +1767,6 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, linux_dump_mapping_p_ftype *should_dump_mapping_p, linux_find_memory_region_ftype func) { - pid_t pid; /* Default dump behavior of coredump_filter (0x33), according to Documentation/filesystems/proc.txt from the Linux kernel tree. */ @@ -1744,12 +1779,12 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, if (current_inferior ()->fake_pid_p) return false; - pid = current_inferior ()->pid; + ptid_t ptid = get_process_reference_ptid (); if (use_coredump_filter) { std::string core_dump_filter_name - = string_printf ("/proc/%d/coredump_filter", pid); + = string_printf ("/proc/%ld/coredump_filter", ptid.lwp ()); gdb::unique_xmalloc_ptr coredumpfilterdata = target_fileio_read_stralloc (NULL, core_dump_filter_name.c_str ()); @@ -1763,7 +1798,7 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, } } - std::string maps_filename = string_printf ("/proc/%d/smaps", pid); + 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 ()); @@ -1771,7 +1806,7 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, if (data == NULL) { /* Older Linux kernels did not support /proc/PID/smaps. */ - maps_filename = string_printf ("/proc/%d/maps", pid); + maps_filename = string_printf ("/proc/%ld/maps", ptid.lwp ()); data = target_fileio_read_stralloc (NULL, maps_filename.c_str ()); if (data == nullptr) @@ -2275,7 +2310,7 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) /* The state of the process. */ char pr_sname; /* The PID of the program which generated the corefile. */ - pid_t pid; + ptid_t ptid = get_process_reference_ptid (); /* Process flags. */ unsigned int pr_flag; /* Process nice value. */ @@ -2286,8 +2321,7 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) gdb_assert (p != nullptr); /* Obtaining PID and filename. */ - pid = inferior_ptid.pid (); - xsnprintf (filename, sizeof (filename), "/proc/%d/cmdline", (int) pid); + 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); @@ -2310,7 +2344,7 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) memset (p, 0, sizeof (*p)); /* Defining the PID. */ - p->pr_pid = pid; + p->pr_pid = ptid.pid (); /* Copying the program name. Only the basename matters. */ basename = lbasename (fname.get ()); @@ -2327,7 +2361,7 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) strncpy (p->pr_psargs, psargs.c_str (), sizeof (p->pr_psargs) - 1); p->pr_psargs[sizeof (p->pr_psargs) - 1] = '\0'; - xsnprintf (filename, sizeof (filename), "/proc/%d/stat", (int) pid); + 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); @@ -2405,7 +2439,7 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) /* Finally, obtaining the UID and GID. For that, we read and parse the contents of the `/proc/PID/status' file. */ - xsnprintf (filename, sizeof (filename), "/proc/%d/status", (int) pid); + 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); @@ -3206,9 +3240,9 @@ linux_address_in_shadow_stack_mem_range if (!target_has_execution () || current_inferior ()->fake_pid_p) return false; - const int pid = current_inferior ()->pid; + ptid_t ptid = get_process_reference_ptid (); - std::string smaps_file = string_printf ("/proc/%d/smaps", pid); + 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 ()); diff --git a/gdb/testsuite/gdb.threads/access-procfs-while-thread-leader-exited.c b/gdb/testsuite/gdb.threads/access-procfs-while-thread-leader-exited.c new file mode 100644 index 00000000000..0686b746c06 --- /dev/null +++ b/gdb/testsuite/gdb.threads/access-procfs-while-thread-leader-exited.c @@ -0,0 +1,48 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2026 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include +#include + +static pthread_t main_thread; + +static void * +start (void *arg) +{ + int i; + + i = pthread_join (main_thread, NULL); + assert (i == 0); + + return arg; /* break-here */ +} + +int +main (void) +{ + pthread_t thread; + int i; + + main_thread = pthread_self (); + + i = pthread_create (&thread, NULL, start, NULL); + assert (i == 0); + + pthread_exit (NULL); + assert (0); + return 0; +} diff --git a/gdb/testsuite/gdb.threads/access-procfs-while-thread-leader-exited.exp b/gdb/testsuite/gdb.threads/access-procfs-while-thread-leader-exited.exp new file mode 100644 index 00000000000..e84953dfc29 --- /dev/null +++ b/gdb/testsuite/gdb.threads/access-procfs-while-thread-leader-exited.exp @@ -0,0 +1,78 @@ +# Copyright 2026 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +standard_testfile +set corefile [standard_output_file ${testfile}.core] + +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != ""} { + return +} + +clean_restart ${testfile} + +gdb_test_no_output "set non-stop on" + +if {![runto_main]} { + return +} + +gdb_test_multiple "info threads" "threads are supported" { + -re ".* main .*\r\n$gdb_prompt $" { + # OK, threads are supported. + } + -re "\r\n$gdb_prompt $" { + unsupported "gdb does not support threads on this target" + return + } +} + +gdb_breakpoint ${srcfile}:[gdb_get_line_number "break-here"] +# gdb_continue_to_breakpoint does not work as it uses "$gdb_prompt $" regex +# which does not work due to the output: (gdb) [Thread ... exited] +set name "continue to breakpoint: break-here" +gdb_test_multiple "continue" $name { + -re "Breakpoint .* (at|in) .* break-here .*\r\n$gdb_prompt " { + pass $name + } +} + +set test "info proc" +set fail_re \ + [multi_line \ + "process $decimal" \ + "warning: unable to open /proc file '/proc/$decimal/cmdline'" \ + "warning: unable to read link '/proc/$decimal/cwd'" \ + "warning: unable to read link '/proc/$decimal/exe'"] +set pass_re \ + [multi_line \ + "process $decimal \\\[Note: information where gathered from LWP $decimal as the thread-group leader \\(LWP=$decimal\\) already exited\\.\\\]" \ + "cmdline = '$binfile'" \ + "cwd = '.+'" \ + "exe = '$binfile'"] + +gdb_test_multiple "$test" $test { + -re -wrap $fail_re { + fail $test + } + -re -wrap $pass_re { + pass $test + } +} + +# Do not run "info threads" before "gcore" as it could workaround the bug +# by discarding non-current exited threads. +gdb_test "info threads" \ + {The current thread has terminated\. See `help thread'\.} \ + "exited thread is current due to non-stop" -- 2.55.0