From patchwork Wed Apr 24 23:15:49 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: 791576 Delivered-To: patch@linaro.org Received: by 2002:a5d:4884:0:b0:346:15ad:a2a with SMTP id g4csp1100982wrq; Wed, 24 Apr 2024 16:16:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUO4LVUus58kWJgdqhde5b05wAQKBVBhEiFyXOLUcnlYnhM05VXq+XtSpy3V/KGjChax50c1N82lhROduBoznH7 X-Google-Smtp-Source: AGHT+IGOxM4UOL3fVx0NuVHLzMUx34WaqIYrLTOHHeuqDDvJLrBW+mBOve7xOyYKaSzbd9bxWBys X-Received: by 2002:a54:481a:0:b0:3c8:42f5:4b5a with SMTP id j26-20020a54481a000000b003c842f54b5amr3757206oij.13.1714000609883; Wed, 24 Apr 2024 16:16:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714000609; cv=pass; d=google.com; s=arc-20160816; b=ksIjvVlm6M0/SncO153L9q+UKRTm+wrt381rkw7JOYtpKqkl5Of6o6gEFwi1i/QH6J TtNZPrdlRcasKlWUDAlRm9bh+iyeY36JfsWt/rdtHzfAVkXmk0ROclJh0XPY42cNzH16 7AV+foeMJreASTH2z3NIc4ezxgc89dg+w+5Yr+9nl8zGtqWDdtS+yHLTWLJKdUkqDfn/ u2n7/4qOfrB3KUf7vwgckWswt4Qy15R98toWdcWOwkqAaA2O+2vY8QIx5PyPNy5LY+4F q3DLW1Ky1HaYkL3PieqssS9ADuHXn3kqRMBdFomy3V3DpC6QhXuoR8XPRZyfDiXM94dI JCew== 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=fYBh+n9IwUhNo/7khRr/3J4ptTWU7xn/Zet84InQcgE=; fh=hiz3ehk7igAf1jDTyW+iD8dgiuxOgEsxZsLHCOrAJYo=; b=yETMFO6yVTqn6LWL9g+uPKXIkHQgx/0zEqLIV/F1K6pWLLqv0/vzNzfpGJaqeLmPUI wvbtUmHMf03EYezhWsgDOaZ7XdNo2324fjbQHKzTYY4E8SxVBLU1V9K5jG8D5EZtTUET JezFoYARLkzLj08JU1l356eUNhvWJIiG/ITzzgkKQVWHaaE+P6SvOMc5viW3AbZJxgUp J2kZlXIyJ2VRiaYG7J9wslnPvGoIOw8en3/cKjefSSmMRUvQpBcM7i0SDZaL9ph9CPrd s3QRxwaBBvO934ABkrkoy2DzA3p6zT3ZaXkPy1Q2jUxa9qTGhjs77mGgx5WH2qwM6w/o BXng==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oWKvCDbP; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id y20-20020a37e314000000b0078ecf9c3480si15191311qki.555.2024.04.24.16.16.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 16:16:49 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oWKvCDbP; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 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 80D9D38449C1 for ; Wed, 24 Apr 2024 23:16:49 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 388D43846410 for ; Wed, 24 Apr 2024 23:15:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 388D43846410 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 388D43846410 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714000561; cv=none; b=Wg7zGwfTH8g67XGBBHjZ32XOLrm5tOMdZLAbcPU9mFXEt/cZ/53H20+1u2GhgaaBHd4mYfU6rAwBgSS16V4n1rySeTLpNmqBg3c5aYaZr040FgrS88hKZyigPJgAcyDtunVwf7+CG4dAzRfDr3qSewztBavbnpcP5er4UQvzYi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714000561; c=relaxed/simple; bh=1xGhkGDmn9yKghDG/UQUQESMBKjS89m7wdcPxf2ymNU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GKTx8WyEL8BnY7yPX+qGHNpZ9GyZ/qQif6PzBaSfhzIp4/HZVGZTJyJq+ZbcqOatFA1elrxRdBEe8PB0p+ltnO/ap+SGmYUz8NWfVgoOusx+D1/+KNBHwd+b+AkegXjZmDCBEx3ItFV8U4AcI0u54qLIAoq4itPawl/l66mLQ4o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1e83a2a4f2cso2662075ad.1 for ; Wed, 24 Apr 2024 16:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714000558; x=1714605358; 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=fYBh+n9IwUhNo/7khRr/3J4ptTWU7xn/Zet84InQcgE=; b=oWKvCDbPCBVy2CtMX3UDKmg5ePZckvhOi3uEXXkLs9I0VsH51DFstv+PY9FReUrjuG LFiHtu19bGWPZz6OTrUVxqscmAf/Fn3SxHapmXKnSSEVtuVH/jAmxOLBM41wl0xjazXJ nuqfs7tP6Wxs7fGjAZ12c5nhbJg8/AykThsvVNOzAZYwnetfWUrJMI+ctw+cXoJke/rp ZC05Hl7HEOt1TKu3zf5GM+C6QP0TXphSQbVzFHBC/12gZ5LnIfZRCaPTzG29R0+Gl10J 4dir2Q5vmfqoY6wEMttqQ1umCw08HKVGzt2AXvEx8Km8ojRukuJsqZY4NwPpvyAefoRl BWHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714000558; x=1714605358; 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=fYBh+n9IwUhNo/7khRr/3J4ptTWU7xn/Zet84InQcgE=; b=eEmsHRozE77mMZDV/zWFdXD3OESByOtkqCU1fPoHnzOROd5goAnqroVcIlWUEvXMiz gNwdLWUFBa0Zc/AVRAgKr6hYbSzbefsON+iAIE6hbOluShrhDsg7yLNQfX2zSB5PJuWf RF5dGeNCEEcvovXejzcOZmjF3UqOjd1MBGavhK5ptPEKBz1xA32btmJHn74ZzIsQy+Jd jd5zEXxOHZwDc7FtLG/UICIKLHUKYN5W/f2S3UvjqiJg5VIU97liJ8qtaDGLq65Rawcu WgTU8ZuYlSBKjh8F7txiNlbWXgt5iCnPNNwJw5+vm52PUhZ3P8+Pr+bKUEgdSCQ0Nw0S bc1w== X-Gm-Message-State: AOJu0YxvoZ+ecaxQWtTqW+ncIZTazqK4z3tB3ISPBZzGi09jzgUqejPC cWDg8s7CJwAIIZjqQIdHvTMCNuM0nuO6cO4arWWHHaF/cGyAQ7MjamBm14Wh/RVCQsK4QuF1kSg k X-Received: by 2002:a17:902:7488:b0:1e2:a91c:9836 with SMTP id h8-20020a170902748800b001e2a91c9836mr3893078pll.33.1714000558122; Wed, 24 Apr 2024 16:15:58 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:b65d:315b:9fcb:d747]) by smtp.gmail.com with ESMTPSA id ba5-20020a170902720500b001e2b4f513e1sm12433555plb.106.2024.04.24.16.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 16:15:57 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Christophe Lyon , Luis Machado , Pedro Alves Subject: [PATCH v3 1/3] gdb/nat: Use procfs(5) indexes in linux_common_core_of_thread Date: Wed, 24 Apr 2024 20:15:49 -0300 Message-ID: <20240424231551.1577518-2-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240424231551.1577518-1-thiago.bauermann@linaro.org> References: <20240424231551.1577518-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 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) Changes in v3: - Use macro names in comment, and clarify why we use those fields (suggested by Pedro). 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..4812bc735e86 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,9 @@ 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) + /* The first field after program name is LINUX_PROC_STAT_STATE, and we are + interested in field LINUX_PROC_STAT_PROCESSOR. */ + for (int i = LINUX_PROC_STAT_STATE; i <= LINUX_PROC_STAT_PROCESSOR; ++i) { /* Find separator. */ pos = content->find_first_of (' ', pos);