From: Disconnect3d <dominik.b.czarnota@gmail.com>
To: gdb-patches@sourceware.org
Cc: tom@tromey.com, Disconnect3d <dominik.b.czarnota@gmail.com>
Subject: [PATCH v2] gdb/linux-tdep: use thread lwp instead of pid for info proc
Date: Sat, 12 Apr 2025 22:11:41 +0200 [thread overview]
Message-ID: <20250412201140.31510-1-dominik.b.czarnota@gmail.com> (raw)
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
next reply other threads:[~2025-04-12 20:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-12 20:11 Disconnect3d [this message]
2025-04-17 21:25 ` Kevin Buettner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250412201140.31510-1-dominik.b.czarnota@gmail.com \
--to=dominik.b.czarnota@gmail.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox