From: guoren@kernel.org
To: guoren@kernel.org, palmer@dabbelt.com, arnd@arndb.de,
anup.patel@wdc.com, gregkh@linuxfoundation.org,
liush@allwinnertech.com, wefu@redhat.com, drew@beagleboard.org,
wangjunqiang@iscas.ac.cn, lazyparser@gmail.com
Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-csky@vger.kernel.org, Guo Ren <guoren@linux.alibaba.com>
Subject: [PATCH 13/13] riscv: compat: ptrace: Add compat_arch_ptrace implement
Date: Wed, 22 Dec 2021 00:35:32 +0800 [thread overview]
Message-ID: <20211221163532.2636028-14-guoren@kernel.org> (raw)
In-Reply-To: <20211221163532.2636028-1-guoren@kernel.org>
From: Guo Ren <guoren@linux.alibaba.com>
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: Guo Ren <guoren@linux.alibaba.com>
---
arch/riscv/kernel/ptrace.c | 80 +++++++++++++++++++++++++++++++++++---
1 file changed, 74 insertions(+), 6 deletions(-)
diff --git a/arch/riscv/kernel/ptrace.c b/arch/riscv/kernel/ptrace.c
index 55dd50f8a5cc..76042ed861a3 100644
--- a/arch/riscv/kernel/ptrace.c
+++ b/arch/riscv/kernel/ptrace.c
@@ -114,11 +114,6 @@ static const struct user_regset_view riscv_user_native_view = {
.n = ARRAY_SIZE(riscv_user_regset),
};
-const struct user_regset_view *task_user_regset_view(struct task_struct *task)
-{
- return &riscv_user_native_view;
-}
-
struct pt_regs_offset {
const char *name;
int offset;
@@ -278,9 +273,82 @@ __visible void do_syscall_trace_exit(struct pt_regs *regs)
}
#ifdef CONFIG_COMPAT
+static int compat_riscv_gpr_get(struct task_struct *target,
+ const struct user_regset *regset,
+ struct membuf to)
+{
+ struct compat_user_regs_struct cregs;
+
+ regs_to_cregs(&cregs, task_pt_regs(target));
+
+ return membuf_write(&to, &cregs,
+ sizeof(struct compat_user_regs_struct));
+}
+
+static int compat_riscv_gpr_set(struct task_struct *target,
+ const struct user_regset *regset,
+ unsigned int pos, unsigned int count,
+ const void *kbuf, const void __user *ubuf)
+{
+ int ret;
+ struct compat_user_regs_struct cregs;
+
+ ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &cregs, 0, -1);
+
+ cregs_to_regs(&cregs, task_pt_regs(target));
+
+ return ret;
+}
+
+static const struct user_regset compat_riscv_user_regset[] = {
+ [REGSET_X] = {
+ .core_note_type = NT_PRSTATUS,
+ .n = ELF_NGREG,
+ .size = sizeof(compat_elf_greg_t),
+ .align = sizeof(compat_elf_greg_t),
+ .regset_get = compat_riscv_gpr_get,
+ .set = compat_riscv_gpr_set,
+ },
+#ifdef CONFIG_FPU
+ [REGSET_F] = {
+ .core_note_type = NT_PRFPREG,
+ .n = ELF_NFPREG,
+ .size = sizeof(elf_fpreg_t),
+ .align = sizeof(elf_fpreg_t),
+ .regset_get = riscv_fpr_get,
+ .set = riscv_fpr_set,
+ },
+#endif
+};
+
+static const struct user_regset_view compat_riscv_user_native_view = {
+ .name = "riscv",
+ .e_machine = EM_RISCV,
+ .regsets = compat_riscv_user_regset,
+ .n = ARRAY_SIZE(compat_riscv_user_regset),
+};
+
long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
compat_ulong_t caddr, compat_ulong_t cdata)
{
- return 0;
+ long ret = -EIO;
+
+ switch (request) {
+ default:
+ ret = compat_ptrace_request(child, request, caddr, cdata);
+ break;
+ }
+
+ return ret;
}
+#endif /* CONFIG_COMPAT */
+
+const struct user_regset_view *task_user_regset_view(struct task_struct *task)
+{
+#ifdef CONFIG_COMPAT
+ if (test_tsk_thread_flag(task, TIF_32BIT))
+ return &compat_riscv_user_native_view;
+ else
#endif
+ return &riscv_user_native_view;
+}
--
2.25.1
next prev parent reply other threads:[~2021-12-21 16:36 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-21 16:35 [PATCH 00/13] riscv: compat: Add COMPAT mode support for rv64 guoren
2021-12-21 16:35 ` [PATCH 01/13] syscalls: compat: Fix the missing part for __SYSCALL_COMPAT guoren
2021-12-21 17:08 ` Arnd Bergmann
2021-12-22 11:16 ` Guo Ren
2021-12-22 11:24 ` Arnd Bergmann
2021-12-24 6:52 ` Christoph Hellwig
2021-12-21 16:35 ` [PATCH 02/13] riscv: Fixup difference with defconfig guoren
2021-12-21 17:09 ` Arnd Bergmann
2021-12-22 11:34 ` Guo Ren
2021-12-22 11:44 ` Arnd Bergmann
2021-12-22 13:06 ` Guo Ren
2021-12-22 13:30 ` Arnd Bergmann
2021-12-23 2:12 ` Guo Ren
2021-12-21 16:35 ` [PATCH 03/13] riscv: compat: Add basic compat date type implementation guoren
2021-12-21 17:12 ` Arnd Bergmann
2021-12-22 12:03 ` Guo Ren
2021-12-22 12:46 ` Arnd Bergmann
2021-12-26 15:33 ` Guo Ren
2021-12-24 6:53 ` Christoph Hellwig
2021-12-24 9:28 ` Guo Ren
2021-12-21 16:35 ` [PATCH 04/13] riscv: compat: Re-implement TASK_SIZE for COMPAT_32BIT guoren
2021-12-21 16:35 ` [PATCH 05/13] riscv: compat: syscall: Add compat_sys_call_table implementation guoren
2021-12-21 17:15 ` Arnd Bergmann
2021-12-22 12:43 ` Guo Ren
2021-12-22 13:21 ` Arnd Bergmann
2021-12-22 14:00 ` Arnd Bergmann
2021-12-24 9:42 ` Guo Ren
2021-12-21 16:35 ` [PATCH 06/13] riscv: compat: syscall: Add entry.S implementation guoren
2021-12-21 16:35 ` [PATCH 07/13] riscv: compat: Add elf.h implementation guoren
2021-12-21 16:35 ` [PATCH 08/13] riscv: compat: Add COMPAT Kbuild skeletal support guoren
2021-12-21 17:21 ` Arnd Bergmann
2021-12-22 12:06 ` Guo Ren
2021-12-24 6:54 ` Christoph Hellwig
2021-12-21 16:35 ` [PATCH 09/13] riscv: compat: init: Add hw-cap detect in setup_arch guoren
2021-12-21 16:35 ` [PATCH 10/13] riscv: compat: vdso: Add rv32 VDSO base code implementation guoren
2021-12-21 16:35 ` [PATCH 11/13] riscv: compat: vdso: Add setup additional pages implementation guoren
2021-12-21 16:35 ` [PATCH 12/13] riscv: compat: signal: Add rt_frame implementation guoren
2021-12-21 16:35 ` guoren [this message]
2021-12-21 17:38 ` [PATCH 00/13] riscv: compat: Add COMPAT mode support for rv64 Arnd Bergmann
2021-12-22 12:59 ` Guo Ren
2021-12-22 13:29 ` Arnd Bergmann
2021-12-26 8:22 ` Jisheng Zhang
2021-12-26 12:38 ` Guo Ren
2021-12-26 20:31 ` Arnd Bergmann
2021-12-27 1:16 ` Guo Ren
2021-12-27 2:29 ` Jessica Clarke
2021-12-28 10:45 ` Guo Ren
2021-12-22 12:00 ` Guo Ren
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=20211221163532.2636028-14-guoren@kernel.org \
--to=guoren@kernel.org \
--cc=anup.patel@wdc.com \
--cc=arnd@arndb.de \
--cc=drew@beagleboard.org \
--cc=gregkh@linuxfoundation.org \
--cc=guoren@linux.alibaba.com \
--cc=lazyparser@gmail.com \
--cc=linux-csky@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=liush@allwinnertech.com \
--cc=palmer@dabbelt.com \
--cc=wangjunqiang@iscas.ac.cn \
--cc=wefu@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).