From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Ia/sEY1jjGrNnDwAWB0awg (envelope-from ) for ; Mon, 24 Aug 2026 11:30:21 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=MTn0GoJj; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=MTn0GoJj; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 425881E0A3; Mon, 24 Aug 2026 11:30:21 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-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 75A7A1E033 for ; Mon, 24 Aug 2026 11:30:20 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 444864B9DB72 for ; Mon, 24 Aug 2026 15:30:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 444864B9DB72 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=MTn0GoJj; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=MTn0GoJj 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 8E0A54BA9033 for ; Mon, 24 Aug 2026 15:29:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E0A54BA9033 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 8E0A54BA9033 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=1787585391; cv=pass; b=fXr65PRt/Er8aeRvd890K2pzK7TZpXwvo1++4h2to5nluJ3UXGlYwxfRXbAcFPi7zfxrRpkGW8ksYRtTpFpTNfVujfB7/CDwU7J3jUpw/H1meeySA+29JMCqGM0QJHyidbQ3MBeCa7WzuoT/piXcx5bPa4yipVuwgVHI0Vg/YpA= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1787585391; c=relaxed/simple; bh=8BuIGOUJuDaiq7wLd169TqI03aF93bj1s6fwj0B0EyY=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:Subject:To:From: MIME-Version; b=MvqtA15tOQWKcgfjXI+5Mswk1ipi55vZ6ToKFZkPhvfrAZ9wwQ143t3ABRXCG1FCkB+ZM3tlXxReZDRu9RL7Vw3vTgPXUhJ2s8Rxlt0IGV5OIxslVrrLba7OGSKYhCOorkrcogtKjqRrqb5+9xJZ18sSdtgb1bABWVytuWceO7w= 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=MTn0GoJj; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=MTn0GoJj DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E0A54BA9033 ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=hU6Ynu6myKnTUKy2iMeFg+wCqUn9FBju6CnnNcqSoV5M+D1tRpwdu4fBqjpksANB+ZmAsmnwNctZw54RT+1/x1jF1ycxTgLIDShXfMUWAgRkrR1SxTKePhdRKx+1j8DDoZw0trIPxPbxyjtzfI8AY/ezbflgFRCrHX3izEADg36c44ycKg1r+OLhMQUXLpSOp56CVQnXcB774IdBGU9QajeJDpCRU2Xbecqd2YDx+bqTnetP+hifi7KvUFOm13Sh98cTK8E8TOteThe0kOk/JVT0h+ZF+kMxFOeSArn0B7V/YI6A06L36Gt1KzSLoDFLc21Hp/W7fuT4T0nCARHMfQ== 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=+zdggE9kFSqMTmxinKC+rjXCADNVwuHqFWuFrfqttiw=; b=I60MA5B738mnQAoQhxgpsTy0hRZOKHRW+JuEOdiDTvO3Y5UoF+bYwNMEgOUT/iWV68lNxPFojvNFVwvCwcFpOea+T0VmumEsnShGxFkeNkSgVD2AIZ4JnptA/KY3PCZN9t5jXj3PGimiMuIkA2hR8cZuwsTlGfuKkC2hWzVvVH1cPhnRK8F1riIVIpqjkTXc/s6pWQjdyAM291C0X8AHfEia4C9NLk5zbdZWmDMhRHMvAVSvdGY1KMXd0kwSlA388ayNOHADmvT5mpTs4MTYwsap3PjdGoAzyK0zDUQJe4vIvzFoCp5CjkP5zf0poMXKAzn6QjP/7V+gdECtK7Z/mg== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 4.158.2.129) smtp.rcpttodomain=simark.ca 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] dkim=[1,1,header.d=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=+zdggE9kFSqMTmxinKC+rjXCADNVwuHqFWuFrfqttiw=; b=MTn0GoJj2fayQK0QYEwYrXfMFGYAP7+Mig8GJSg5hdbihHORpZ3eXSSAnti05tamMdI+XebZUGp/JB9u2Uu8l0L+12LhIHeYElhGRPsTeZqaCaz0wgp6PRojmFROorMzFBu1zg7szs9idyU/O3Nk3IXYBk0TFWtWDT//oPIeBhk= Received: from AM7PR02CA0018.eurprd02.prod.outlook.com (2603:10a6:20b:100::28) by AS8PR08MB8221.eurprd08.prod.outlook.com (2603:10a6:20b:524::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.339.12; Mon, 24 Aug 2026 15:29:46 +0000 Received: from DU6PEPF0000A7E4.eurprd02.prod.outlook.com (2603:10a6:20b:100:cafe::74) by AM7PR02CA0018.outlook.office365.com (2603:10a6:20b:100::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.339.12 via Frontend Transport; Mon, 24 Aug 2026 15:29:46 +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 DU6PEPF0000A7E4.mail.protection.outlook.com (10.167.8.43) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.360.3 via Frontend Transport; Mon, 24 Aug 2026 15:29:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KD0d1uAhw6mZoQxLknsDwV3VwtaGphfjXrBxvMydJbFYv5c2un+D5IVWWK0JmBW7hlyryRU60bKY4Q8V9zUc9RgrjTcSZwM5eV546dsr/YWOQdvraXmJHAaWks225ETGyeebjeUP38T3O9RTHjt3I270Tpx75SewIYREXJeDBoImp2xcKLeP7TEVkZa6VE8OJ2+FPTaoXmN8ZTbSg2oMu160TK3n53aBdY4qpIjui7DTh9TxS5pL7n67vFtMOMfy32mah7nxDGGb7d8cSyuAqc9Gkc1LT6uMhnbRcFnSWWN/9w5/57NP/ZR7hEpTMnzThRnZ/mz2xA20hPoZLkykSw== 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=+zdggE9kFSqMTmxinKC+rjXCADNVwuHqFWuFrfqttiw=; b=p/kZF0FKYKt5590AF8COmonFkVWfIU9AqgDG+tstiIYLUtzqJ2+aQ7KbgJBlh22czufJXP9KI1ouxzDjAGxHv/O4nONAr76Kxwl1CvDb4HKS7veweiBpLUbOH8lJzYOXGLuU4+rkUo7hW5RGUwAq5PEArl0HnXZMzy4wydYwNn9asJDWpb3h+DoRCPSUdJSCZMH6arkIkeagFZr9JLuJEIrTDm0/OrQkfBa4oLuSOn7WgzVawyxMiv6RVg+U6MoMR2paryWROLhMUpD2rTZ2+yzSMku682jN64PeIEXogVcy2Yu1EwNhv1bnAVo4A43BYJebCx19dL1CISQ+Y4tZUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none 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=+zdggE9kFSqMTmxinKC+rjXCADNVwuHqFWuFrfqttiw=; b=MTn0GoJj2fayQK0QYEwYrXfMFGYAP7+Mig8GJSg5hdbihHORpZ3eXSSAnti05tamMdI+XebZUGp/JB9u2Uu8l0L+12LhIHeYElhGRPsTeZqaCaz0wgp6PRojmFROorMzFBu1zg7szs9idyU/O3Nk3IXYBk0TFWtWDT//oPIeBhk= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AS8PR08MB8659.eurprd08.prod.outlook.com (2603:10a6:20b:563::10) by AS8PR08MB9362.eurprd08.prod.outlook.com (2603:10a6:20b:5a9::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.339.12; Mon, 24 Aug 2026 15:29:12 +0000 Received: from AS8PR08MB8659.eurprd08.prod.outlook.com ([fe80::96bf:2de3:5eab:70ae]) by AS8PR08MB8659.eurprd08.prod.outlook.com ([fe80::96bf:2de3:5eab:70ae%5]) with mapi id 15.21.0339.012; Mon, 24 Aug 2026 15:29:11 +0000 Message-ID: <8c4fa73b-5a34-4365-9662-08ca3702c3bd@arm.com> Date: Mon, 24 Aug 2026 16:29:10 +0100 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 2/2] gdb: rely on the first non-exited thread TPID when reading Linux procfs files To: Simon Marchi , gdb-patches@sourceware.org Cc: Luis Machado , Luis Machado , Thiago Jung Bauermann References: <20260728143317.245389-1-matthieu.longo@arm.com> <20260728143317.245389-3-matthieu.longo@arm.com> Content-Language: en-US From: Matthieu Longo In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P123CA0399.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:189::8) To AS8PR08MB8659.eurprd08.prod.outlook.com (2603:10a6:20b:563::10) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AS8PR08MB8659:EE_|AS8PR08MB9362:EE_|DU6PEPF0000A7E4:EE_|AS8PR08MB8221:EE_ X-MS-Office365-Filtering-Correlation-Id: 1379afe7-3c74-48c2-fb98-08df01f486dc x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; ARA:13230040|366016|23010399003|376014|1800799024|10067099003|18002099003|22082099003|4143699003|11063799006|56012099006; X-Microsoft-Antispam-Message-Info-Original: UYd1TuPzG38MDY7hQLrW6NJn6CSCtv9MJjSrsJgppLqjcsdbHFnqn3pOLFzrEBJvAUu4T1dLC7b+BbxS7q/ladSxF7fupQgk9Dx4YzTfdlFriLsXqT+rIhyeMQOSqQ7hrAJVHiT1gXg2vpSD34d7tRnXdO5jz8f6jNnlJSDbMdlcR7o4L8F48D6VK1MQ3YG6Dy2eFQbpFnxIsPcU23/8la7oDGGBDLWWLryvdnWNHosQ3CFWDjQ7R8yxmHlqLZdxTYkMZx72xblqaENVqn/gClaU0peDNryvgkASTGNQeQI3J7E2KBvLk7KrXpgy6Z9DeAfJ/qlaqvR8O5cJHvWVcvuOMFtb0ZkVDkXB/Sme/pNFCXNdgPPP518UfgMpedOUFAHULHXpledkZipH6S/SWo80yYG4+BXdKhtmqKy3PK+vzG0qkjY2i4Cn8qRqqhZ0KMFEWxYn48II1yirmlBuNj1NvPweCRN4ZRzsOdGkk6lp9wUT6PyP7wcpgKYX0URZzJNdSuj6bKRisPEbPT65qvIX7vgVU1a778x+toeiRBR0LiLjZygsOdSyL/BIvSZP1f59/QJPX/8WdLMXl89WFp95GZRjhsKt0/G2lnGP8rD+Y/9oVHvhPHwdWQPc9xF4DlzWWGu9be3eOjjfCazr7q9ciqPMKw18cpoOkHMJ4G8= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB8659.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(23010399003)(376014)(1800799024)(10067099003)(18002099003)(22082099003)(4143699003)(11063799006)(56012099006); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: Oaw8LHN19mxL96lai9BRllxI1O6kwvWRvgf7lpbZEZ1/1tQ7rZllm6qRyVGgmQhxKH+OwKBlvPiY7r065JH5A/7D8sVasLLjswA1ZyixSrFY8qZedgslMagIryuTh8yV+QdOXkmEpfHaBPkjScGsS43cGuUMum7/4P/2dRX2dXF3lAsv+BVM0l//rm6p/1ZIc/c/SOsZ7xPhI6sLSzK0HR3YvEKslWkhsXO5j1at1Ksg+/zTsRHxYPj+PEn93Tts6C0FYHqEc0YRXqm4t082eXkp/japvildOg26/tWI9vGQhmWrTkfFfdJYCWm0+oYIxVsIeACRDm8IbCryPFgETg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9362 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DU6PEPF0000A7E4.eurprd02.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: d5e696d9-0672-4cda-5f66-08df01f47289 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700016|376014|23010399003|1800799024|14060799003|35042699022|10067099003|56012099006|11063799006|4143699003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: ZYN0Is/Vq8h8nAnHkmRLMboIXFz/PZjVKkUwlxo8FF0XFWq1d7EpH2zlGuSvHY74MXdGbCusGnDUBNOChSckeHGyG/y+PqywJt+Jadrn87TEPZ7LKOLfVb9e+Whm3ryhWSK+cowAfvmCJRjmjSOzoYvwq/GI/Y2PMPL5PUJ66MVzZXm8xTSlY7toyKNZB36QvrBLkEcaUjaGJ0MABm0Xrx0Vos6CEC5mAXMnom41UnfkM+u27ZAvSZRQDosQbdeew/r1alzZySR0K8QE3JoK8mTCWyiowCieRQT4A+uq6BD8ikCXMDPCs7Qw4LTO2QdNwNUZk1fBE0OV/nRlI/oTlbRoGJfgVe/B2y4bqsXAcP9h+XhpU5RDMAG+0UjIGrZchdsV145ey32icyv69o03d65c4rGPQ99N4klVgPpDyvZPPKh1+EeKaLGr19/C0cRLuvM9LRPOjOrhR1Pne66KVJ3SeEJo9dGGIvcdxUW0/Do4kjI/UeaX/aphN63ByYGQuJoboetWTTxdjqzGzqq89WQFwi4xug2ILQ84+7AmzVdiCo+yG82f3sDV0XaO3SX54H47NGezyB0aFRNFMflas3kooszrrYQWkyz1qMeFB2tCytMWWMfWqLlApFz4eI+qeBiO0k5xnJFnhjBQHkheurJnJhpuLqt3k7c1QIATQD7I+2WsTZYhYe4cPLcNbSDboaXjyWEGjpTgcRvIu2JmHw== 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)(36860700016)(376014)(23010399003)(1800799024)(14060799003)(35042699022)(10067099003)(56012099006)(11063799006)(4143699003)(22082099003)(18002099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: h5RosBS7u+BfAZRVS/19xRFN7j9P5YFsNYCoPzCu3g8EFM+R9pDU59zQrp6M2wrs+30jzGP+NenWIzA/DDpnaXcKP8/bYCaZzu013rq0Y8vVrU043RZ5dAmv4hUUdxcTko7qBmtI+7ZnQHRkaURQegH6d4YiLLud78vAKVw0E9kJUMhq62X+V/SLf9/P0BDxjknGD2kj1G/+vXHcuckMSG23KV4T39q9liOVktNPBf/mKNiOhhgZuuNvQPEAvrcvmcA/b4KTWeI3k+04V7AYowgaMMpDaUHR1/vAzOlfWPuyID2IvUMc8uJ+/6Aab/6pUTSD14C3AXs+LJ2Sth0gZ752FuXLQUOBWmWsJ7Z08iv8DHohuaTQREYdgzEy1S/1R136RTDHeg08L9jxjojPrl1YhmabCV5qpLf8BZO+sMR/GAXhPA51O1q4SrqREplY X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2026 15:29:45.5203 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1379afe7-3c74-48c2-fb98-08df01f486dc 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: DU6PEPF0000A7E4.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB8221 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 20/08/2026 16:48, Simon Marchi wrote: > On 7/28/26 10:33 AM, Matthieu Longo wrote: >> 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; > > I think it would be more consistent with the other "find thread" methods > to return the `thread_info *` > Makes sense. Fixed. >> 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 ()); > > I don't think the printfs should be part of this getter function. Move > it to a separate function called by whoever needs it. Or just inline > it, it looks like there is just a single caller that needs it > (linux_info_proc). > The idea is to inform the user if a fallback occurs. Now, if I move the printing to another function, I don't have the fetched information anymore, and cannot figure out easily if a fallback happened and using which thread. It is ugly but I could not find better. Do you have a better approach ? > And really (IIUC), this function only really needs to return a tid (the > id of one LWP), not a ptid. Yes, at one exception in linux_fill_prpsinfo() where it needs the PID too. > > Simon Matthieu