[v2] gdb/linux-tdep: use thread lwp instead of pid for info proc
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-arm |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Test passed
|
Commit Message
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(-)
Comments
A couple of nits - 1) add a Bug tag/line to the commit message, and 2)
I got some whitespace nits when applying this patch. See below.
On Sat, 12 Apr 2025 22:11:41 +0200
Disconnect3d <dominik.b.czarnota@gmail.com> wrote:
> 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.
Please add:
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31207
> 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.
When applying this patch, "git am" complained that spaces were being used
instead of a tab for the above two lines.
> + */
> + pid = inferior_thread ()->ptid.lwp ();
> }
>
> args = skip_spaces (args);
With those nits fixed, it's okay to push:
Approved-by: Kevin Buettner <kevinb@redhat.com>
@@ -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);