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: 88787 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B54C3858415 for ; Sat, 20 Apr 2024 05:57:34 +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-Google-Smtp-Source: AGHT+IHUOIlLUS037QrunMz4AOnN4WZnq7p47Oc5DbmJXv7zfT7OfZWYl0qburxzYXnHBIt7uv1/oQ== 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+patchwork=sourceware.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);