From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id FBkgK8uv/WXEthEAWB0awg (envelope-from ) for ; Fri, 22 Mar 2024 12:20:27 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=RNtZ4667; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=RNtZ4667; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9C1BC1E0C0; Fri, 22 Mar 2024 12:20:27 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 801621E030 for ; Fri, 22 Mar 2024 12:20:25 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 310D03858421 for ; Fri, 22 Mar 2024 16:20:25 +0000 (GMT) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2088.outbound.protection.outlook.com [40.107.13.88]) by sourceware.org (Postfix) with ESMTPS id C399D3858D28 for ; Fri, 22 Mar 2024 16:19:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C399D3858D28 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 C399D3858D28 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.13.88 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1711124402; cv=pass; b=gcNv3cSzN7+l0Bjc+1HfAN/IfeNFMlv7zHBNRPrFrtSv9ktIRZyW/gTSQ5eLWPojQmoEn/e6GQhbvxctt7eX9oVAX7rdUjIQQXhWbNZLz00vVuOL92smRNRXzWTrSDiBrFTpkYwizUeHOCdtiWHRyOsJa3TnjLjcvIPdAYu1XfM= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1711124402; c=relaxed/simple; bh=m2oKzJUV80BtKx8BNMO6pyaRwpg6htejxxMk1cE03Z8=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:Subject:To:From: MIME-Version; b=ha0tm0a3NPQOlE9/4oKtE2fJJ48UR4e45MjBoEySTGcIqXyibMbQEjGdpctCz3N4N7VMLzwusjvNQWvPTw84aunlrN/3798ZqCy+GVbBxZnCfdMIQkoe0/JRqxhfX0JzgQJMTaG+eZlA2BHGVI0J4g+VSRAE2Gi6Zr242VrD1oE= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=DbgaI+1HzKnlTWdNTtxjVs4j1NoaJy0w5JAARge7TnHhVkE0BUp/5oKUxEnKEPaThSAljcvUYHHW5X0yipZ/jKIYCgeVwf/W0QX30fkGdh+LeKJp1D/iyTD6Wo5nPE8U/xc1yxgrsXV5ISanEt2h1+hYLcXzXy8c6phYPx0Vg+X2n0kxhlj1siMY/UGhauZ6AlCf/wZmIyssN9GcIQHuEXbduTIIr8/CqGvkHI3cgmAIjonzYi5kEJYg7VhLtAFuxVLHZswIzjsGLCn2ecJ1+6gBPnAgnmOE+2/KJS2FmvEIsOTNxGeUaujiMtIZZIGRXv0Q91t7Il3ir++mc+WHxQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=0S1qiMtv7DKOJroXbzm/7sMZjtMUjbf6cueoG15UAz4=; b=Icsw1YbnJP1seItMTN+ogNnnSNqaGuW9iiuf0i9VmK46CI8yoRT8kHZTLWpi+zax/e+w/5U/c796ARD5bCSu9+QAUVjXvY6xUzZgPQuDKCz3BJ8vTFvH9II/KXOeZIGiPWV8tC9nu1k1sAPOGYaBwyyTeoT8iXB26eNkRDifqZjsoGkxoCZ7FekBHQSxdpQyJnoGZOXZ2Dms9Zl7G2Mxy1AKb3i+AFbS7fHyXQpgfULtnq0OteDWbUzdKb2ZsSGMi1L5t6aQLCabRqDnCTM8a+8C7tvbG4XHxz9hYJV848xx0FImYY0oJoHFzxIwWKHvOH0Ni29+mDngIvw0tVs/wA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) 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=armh.onmicrosoft.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=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0S1qiMtv7DKOJroXbzm/7sMZjtMUjbf6cueoG15UAz4=; b=RNtZ4667IA8mMvOkQXa2MET6cYT1puQvPBbilKNcmkHJoA7fPP9nC8L6g+15X4BKtDLCwHZmbRgAGgXAbMgrowZFf2IIzUPyyfYDmlF8rQ8hGVwjxsJGdIlpqx+J4b/nf510qijAZaasbGJQ6TAPlbG1DEvg9bxRTPIqezxzLcY= Received: from AM6PR10CA0022.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:89::35) by PA4PR08MB7641.eurprd08.prod.outlook.com (2603:10a6:102:273::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.30; Fri, 22 Mar 2024 16:19:45 +0000 Received: from AMS0EPF000001A2.eurprd05.prod.outlook.com (2603:10a6:209:89:cafe::68) by AM6PR10CA0022.outlook.office365.com (2603:10a6:209:89::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Fri, 22 Mar 2024 16:19:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AMS0EPF000001A2.mail.protection.outlook.com (10.167.16.235) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.10 via Frontend Transport; Fri, 22 Mar 2024 16:19:44 +0000 Received: ("Tessian outbound f0b355493f75:v300"); Fri, 22 Mar 2024 16:19:44 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 4e84b69a44e097ed X-CR-MTA-TID: 64aa7808 Received: from 8d3cf259fea9.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 36340F36-D115-4454-B8D0-58398C9F0006.1; Fri, 22 Mar 2024 16:19:38 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 8d3cf259fea9.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 22 Mar 2024 16:19:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k0m1uLYw4ty+UlqnI0scOJK06zpsnT1EJpdBsMNuUWbh2/9Vtmr4r7ccJbGScWQ8Reu7dwjDUJ8S36eaQCKN+RXCpzqGe//kOx29ukoS5dXRp4QgbsS+JgoOwzNbc4Q5dtm2iIXKvGW3NTuybmXKYHMonx29g3QoWVQK+OWDaArsBMJr2IqWNRuxKWSVyObYOmTOgc8ABYn8IugZDVy1xKqGvjaBVrzDJHMMZ2YIEjejhzQFUWH/ocXrE2/ExuNLXMrtgcIEX1Ts93u3xiAA6BzLj+Fv/PRr2vNSxLyxkYumAAzSpcCQIs+ZKs1GAuwiPzvEma67Zl0Mvi8Nq1U3GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=0S1qiMtv7DKOJroXbzm/7sMZjtMUjbf6cueoG15UAz4=; b=TxU9RdNaRN0pN8x596y2MpNyd+eir6YI+76caj4KASBONcUMo1+PhEJfhPKMshEnXwqK7emZ2KTtk0Z3eEpD5AD1qk8IzTRA+5OQnVJ7CW+PMbj0LV6vJIhOjcjm7cbtZjWtjdT1q7sww7RRywubXGbVKNBuyMsE5ZjnO9ZldkKABKhE52I3xUAFwz6qmNLBKotqQWbwpfDQWCG4pC5LHoru0Lw2od2Q1dFbye3nyWfgCxd4NjET+GUnmgSfn/MRiuCKfbUv/hJryVE+/Tl38iwi/TbdSD7+4q2+2I5u6PDp/cG0OXnTn1+nVp38Pl7M5kPEvmAJ7ZMkWV0HsMc9wA== 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=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0S1qiMtv7DKOJroXbzm/7sMZjtMUjbf6cueoG15UAz4=; b=RNtZ4667IA8mMvOkQXa2MET6cYT1puQvPBbilKNcmkHJoA7fPP9nC8L6g+15X4BKtDLCwHZmbRgAGgXAbMgrowZFf2IIzUPyyfYDmlF8rQ8hGVwjxsJGdIlpqx+J4b/nf510qijAZaasbGJQ6TAPlbG1DEvg9bxRTPIqezxzLcY= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) by DU0PR08MB9273.eurprd08.prod.outlook.com (2603:10a6:10:419::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.24; Fri, 22 Mar 2024 16:19:36 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::363f:3fc8:fc36:58ed]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::363f:3fc8:fc36:58ed%5]) with mapi id 15.20.7386.025; Fri, 22 Mar 2024 16:19:36 +0000 Message-ID: <6a1f6061-f04f-4bf2-8dca-8841efc9e487@arm.com> Date: Fri, 22 Mar 2024 16:19:34 +0000 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 3/3] gdb/nat/linux: Fix attaching to process when it has zombie threads Content-Language: en-US To: Thiago Jung Bauermann , gdb-patches@sourceware.org References: <20240321231149.519549-1-thiago.bauermann@linaro.org> <20240321231149.519549-4-thiago.bauermann@linaro.org> From: Luis Machado In-Reply-To: <20240321231149.519549-4-thiago.bauermann@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P265CA0152.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2c7::15) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|DU0PR08MB9273:EE_|AMS0EPF000001A2:EE_|PA4PR08MB7641:EE_ X-MS-Office365-Filtering-Correlation-Id: 457ce448-d053-4ebf-2097-08dc4a8be319 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: MbSWPvwe4qF8t8Zwn0atveajKFMjQhjLgPt8riIsX4O+xAbbidoFhpHjxmdHvcOjsrwQapEi7+wdICZbDgwny3JOOl4m1rPp7U1GQ/cmKEHQHFiqSQDiGrqrqU+k7fDXSEISh3XNyVwUQ0a9oon14wkbSywvlm/gkG3iohBOQ+EABVinktFfGYxrexCcPOC6shybG8X/Kc/w0RNzLQf5e/eE4S6anfbeIQ78QbfppLKD2mPx4+qcrrb0C6dt1MGiQUaJXhFmJkRRiMJVLGCM1dRZdEf4eav0nXMuLKMB3WPMqoBUm4qF2fno/nUHOToarDix98oMdOcetd+QWt+Mih8g8F/DPA0xFrtNuxnpPNPT4RTlc92dT4njOQRIe96zc8JYEAnW/O2QuUrCzBu4z91V4pP/2Ov3ILJJJrPk+Z1FBq8PNRiMiPvd4bwx5PzODE4+jJSui2j9HKAN1fzX7ZZz5s+oL31czwnFiYmkVQj+GSLr8Khy8VONi8xWZE0X9hD1Cg4E1zmzIPvZ1iXmHhHoO+WWZLSmbEB+YppFyLVz0pmJ0rDakQ1CuZegin/YT4V6//LJt7ZZ+dRl3bVnK8dc0h4ysa0vYcix0VC0Fpc= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB3919.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(1800799015)(366007)(376005); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9273 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AMS0EPF000001A2.eurprd05.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: eb53dae9-5122-41d9-1eec-08dc4a8bddbd X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ptL8AagqCe9sMBXLz1puLA4s8GR4RBR80l1ZMceOmiUvSW9gzxmT9nHeNYV591l0E2rE4JPnpEvsyncnbJW++X+7LMBT+9a0VxWws6P1zC7aJqJcaNDWVzPt6dn3cYzTXa2L0babzVdyj8dSN0XF4eCyO/Br7IKYxREdzCX+KYePsDfbHXyyvPz1PPeEfSYEI0Cufi6p68bJ0jAgidOpYZTL5b8AYZywEu4A4bwrpOSNGEdrXY5nbdlCfMQQRi4TZkivTXFXt3dqdMLISbKahN3UBspQbcKgqilsOtJ4ZxxenBtSJkXvXzwHl0KLLUO7/kLov89ETutrlvSGHWXBNWhMIuHfs8RXPh4DBw2JAe0lxd7OfuDC+tw9AS9a8S7QGxNVgIikEGhdSh20JxEEk9ZvY8SZkinZU29aVx1xY6QwtCA0XHoYBUGGTu8OaGdxIFoetyBeXAS2EmymU8MtK0t/vN7jwiZGavRwp38KvY/CMbOwNee05q16K48J1vVdcx8qpzvJvVfocu1yQn2Cl3swzrcPFOeUnRvK784ahl6fb1v6h9jMzunjxO03ofWCR7891j57hDu6/iLjzuOXoEVLqgHpBy4tMlTNKWL6JGi4xChmxTi74SoB24RnRdz0+OfEKHWOiJh1N80vj8njD0i3dD7IV82+gYNbw0porGyqOImTS3AfiQTDwOsSx5BFQUcPg0omoSjnjry3k40RNQ== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230031)(36860700004)(82310400014)(1800799015)(376005); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2024 16:19:44.9970 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 457ce448-d053-4ebf-2097-08dc4a8be319 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AMS0EPF000001A2.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB7641 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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+public-inbox=simark.ca@sourceware.org Thanks for the patch. On 3/21/24 23:11, Thiago Jung Bauermann wrote: > When GDB attaches to a multi-threaded process, it calls > linux_proc_attach_tgid_threads () to go through all threads found in > /proc/PID/task/ and call attach_proc_task_lwp_callback () on each of > them. If it does that twice without the callback reporting that a new > thread was found, then it considers that all inferior threads have been > found and returns. > > The problem is that the callback considers any thread that it hasn't > attached to yet as new. This causes problems if the process has one or > more zombie threads, because GDB can't attach to it and the loop will > always "find" a new thread (the zombie one), and get stuck in an > infinite loop. > > This is easy to trigger (at least on aarch64-linux and powerpc64le-linux) > with the gdb.threads/attach-many-short-lived-threads.exp testcase, because > its test program constantly creates and finishes joinable threads so the > chance of having zombie threads is high. > > This problem causes the following failures: > > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: attach (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: no new threads (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: set breakpoint always-inserted on (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: break break_fn (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: break at break_fn: 1 (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: break at break_fn: 2 (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: break at break_fn: 3 (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: reset timer in the inferior (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: print seconds_left (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: detach (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: set breakpoint always-inserted off (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: delete all breakpoints, watchpoints, tracepoints, and catchpoints in delete_breakpoints (timeout) > ERROR: breakpoints not deleted > > The iteration number is random, and all tests in the subsequent iterations > fail too, because GDB is stuck in the attach command at the beginning of > the iteration. > > The solution is to make linux_proc_attach_tgid_threads () remember when it > has already processed a given LWP and skip it in the subsequent iterations. > > PR testsuite/31312 > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31312 > --- > gdb/nat/linux-osdata.c | 22 ++++++++++++++++++++++ > gdb/nat/linux-osdata.h | 4 ++++ > gdb/nat/linux-procfs.c | 19 +++++++++++++++++++ > 3 files changed, 45 insertions(+) > > diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c > index c254f2e4f05b..998279377433 100644 > --- a/gdb/nat/linux-osdata.c > +++ b/gdb/nat/linux-osdata.c > @@ -112,6 +112,28 @@ linux_common_core_of_thread (ptid_t ptid) > return core; > } > > +/* See linux-osdata.h. */ > + > +std::optional > +linux_get_starttime (ptid_t ptid) > +{ > + std::optional field = linux_find_proc_stat_field (ptid, 22); Same idea about turning the explicit index into a named constant. > + > + if (!field.has_value ()) > + return {}; > + > + errno = 0; > + const char *trailer; > + ULONGEST starttime = strtoulst (field->c_str (), &trailer, 10); > + if (starttime == ULONGEST_MAX && errno == ERANGE) > + return {}; > + else if (*trailer != '\0') > + /* There were unexpected characters. */ > + return {}; > + > + return starttime; > +} > + > /* Finds the command-line of process PID and copies it into COMMAND. > At most MAXLEN characters are copied. If the command-line cannot > be found, PID is copied into command in text-form. */ > diff --git a/gdb/nat/linux-osdata.h b/gdb/nat/linux-osdata.h > index a82fb08b998e..1cdc687aa9cf 100644 > --- a/gdb/nat/linux-osdata.h > +++ b/gdb/nat/linux-osdata.h > @@ -27,4 +27,8 @@ extern int linux_common_core_of_thread (ptid_t ptid); > extern LONGEST linux_common_xfer_osdata (const char *annex, gdb_byte *readbuf, > ULONGEST offset, ULONGEST len); > > +/* Get the start time of thread PTID. */ > + > +extern std::optional linux_get_starttime (ptid_t ptid); > + > #endif /* NAT_LINUX_OSDATA_H */ > diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c > index b17e3120792e..b01bf36c0b53 100644 > --- a/gdb/nat/linux-procfs.c > +++ b/gdb/nat/linux-procfs.c > @@ -17,10 +17,13 @@ > along with this program. If not, see . */ > > #include "gdbsupport/common-defs.h" > +#include "linux-osdata.h" > #include "linux-procfs.h" > #include "gdbsupport/filestuff.h" > #include > #include > +#include > +#include > > /* Return the TGID of LWPID from /proc/pid/status. Returns -1 if not > found. */ > @@ -290,6 +293,10 @@ linux_proc_attach_tgid_threads (pid_t pid, > return; > } > > + /* Keeps track of the LWPs we have already visited in /proc, > + identified by their PID and starttime to detect PID reuse. */ > + std::set> visited_lwps; > + > /* Scan the task list for existing threads. While we go through the > threads, new threads may be spawned. Cycle through the list of > threads until we have done two iterations without finding new > @@ -308,6 +315,18 @@ linux_proc_attach_tgid_threads (pid_t pid, > if (lwp != 0) > { > ptid_t ptid = ptid_t (pid, lwp); > + std::optional starttime = linux_get_starttime (ptid); > + > + if (starttime.has_value ()) > + { > + std::pair key (lwp, *starttime); > + > + /* If we already visited this LWP, skip it this time. */ > + if (visited_lwps.find (key) != visited_lwps.cend ()) > + continue; > + > + visited_lwps.insert (key); > + } > > if (attach_lwp (ptid)) > new_threads_found = 1; Looks OK to me overall as well, pending the constant comment. I'd like to give others a chance to comment first. Reviewed-By: Luis Machado