public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb/nat: Use procfs(5) indexes in linux_common_core_of_thread
@ 2024-04-30  2:37 Thiago Bauermann
  0 siblings, 0 replies; only message in thread
From: Thiago Bauermann @ 2024-04-30  2:37 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3de4256ca3e80fe1ab9531585b9a0fee3920921d

commit 3de4256ca3e80fe1ab9531585b9a0fee3920921d
Author: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Date:   Mon Mar 18 19:28:50 2024 -0300

    gdb/nat: Use procfs(5) indexes in linux_common_core_of_thread
    
    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 <luis.machado@arm.com>
    Approved-By: Pedro Alves <pedro@palves.net>

Diff:
---
 gdb/nat/linux-osdata.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c
index 6ffabe90aa7..4812bc735e8 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);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-30  2:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-30  2:37 [binutils-gdb] gdb/nat: Use procfs(5) indexes in linux_common_core_of_thread Thiago Bauermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).