Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH v2] gdb/linux-tdep: use thread lwp instead of pid for info proc
@ 2025-04-12 20:11 Disconnect3d
  2025-04-17 21:25 ` Kevin Buettner
  0 siblings, 1 reply; 2+ messages in thread
From: Disconnect3d @ 2025-04-12 20:11 UTC (permalink / raw)
  To: gdb-patches; +Cc: tom, Disconnect3d

This commit fixes bug #31207 where GDB shows an empty result
of `info proc mappings` when we debug a non-main thread of a Linux
process while the main thread has exitted. In such a case, the
`/proc/<pid>/maps` file renders an empty file and `/proc/<lwp>/maps`
should be used instead.

It is worth noting that the `/proc/<lwp>/` directories are not
rendered by the Linux kernel when listing the procfs directory
but they can be opened and they contain the usual procfs entries,
just for the pid of the thread.

Signed-off-by: Disconnect3d <dominik.b.czarnota@gmail.com>
---
 gdb/linux-tdep.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 141c1199c8a..c141c9c6701 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -842,7 +842,11 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
       if (current_inferior ()->fake_pid_p)
 	error (_("Can't determine the current process's PID: you must name one."));
 
-      pid = current_inferior ()->pid;
+      /* Use the thread's LWP ID instead of process ID when accessing procfs,
+         since the LWP-specific entries provide more useful information.
+         For example, /proc/<pid>/maps may be empty if the current thread has exited.
+      */
+      pid = inferior_thread ()->ptid.lwp ();
     }
 
   args = skip_spaces (args);
-- 
2.30.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-04-17 21:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-12 20:11 [PATCH v2] gdb/linux-tdep: use thread lwp instead of pid for info proc Disconnect3d
2025-04-17 21:25 ` Kevin Buettner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox