From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ziY1Gwiu/WU4tREAWB0awg (envelope-from ) for ; Fri, 22 Mar 2024 12:12:56 -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=T4KsvCU/; 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=T4KsvCU/; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 5C3DA1E0C0; Fri, 22 Mar 2024 12:12:56 -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 383F51E030 for ; Fri, 22 Mar 2024 12:12:54 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A60413858415 for ; Fri, 22 Mar 2024 16:12:53 +0000 (GMT) Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on2053.outbound.protection.outlook.com [40.107.15.53]) by sourceware.org (Postfix) with ESMTPS id 935A83858D28 for ; Fri, 22 Mar 2024 16:12:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 935A83858D28 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 935A83858D28 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.15.53 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1711123951; cv=pass; b=M3Qr0G6aJ3c5zN0FUq8wZ2tinqZdBlhowUJk88wqwt+rDNtzeM/NU3ZRw4ZmZoneHI1X+/P0GG0F2wE3Iu5cZaDd+4TfxdT5foe5tSfO00xW2ECLv4PimsRIRXna5c3uhcr22EXYO0/gVA0gwGrcX3PqZEsBzdvrYo1F87fYbi0= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1711123951; c=relaxed/simple; bh=xdZAoLWvV3rzzX2DfqijUTFvTBtZ4JWdj5AJGk8SwHk=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:Subject:To:From: MIME-Version; b=nEy+wDraZF7TyzyNYoaKNVWzEr9q5brEb7LLZxHxtFb81mbF7xE8/zAfuz/RaPnXmAmhSaI7q+r5nzSDRts8p30NlqBD7XMCnbTnJS5sW0/ykX93R5KzltE/c8f1vLdCzCE3OQl7A3QbqdBM6Q80FzJwuERCupWOA6uA1fyU8B4= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=ny+HM9c7rOtD07V0mxyjVm1NIXaWQEWkwSUFDPjGbAXyBP1DatZ3Vl4TeFBR1f5e+xI2uPiX9KYknfmtk4srPPq0VLfBZNVLoBtLLosXlS6z2SXwjPgs/gSWV/uTzfwQ6y32N4MqJoAhoWbexAMlw55DxIH3CfhJZhrHMxCXzeiw8qS4D93q2fZN76+Sp2abwUIBV55cGqLv8f0bKuZBexzXY59+kKcg2ofaatto084N78EvIwsORogSJC6UWkLj9WTmN4iWy9ijsakFEXytC5LlufT+1MnG+bgcfGCH00kfCWCB0CujyoNUqQwIPy5+UKIlj8OXblehzXX0tCcd/w== 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=5nQ9Uxhvzqvat23FbfY7z0W2vDFuCjkpoUiSOnzBoMk=; b=DnBrV97RAWy94Dw5rDcKYfkNPgPoWl0GsAgLMar2U0E5tfuHBSSqupJ0PEPohnyb0eYErSUzizndjeCz4KjMu//F+9uSH6P+j+q0xLzolaEuWgNDjLWAxj+VYlhUbeGBPm/CeMh5DeX8PzE9ZgpRfXPb3lqSpmk/D46tL+7o1s1n9LdFwKZyf50SU73Z4VZaG/dYdPx1yT8qzQlv/4cIHgCqACahrmNeAika5lP+bErd706RNH42Mj8TPOVP6rvO4eIm2VqjENXx7kGO12t8asAE1x6axVfcj5enFpcX6o7mROcW9Z2UN/UdyTmmksSPKZFiM16gXUSXJfdPB0qFWw== 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=5nQ9Uxhvzqvat23FbfY7z0W2vDFuCjkpoUiSOnzBoMk=; b=T4KsvCU/pAP9uUCdTxd8hwW0/NMLzOtDrg3lllq6+KKy9ostsKf/7gVq4T/VHIunWCLoog9PqpKxHUCKhFerOLsBhvsuytPQuoaT1jRWJ5k04dLm0HkqheH5PSmCC6VTCxZ3wJOauSLXejixLqp49iC0VUD1L0hBZlmMrtaz8nI= Received: from AM5PR0601CA0063.eurprd06.prod.outlook.com (2603:10a6:206::28) by AM8PR08MB5747.eurprd08.prod.outlook.com (2603:10a6:20b:1c7::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:12:17 +0000 Received: from AMS1EPF00000041.eurprd04.prod.outlook.com (2603:10a6:206:0:cafe::7c) by AM5PR0601CA0063.outlook.office365.com (2603:10a6:206::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.28 via Frontend Transport; Fri, 22 Mar 2024 16:12:17 +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 AMS1EPF00000041.mail.protection.outlook.com (10.167.16.38) 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:12:15 +0000 Received: ("Tessian outbound 9b7417e2a8eb:v300"); Fri, 22 Mar 2024 16:12:15 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 8ad3abdf98e8de97 X-CR-MTA-TID: 64aa7808 Received: from 613f1dc78e85.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 329EAEE7-5525-4992-A130-6B1601AB1393.1; Fri, 22 Mar 2024 16:12:09 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 613f1dc78e85.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 22 Mar 2024 16:12:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gr+Y4gjcnbgfVV3l9bDN1vKO9QXhJJcouSVTkvegoz7jxprfvaavubw7X6rgZGSPTujfcpMP3hJAIHDrLOfhp7ciy5aOiVm6wMOl6sJr7NgcJ76ztSNtUbFtlLmYVs96W67XPXqTGOgrw9m6nBa/VLYszEASRDHePQhW6M9T+ottmv2pgl0fQsx1lWOGm9lgHGE3B9GHzItYmcHvSBx3S2+T+1Gn41jkWPUrLDRJm0fRsQ2Y1u9Jql/D0qUFu+ttEXabdB4BY18AnsyFr24bqtH3HQ7wQpOvxwdxhFK/w9tMQri9IDJxVQSgm/FtiHo2kYbAv+5ukKtqEkoZhNhQ0Q== 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=5nQ9Uxhvzqvat23FbfY7z0W2vDFuCjkpoUiSOnzBoMk=; b=Ewu2acHURfZ9WVLvugdUAzgqsvPp/yFPdIdV3bCtue+QL8ZqPm3Bga8jTbwmFL8qjr1ReTNS2ne/qSStB3wUfCOrPuKGdue2Rfspv4ZDrdBfYbXnx1gEC3qL2S1aoa2sqGMzGVT8vxgSFB8PP4amtZo9n8fu+fJPJLE3FLWO0Ug46a+dolxc9luS66J7eDGV6fLZoyn10M+gW0g6pY2a3hrj9OXvAj9xuFVmT9UtZJSX4OyQg9LggR4JCru5QXXcVK7H6YJxv9VedHDXr21sma1h+h13Bm65ZNAQabUjd4JVD8iXk5D4yFpaPhMNOOft2g5CHiiQKqa1K02zT8bPXA== 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=5nQ9Uxhvzqvat23FbfY7z0W2vDFuCjkpoUiSOnzBoMk=; b=T4KsvCU/pAP9uUCdTxd8hwW0/NMLzOtDrg3lllq6+KKy9ostsKf/7gVq4T/VHIunWCLoog9PqpKxHUCKhFerOLsBhvsuytPQuoaT1jRWJ5k04dLm0HkqheH5PSmCC6VTCxZ3wJOauSLXejixLqp49iC0VUD1L0hBZlmMrtaz8nI= 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 VI0PR08MB10709.eurprd08.prod.outlook.com (2603:10a6:800:206::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.26; Fri, 22 Mar 2024 16:12:06 +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:12:06 +0000 Message-ID: Date: Fri, 22 Mar 2024 16:12:02 +0000 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 2/3] gdb/nat: Factor linux_find_proc_stat_field out of linux_common_core_of_thread To: Thiago Jung Bauermann , gdb-patches@sourceware.org References: <20240321231149.519549-1-thiago.bauermann@linaro.org> <20240321231149.519549-3-thiago.bauermann@linaro.org> Content-Language: en-US From: Luis Machado In-Reply-To: <20240321231149.519549-3-thiago.bauermann@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P265CA0115.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2c3::19) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|VI0PR08MB10709:EE_|AMS1EPF00000041:EE_|AM8PR08MB5747:EE_ X-MS-Office365-Filtering-Correlation-Id: 3c0b8490-7d31-4904-c215-08dc4a8ad766 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: v7rcUX7xp6yewuUrDnw9M4lUJHDkN2WY+OAozkBxilcRgkXesOEP/dYXHJHXRdHQ+87k9FppTbChITxNWBE5LpFA5BQIX3ACSgYristWpLZ0W0OhF3gs7PiERFtiJX1PGEFQpRQGfEwO1TKVbqzqIUncdkInMiprCGC1x0+/nEQEbZURXfUoVdQGQsurZZ3sq3tTk6xK7HBNLBRKE3k2DYbKbuGNHg4Z0vCvkqNazXH2wnZq5X3TbhsayFYr5TPUf5P411+8LeJ+C4rAeP0gM5fvS92pIv1bXrr0iuxb2BuaxySApPjv+zqdWra47aI2P+Kw27DCYfY5saH4gx+m8xFvhgC1kc+3qRWvsKElX+ZxW4jpzJBhiBRvxa8cMZLnjCy1DIQUl+z0yD65IoOewYLrAer2yMyerAnmsGQgnUmEg7QpMygKN8sSfNA940IRzj9uiT+r8z0dS5borWSAn9yBsEPExhefBW1O5yVZfjlOgqOI9sdJlhMYotw0sg9pumsiFpeBZ5D0tHHsKt8xbr/yd5Vn1fJzvQlM8sV5mSfpxl08x5UROCPegBcq7DR/UujQ8chdNNIsSg+KOb/nZfkYhRa2tm39VEU4N2SCwc7hEivGC1I6VgTB/d/OV227lmu9nGsMmChqzwqFgjlkfw== 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)(376005)(366007)(1800799015); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI0PR08MB10709 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: AMS1EPF00000041.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: e9c60309-85c7-4835-0ed9-08dc4a8ad184 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /j6VzDYjVMVGI7t9HxnTBgZaeL1KyZ7xKueMSU0MSL3BYTToIyyYTg7z1YWQguR8HESo226kSb4GTRtfAXqseiTGlKA8J8zmcNh9/9IXNDW2y1hXHMDsHN/j5ZHTd/gF+4l0tX5vEvQIY9d9BjIMUeAOWq7L7cdiOorOeKDW0Z6+BRv0DRHyC2xPPRejoZqslsXbgRKRlhl1DxZcIg15JIRIjOWmijlkYHS/SLcxnv8wQus8mz34FUU8MzzPy8lOZKaXBr9DSQbIa2H5Cb5XAxxtsvYtGcQNdYb2v3US0TUUVw4LdfnCnVdfGxerfh/XWSQBjxvpD2jwQPLgmqRWGLzjGzTUB4h/6XRIgtGVO1lY8UbvyPHDXDiFJgJfRcVH94PuCgpTI2SZ9s8LqALgSIiGsCqwdnH6xJd18Z1HEauzrRjIWdLkgIP8ujaKFXa+ej3qBzt6cmZGbiJdkD4auWoq/FJ+btRAgxl2aYp1YmhNrfaJI5dZQJ093PuAjiWabctZj0/TEg+cfS3aq45CmRHKEnDLOU+UslDZi3bu+f0vsQavO8MRtH3N8MEKzcH9sL/fS9J/LjNnNVWf1K94h+ETAKhSKE3j37t4VmHNnu5gQV4a3wfMUCwudZVmkeN6ikCyqWqGgg33JCJ7G21BU/Fp8ORGG/b5OtS7E+aworhryfMyXDRlPcs6LzE0c2JyxDADSMUFRIjg1bXZMJMuLqmNB91pD6pcwQZKgQ1mGdn+7ZCBmoQ16WrScIJX6xPL 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)(376005)(82310400014)(36860700004)(1800799015); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2024 16:12:15.8920 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3c0b8490-7d31-4904-c215-08dc4a8ad766 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: AMS1EPF00000041.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5747 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, 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 On 3/21/24 23:11, Thiago Jung Bauermann wrote: > The new function will be used in a subsequent patch to read a different > stat field. > > The new code is believed to be equivalent to the old code, so there should > be no change in GDB behaviour. > > Also, take the opportunity to move the function's documentation comment to > the header file, to conform with GDB practice. > --- > gdb/nat/linux-osdata.c | 43 ++++++++++++++++++++++++++++-------------- > gdb/nat/linux-osdata.h | 3 +++ > 2 files changed, 32 insertions(+), 14 deletions(-) > > diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c > index 172fea5cea85..c254f2e4f05b 100644 > --- a/gdb/nat/linux-osdata.c > +++ b/gdb/nat/linux-osdata.c > @@ -53,32 +53,31 @@ typedef long long TIME_T; > > #define MAX_PID_T_STRLEN (sizeof ("-9223372036854775808") - 1) > > -/* Returns the CPU core that thread PTID is currently running on. */ > +/* Returns FIELD (as numbered in procfs(5) man page) of > + /proc/PID/task/LWP/stat file. */ > > -/* Compute and return the processor core of a given thread. */ > - > -int > -linux_common_core_of_thread (ptid_t ptid) > +static std::optional > +linux_find_proc_stat_field (ptid_t ptid, int field) > { > + /* We never need to read PID from the stat file, and there's > + command_from_pid to read the comm field. */ > + gdb_assert (field >= 3); > + > char filename[sizeof ("/proc//task//stat") + 2 * MAX_PID_T_STRLEN]; > - int core; > > sprintf (filename, "/proc/%lld/task/%lld/stat", > (PID_T) ptid.pid (), (PID_T) ptid.lwp ()); > > std::optional content = read_text_file_to_string (filename); > if (!content.has_value ()) > - return -1; > + return {}; > > /* ps command also relies on no trailing fields ever contain ')'. */ > std::string::size_type pos = content->find_last_of (')'); > if (pos == std::string::npos) > - return -1; > + return {}; > > - /* If the first field after program name has index 3, then core number is > - the field with index 39. These are the indexes shown in the procfs(5) > - man page. */ > - for (int i = 3; i <= 39; ++i) > + for (int i = 3; i <= field; ++i) > { > /* Find separator. */ > pos = content->find_first_of (' ', pos); > @@ -91,8 +90,24 @@ linux_common_core_of_thread (ptid_t ptid) > return {}; > } > > - if (sscanf (&(*content)[pos], "%d", &core) == 0) > - core = -1; > + /* Find end of field. */ > + std::string::size_type end_pos = content->find_first_of (' ', pos); > + if (end_pos == std::string::npos) > + return content->substr (pos); > + else > + return content->substr (pos, end_pos - pos); > +} > + > +/* See linux-osdata.h. */ > + > +int > +linux_common_core_of_thread (ptid_t ptid) > +{ > + std::optional field = linux_find_proc_stat_field (ptid, 39); > + int core; > + > + if (!field.has_value () || sscanf (field->c_str (), "%d", &core) == 0) > + return -1; > > return core; > } > diff --git a/gdb/nat/linux-osdata.h b/gdb/nat/linux-osdata.h > index 833915cdb2fd..a82fb08b998e 100644 > --- a/gdb/nat/linux-osdata.h > +++ b/gdb/nat/linux-osdata.h > @@ -20,7 +20,10 @@ > #ifndef NAT_LINUX_OSDATA_H > #define NAT_LINUX_OSDATA_H > > +/* Returns the CPU core that thread PTID is currently running on. */ > + > 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); > Looks OK overall. I'd just attempt to replace the constants (3 and 39) with something more explicit (or an enum, not sure if we need to go that far though) Reviewed-By: Luis Machado