• Guo Ren's avatar
    riscv: compat: ptrace: Add compat_arch_ptrace implement · 4608c159
    Guo Ren authored
    Now, you can use native gdb on riscv64 for rv32 app debugging.
    
    $ uname -a
    Linux buildroot 5.16.0-rc4-00036-gbef6b82fdf23-dirty #53 SMP Mon Dec 20 23:06:53 CST 2021 riscv64 GNU/Linux
    $ cat /proc/cpuinfo
    processor       : 0
    hart            : 0
    isa             : rv64imafdcsuh
    mmu             : sv48
    
    $ file /bin/busybox
    /bin/busybox: setuid ELF 32-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
    $ file /usr/bin/gdb
    /usr/bin/gdb: ELF 32-bit LSB shared object, UCB RISC-V, version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
    $ /usr/bin/gdb /bin/busybox
    GNU gdb (GDB) 10.2
    Copyright (C) 2021 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    ...
    Reading symbols from /bin/busybox...
    (No debugging symbols found in /bin/busybox)
    (gdb) b main
    Breakpoint 1 at 0x8ddc
    (gdb) r
    Starting program: /bin/busybox
    Failed to read a valid object file image from memory.
    
    Breakpoint 1, 0x555a8ddc in main ()
    (gdb) i r
    ra             0x77df0b74       0x77df0b74
    sp             0x7fdd3d10       0x7fdd3d10
    gp             0x5567e800       0x5567e800 <bb_common_bufsiz1+160>
    tp             0x77f64280       0x77f64280
    t0             0x0      0
    t1             0x555a6fac       1431990188
    t2             0x77dd8db4       2011008436
    fp             0x7fdd3e34       0x7fdd3e34
    s1             0x7fdd3e34       2145205812
    a0             0xffffffff       -1
    a1             0x2000   8192
    a2             0x7fdd3e3c       2145205820
    a3             0x0      0
    a4             0x7fdd3d30       2145205552
    a5             0x555a8dc0       1431997888
    a6             0x77f2c170       2012397936
    a7             0x6a7c7a2f       1786542639
    s2             0x0      0
    s3             0x0      0
    s4             0x555a8dc0       1431997888
    s5             0x77f8a3a8       2012783528
    s6             0x7fdd3e3c       2145205820
    s7             0x5567cecc       1432866508
    --Type <RET> for more, q to quit, c to continue without paging--
    s8             0x1      1
    s9             0x0      0
    s10            0x55634448       1432568904
    s11            0x0      0
    t3             0x77df0bb8       2011106232
    t4             0x42fc   17148
    t5             0x0      0
    t6             0x40     64
    pc             0x555a8ddc       0x555a8ddc <main+28>
    (gdb) si
    0x555a78f0 in mallopt@plt ()
    (gdb) c
    Continuing.
    BusyBox v1.34.1 (2021-12-19 22:39:48 CST) multi-call binary.
    BusyBox is copyrighted by many authors between 1998-2015.
    Licensed under GPLv2. See source distribution for detailed
    copyright notices.
    
    Usage: busybox [function [arguments]...]
       or: busybox --list[-full]
    ...
    [Inferior 1 (process 107) exited normally]
    (gdb) q
    Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
    Signed-off-by: default avatarGuo Ren <guoren@kernel.org>
    Reviewed-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
    Reviewed-by: default avatarArnd Bergmann <arnd@arndb.de>
    Tested-by: default avatarHeiko Stuebner <heiko@sntech.de>
    Link: https://lore.kernel.org/r/20220405071314.3225832-20-guoren@kernel.orgSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
    4608c159
ptrace.c 8.53 KB