This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug threads/20294] New: bfd/elfxx-aarch64.c _bfd_aarch64_elf_grok_prstatus use error offset of pr_pid on arm64_ilp32


https://sourceware.org/bugzilla/show_bug.cgi?id=20294

            Bug ID: 20294
           Summary: bfd/elfxx-aarch64.c  _bfd_aarch64_elf_grok_prstatus
                    use error offset of pr_pid on arm64_ilp32
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: threads
          Assignee: unassigned at sourceware dot org
          Reporter: nixiaoming at huawei dot com
  Target Milestone: ---

When I use gdb to analysis a core generated by multithread ilp32 exe
Gdb canât get accurate threads info.  
after read gdb and linux code, 
I think maybe gdb use a error pr_pid offset in function
_bfd_aarch64_elf_grok_prstatus for arm64 ilp32 

Patch:
    fix error offset of pr_pid on arm64_ilp32

diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c
index f34ad9f..8e699cd 100644
--- a/bfd/elfxx-aarch64.c
+++ b/bfd/elfxx-aarch64.c
@@ -563,8 +563,12 @@ _bfd_aarch64_elf_grok_prstatus (bfd *abfd,
Elf_Internal_Note *note)
          = bfd_get_16 (abfd, note->descdata + 12);

        /* pr_pid */
+ /* ilp32 use compat_elf_prstatus, and pr_pid offset is 24
+  * (gdb) p  &((struct compat_elf_prstatus*) 0)->pr_pid
+  * $1 = (compat_pid_t *) 0x18 
+  */
        elf_tdata (abfd)->core->lwpid
-     = bfd_get_32 (abfd, note->descdata + 32);
+   = bfd_get_32 (abfd, note->descdata + 24);

        /* pr_reg */
        offset = 72;


test code:
ulimit -c unlimited
./mul_thread &
sleep 1
kill -11 $!

gdb ./mul_thread -c ./core-

        [New LWP 1631]
        [New LWP 1631]
        [New LWP 1631]
        [New LWP 1631]
        [New LWP 1631]
        [New LWP 1631]
        [New LWP 1631]
        [New LWP 1631]
        [New LWP 1631]
        [New LWP 1631]

        warning: Could not load shared library symbols for
linux-ilp32-vdso.so.1.
        Do you need "set solib-search-path" or "set sysroot"?
        Warning: couldn't activate thread debugging using libthread_db: Cannot
find new threads: debugger service failed

        warning: Unable to find libthread_db matching inferior's thread
library, thread debugging will not be available.
        Warning: couldn't activate thread debugging using libthread_db: Cannot
find new threads: debugger service failed

        warning: Unable to find libthread_db matching inferior's thread
library, thread debugging will not be available.
        Core was generated by `./mul_thread'.
        Program terminated with signal SIGSEGV, Segmentation fault.
        #0  0xf709be70 in pthread_join () from /libilp32/libpthread.so.0
        (gdb) info threads 
          Id   Target Id         Frame 
        * 31   LWP 1631          0xf709be70 in pthread_join () from
/libilp32/libpthread.so.0
        (gdb) 

objdump -h  core
        16 .reg/1631     00000110  00000000  00000000  00001474  2**2
                                          CONTENTS
         17 .reg2/1631    00000210  00000000  00000000  000015a0  2**2
                                          CONTENTS
         18 .reg-aarch-tls/1631 00000008  00000000  00000000  000017c4  2**2
                                          CONTENTS
         19 .reg-aarch-hw-break/1631 00000108  00000000  00000000  000017e0 
2**2
                                          CONTENTS
         20 .reg-aarch-hw-watch/1631 00000108  00000000  00000000  000018fc 
2**2
                                          CONTENTS
         21 .reg/1631     00000110  00000000  00000000  00001a78  2**2
                                          CONTENTS
         22 .reg2/1631    00000210  00000000  00000000  00001ba4  2**2
                                          CONTENTS
         23 .reg-aarch-tls/1631 00000008  00000000  00000000  00001dc8  2**2
                                          CONTENTS
         24 .reg-aarch-hw-break/1631 00000108  00000000  00000000  00001de4 
2**2
                                          CONTENTS
         25 .reg-aarch-hw-watch/1631 00000108  00000000  00000000  00001f00 
2**2
                                          CONTENTS
         26 .reg/1631     00000110  00000000  00000000  0000207c  2**2
                                          CONTENTS
         27 .reg2/1631    00000210  00000000  00000000  000021a8  2**2
                                          CONTENTS
         28 .reg-aarch-tls/1631 00000008  00000000  00000000  000023cc  2**2
                                          CONTENTS
         29 .reg-aarch-hw-break/1631 00000108  00000000  00000000  000023e8 
2**2
                                          CONTENTS
         30 .reg-aarch-hw-watch/1631 00000108  00000000  00000000  00002504 
2**2
                                          CONTENTS
         31 .reg/1631     00000110  00000000  00000000  00002680  2**2
                                          CONTENTS
         32 .reg2/1631    00000210  00000000  00000000  000027ac  2**2


code:
        read gdb code,   gdb ilp32 get pid form offset  32  of note->descdata
       
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=888a447e15f0f3349826358a16f7d2756b0bb226
        +       /* pr_pid */
        +       elf_tdata (abfd)->core->lwpid
        +         = bfd_get_32 (abfd, note->descdata + 32);

        But in arch/arm64/kernel/binfmt_ilp32.c, pr_pid offset is 24
          
https://github.com/norov/linux/blob/1a67337e3dfbae194f07d899f04042768490466f/arch/arm64/kernel/binfmt_ilp32.c
        #define elf_prstatus    compat_elf_prstatus

        (gdb) p  &((struct compat_elf_prstatus*) 0)->pr_pid
        $1 = (compat_pid_t *) 0x18 

        So, maybe we should update offset here

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]