diff mbox series

linux-user/elfload: Fix pr_pid values in core files

Message ID 20240801202340.21845-1-iii@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series linux-user/elfload: Fix pr_pid values in core files | expand

Commit Message

Ilya Leoshkevich Aug. 1, 2024, 8:23 p.m. UTC
Analyzing qemu-produced core dumps of multi-threaded apps runs into:

    (gdb) info threads
      [...]
      21   Thread 0x3ff83cc0740 (LWP 9295) warning: Couldn't find general-purpose registers in core file.
    <unavailable> in ?? ()

The reason is that all pr_pid values are the same, because the same
TaskState is used for all CPUs when generating NT_PRSTATUS notes.

Fix by using TaskStates associated with individual CPUs.

Cc: qemu-stable@nongnu.org
Fixes: 243c47066253 ("linux-user/elfload: Write corefile elf header in one block")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 linux-user/elfload.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Richard Henderson Aug. 1, 2024, 9:45 p.m. UTC | #1
On 8/2/24 06:23, Ilya Leoshkevich wrote:
> Analyzing qemu-produced core dumps of multi-threaded apps runs into:
> 
>      (gdb) info threads
>        [...]
>        21   Thread 0x3ff83cc0740 (LWP 9295) warning: Couldn't find general-purpose registers in core file.
>      <unavailable> in ?? ()
> 
> The reason is that all pr_pid values are the same, because the same
> TaskState is used for all CPUs when generating NT_PRSTATUS notes.
> 
> Fix by using TaskStates associated with individual CPUs.
> 
> Cc:qemu-stable@nongnu.org
> Fixes: 243c47066253 ("linux-user/elfload: Write corefile elf header in one block")
> Signed-off-by: Ilya Leoshkevich<iii@linux.ibm.com>
> ---
>   linux-user/elfload.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)

Oops,

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~
Philippe Mathieu-Daudé Aug. 2, 2024, 1:20 p.m. UTC | #2
On 1/8/24 22:23, Ilya Leoshkevich wrote:
> Analyzing qemu-produced core dumps of multi-threaded apps runs into:
> 
>      (gdb) info threads
>        [...]
>        21   Thread 0x3ff83cc0740 (LWP 9295) warning: Couldn't find general-purpose registers in core file.
>      <unavailable> in ?? ()
> 
> The reason is that all pr_pid values are the same, because the same
> TaskState is used for all CPUs when generating NT_PRSTATUS notes.
> 
> Fix by using TaskStates associated with individual CPUs.
> 
> Cc: qemu-stable@nongnu.org
> Fixes: 243c47066253 ("linux-user/elfload: Write corefile elf header in one block")

Isn't it

Fixes: edf8e2af14 ("linux-user: implemented ELF coredump")

?
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>   linux-user/elfload.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Ilya Leoshkevich Aug. 2, 2024, 1:23 p.m. UTC | #3
On Fri, 2024-08-02 at 15:20 +0200, Philippe Mathieu-Daudé wrote:
> On 1/8/24 22:23, Ilya Leoshkevich wrote:
> > Analyzing qemu-produced core dumps of multi-threaded apps runs
> > into:
> > 
> >      (gdb) info threads
> >        [...]
> >        21   Thread 0x3ff83cc0740 (LWP 9295) warning: Couldn't find
> > general-purpose registers in core file.
> >      <unavailable> in ?? ()
> > 
> > The reason is that all pr_pid values are the same, because the same
> > TaskState is used for all CPUs when generating NT_PRSTATUS notes.
> > 
> > Fix by using TaskStates associated with individual CPUs.
> > 
> > Cc: qemu-stable@nongnu.org
> > Fixes: 243c47066253 ("linux-user/elfload: Write corefile elf header
> > in one block")
> 
> Isn't it
> 
> Fixes: edf8e2af14 ("linux-user: implemented ELF coredump")
> 
> ?

I haven't tested it, but this looks correct:

static void fill_thread_info(struct elf_note_info *info, const CPUState
*env)
{
    TaskState *ts = (TaskState *)env->opaque;

> > Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> > ---
> >   linux-user/elfload.c | 8 +++-----
> >   1 file changed, 3 insertions(+), 5 deletions(-)
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>
diff mbox series

Patch

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 7ecbc8a7cc0..0861f115fc4 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -4102,8 +4102,7 @@  static void fill_elf_note_phdr(struct elf_phdr *phdr, size_t sz, off_t offset)
     bswap_phdr(phdr, 1);
 }
 
-static void fill_prstatus_note(void *data, const TaskState *ts,
-                               CPUState *cpu, int signr)
+static void fill_prstatus_note(void *data, CPUState *cpu, int signr)
 {
     /*
      * Because note memory is only aligned to 4, and target_elf_prstatus
@@ -4113,7 +4112,7 @@  static void fill_prstatus_note(void *data, const TaskState *ts,
     struct target_elf_prstatus prstatus = {
         .pr_info.si_signo = signr,
         .pr_cursig = signr,
-        .pr_pid = ts->ts_tid,
+        .pr_pid = get_task_state(cpu)->ts_tid,
         .pr_ppid = getppid(),
         .pr_pgrp = getpgrp(),
         .pr_sid = getsid(0),
@@ -4428,8 +4427,7 @@  static int elf_core_dump(int signr, const CPUArchState *env)
         CPU_FOREACH(cpu_iter) {
             dptr = fill_note(&hptr, NT_PRSTATUS, "CORE",
                              sizeof(struct target_elf_prstatus));
-            fill_prstatus_note(dptr, ts, cpu_iter,
-                               cpu_iter == cpu ? signr : 0);
+            fill_prstatus_note(dptr, cpu_iter, cpu_iter == cpu ? signr : 0);
         }
 
         if (dump_write(fd, header, data_offset) < 0) {