From patchwork Sat Apr 20 05:56:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 790522 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp1416484wrm; Fri, 19 Apr 2024 22:57:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUIrTOm3pCVBr5NgR/4Mq+gUoCpqCZirkJFcStQn2JYjUQX6qkPHVzXWYb5nQIvkv8ghnNW8Xg8J0UjObejjWyQ X-Google-Smtp-Source: AGHT+IGhNDNUkxNNe5aoqZG5maoN6GW7KJBmDvuru+BcCQNf2VMS5Zz8h9LIDJ39aXygjvN50zDp X-Received: by 2002:a05:620a:807:b0:78f:ec9:387f with SMTP id s7-20020a05620a080700b0078f0ec9387fmr4297793qks.56.1713592648376; Fri, 19 Apr 2024 22:57:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713592648; cv=pass; d=google.com; s=arc-20160816; b=j6ECJtk0VJbXrJyktqXBvG5mjip8LfkhPt+UjuX2ZJmL64oyYJRQPvPsIgAPovAiiD 6uFlxXeGlvmquPxm5LioysawbEGeFbtVaRcjWq62UWBaiXm1FKccfC5m8sDAWTO4SzbO slFcgcgh0OgBHfl0cqXc4ziwjMH883PZ1YWJ8dzxw3dy3CFTUP9xJ+r/pkT6jBlq+ffm xdK/M9739mJd/DoOUBzGuSGNTSkLnmwZdwo5EhKliETaCEXjCRrOO4SwQlJk88PWJbEQ mq6TdnRR7zjKOTni+WhlKv7kkuaa6q3tb3Iu/D2GEYa8AXfIY9L9GPgqQ8ZAf3E/Gf0Y fa1Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=IxqndCGpyWwGCj7KkX0XOLriud63z/VjYBlBWwzA58Y=; fh=hiz3ehk7igAf1jDTyW+iD8dgiuxOgEsxZsLHCOrAJYo=; b=W6k/mCAYNUsYKB0x9z1wsV7s09qe2cTVKEKHj9y7qTd7HkFspjkNNVRsIe5Td4DTqV gkO50+JTJbKDGtNBLrUaEFD87QJ98ThP8g3DMcyM+u/fvmVL7mfS8/V0QXgsKvj+6oQ0 DUvdrF7IKgRzufrEBW6Nd2AUCvrS+2JnvU5GGiQhewCaJIyZdF6tCAV1S9igCQEaeo3L 4Mn9yc0tqIssvLfw0qhRztlbnrf39pKBI+jiFa2KIry86vUrX+Km6/dm0saIZZ7xX9wq DzFxzel4GN1HpT1YpbdkxIo4fntx2XFu0d+GRYNMbuVfPFgvaivc2lJxZc3Vn2vENUTO VOKQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b7VY4AiZ; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j25-20020a05620a147900b0078a51670468si5459247qkl.438.2024.04.19.22.57.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 22:57:28 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b7VY4AiZ; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 772DA385840C for ; Sat, 20 Apr 2024 05:57:27 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 2E80B3858D37 for ; Sat, 20 Apr 2024 05:57:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2E80B3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2E80B3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::330 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713592623; cv=none; b=FnokwpVlYXXeAM4LXZiQDG0B0XCLnWVqnIjlHeWraAbfRiBg1FIKGgoJKyqeMmdQ/vhgsw5Sedl1aMAKHLILLr/Vu2boABlDT1w5Xq9Uxwd16u5hC1/W06Q91jEKCxbJT8MxkfJSMYRR0nbk1A7HTfCW2TUexZRtP17OsH2YLsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713592623; c=relaxed/simple; bh=XopwI2VdvcVvsEo0tP95k00O4qdDbyDhuc041TnMrME=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QxJpSwCdpu+DdO0lQQFYhzOEC2PcyxQ5yj2CYnE9840njMjMJH9AKXeIHKlIeAvEZnn3lsPUI8v4hW3wXYVZirPLypPnz3iwo9Vb1MYoG57bD9vgJGLHxTfarcC2p2CkGZOkLRgpyWtdZIKsPn0Oao/bQ6MQDwFXeGaBEYeaUus= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6eb658ca1ceso1934371a34.2 for ; Fri, 19 Apr 2024 22:57:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713592621; x=1714197421; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IxqndCGpyWwGCj7KkX0XOLriud63z/VjYBlBWwzA58Y=; b=b7VY4AiZafF4TBjBN5RWSnasNnBv9g8Yb3IKMBWMpLsKEKKGdWqIDwzoGju4+yZ4YV jo7oGNbbSlUhLu7v1frvU+5n2VypfoUJT9cdn0MnQIDUTAhkctIm9nhHX6jKun4brM/l 4e4re0RYgeN9T/8SdBTJLBiYnZqCXK3izjGe8lW9DC3e/Diz1ggasVj6t/qNbpcjPPO0 I5Rtl+4mKP5uXvXX5w+BcfDtCt274wmo+kgJbIvBMjUZBd1DV+l5cGt3kbdSl02dxUXO lh8CC/C5Pb7GLn0mf/bQDlFq1HhWrgO4z6bpf6ZASEM+QrS8cVOIRT3bn56daKwwzFZi EAfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713592621; x=1714197421; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IxqndCGpyWwGCj7KkX0XOLriud63z/VjYBlBWwzA58Y=; b=PKS5TZBlyATYMMGcQ5SxKTh+LKTNSgAok0Jv6RtkxWac/DWytd4Df+QnXHwF71cD1c YTJ6cSpfbYBHGDtarVBqf/6ExUHNpg+BA/+hDDKglZ2d7LmnrtxA8tFrp1csXYt+HUjD NXT/+hN13h3i+/e0XU2WBYtq1NjaxdYe+v3Wh8dM4SamGN/yRSSUvbFVR+16gKyj7ZSe HC/3OpgRMbfxRfx0kNPmnkQFcurukOL6XKY1PMTrFKIalqSt2F9YvHzoLhzOCzLQMzpj 9e0KcFSaooO/aBVNz9qdykBwovZvXv1oYjLBujQEUBcPDbp4m5Pv3m7EYCNUCZThQf1+ XEGw== X-Gm-Message-State: AOJu0Yz2HTHkNz4uCmr87t2RD6R46lL7O45k3ManFvMs+nufoZFTrAut UYIjwWCMfHYlrpwon9qE0VwWu3M6Zid/gJ8DvehrXklLAFwUZ2SZiFMu6DCj6PPp1GDpaS9TI4E A X-Received: by 2002:a9d:590c:0:b0:6eb:7685:b00 with SMTP id t12-20020a9d590c000000b006eb76850b00mr4857947oth.28.1713592621165; Fri, 19 Apr 2024 22:57:01 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:1348:72c4:7c65:61e7]) by smtp.gmail.com with ESMTPSA id x19-20020a634853000000b005dc5129ba9dsm4081164pgk.72.2024.04.19.22.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 22:57:00 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Christophe Lyon , Luis Machado , Pedro Alves Subject: [PATCH v2 1/3] gdb/nat: Use procfs(5) indexes in linux_common_core_of_thread Date: Sat, 20 Apr 2024 02:56:50 -0300 Message-ID: <20240420055652.819024-2-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240420055652.819024-1-thiago.bauermann@linaro.org> References: <20240420055652.819024-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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+patch=linaro.org@sourceware.org The code and comment reference stat fields by made-up indexes. The procfs(5) man page, which describes the /proc/PID/stat file, has a numbered list of these fields so it's more convenient to use those numbers instead. This is currently an implementation detail inside the function so it's not really relevant with the code as-is, but a future patch will do some refactoring which will make the index more prominent. Therefore, make this change in a separate patch so that it's simpler to review. Reviewed-By: Luis Machado --- gdb/nat/linux-osdata.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) Changes in v2: - Added macros for field indexes in /proc/PID/stat (Suggested by Luis). diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c index 6ffabe90aa7d..079f9ea20c37 100644 --- a/gdb/nat/linux-osdata.c +++ b/gdb/nat/linux-osdata.c @@ -52,6 +52,10 @@ typedef long long TIME_T; #define MAX_PID_T_STRLEN (sizeof ("-9223372036854775808") - 1) +/* Index of fields of interest in /proc/PID/stat, from procfs(5) man page. */ +#define LINUX_PROC_STAT_STATE 3 +#define LINUX_PROC_STAT_PROCESSOR 39 + /* Returns the CPU core that thread PTID is currently running on. */ /* Compute and return the processor core of a given thread. */ @@ -74,10 +78,10 @@ linux_common_core_of_thread (ptid_t ptid) if (pos == std::string::npos) return -1; - /* If the first field after program name has index 0, then core number is - the field with index 36 (so, the 37th). There's no constant for that - anywhere. */ - for (int i = 0; i < 37; ++i) + /* 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 = LINUX_PROC_STAT_STATE; i <= LINUX_PROC_STAT_PROCESSOR; ++i) { /* Find separator. */ pos = content->find_first_of (' ', pos);