[Lldb-commits] [PATCH] D159101: [RISC-V] Add RISC-V ABI plugin
Ted Woodward via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Aug 29 11:30:25 PDT 2023
ted added a subscriber: labath.
ted added a comment.
With this change, I'm able to debug RISC-V 32 and 64 bit applications using Linux user space QEMU, using @labath 's QemuUser platform. Simple expression parsing with the IR Interpreter is working. Complex expression parsing with JIT is not tested.
Here's an example of a simple debug session:
> bin/lldb
(lldb) platform select qemu-user
Platform: qemu-user
Triple: x86_64-*-linux-gnu
OS Version: 5.4.0 (5.4.0-136-generic)
Hostname: 127.0.0.1
WorkingDir: /local/mnt/ted/upstream/full
Kernel: #153~18.04.1-Ubuntu SMP Wed Nov 30 15:47:57 UTC 2022
(lldb) file ~/lldb_test/factrv32
Current executable set to '/usr2/tedwood/lldb_test/factrv32' (riscv32).
(lldb) b main
Breakpoint 1: where = factrv32`main + 28 at factorial.c:32:8, address = 0x000104ea
(lldb) target list
Current targets:
* target #0: /usr2/tedwood/lldb_test/factrv32 ( arch=riscv32-*-linux, platform=qemu-user )
(lldb) r
Process 1 launched: '/usr2/tedwood/lldb_test/factrv32' (riscv32)
Process 1 stopped
* thread #1, stop reason = breakpoint 1.1
frame #0: 0x000104ea factrv32`main(argc=1, argv=0x40800604) at factorial.c:32:8
29 }
30 */
31
-> 32 base = 10;
33
34 printf("Factorial of %d is %d\n", base, factorial(base));
35 return 0;
(lldb) s
Process 1 stopped
* thread #1, stop reason = step in
frame #0: 0x000104ee factrv32`main(argc=1, argv=0x40800604) at factorial.c:34:37
31
32 base = 10;
33
-> 34 printf("Factorial of %d is %d\n", base, factorial(base));
35 return 0;
36 }
37
(lldb)
Process 1 stopped
* thread #1, stop reason = step in
frame #0: 0x00010488 factrv32`factorial(i=10) at factorial.c:6:7
3
4 int factorial(int i)
5 {
-> 6 if (i == 1)
7 return 1;
8 else
9 return i * factorial(i - 1);
(lldb)
Process 1 stopped
* thread #1, stop reason = step in
frame #0: 0x000104a4 factrv32`factorial(i=10) at factorial.c:9:12
6 if (i == 1)
7 return 1;
8 else
-> 9 return i * factorial(i - 1);
10 }
11
12 int main(int argc, char **argv)
(lldb)
Process 1 stopped
* thread #1, stop reason = step in
frame #0: 0x00010488 factrv32`factorial(i=9) at factorial.c:6:7
3
4 int factorial(int i)
5 {
-> 6 if (i == 1)
7 return 1;
8 else
9 return i * factorial(i - 1);
(lldb)
Process 1 stopped
* thread #1, stop reason = step in
frame #0: 0x000104a4 factrv32`factorial(i=9) at factorial.c:9:12
6 if (i == 1)
7 return 1;
8 else
-> 9 return i * factorial(i - 1);
10 }
11
12 int main(int argc, char **argv)
(lldb)
Process 1 stopped
* thread #1, stop reason = step in
frame #0: 0x00010488 factrv32`factorial(i=8) at factorial.c:6:7
3
4 int factorial(int i)
5 {
-> 6 if (i == 1)
7 return 1;
8 else
9 return i * factorial(i - 1);
(lldb)
Process 1 stopped
* thread #1, stop reason = step in
frame #0: 0x000104a4 factrv32`factorial(i=8) at factorial.c:9:12
6 if (i == 1)
7 return 1;
8 else
-> 9 return i * factorial(i - 1);
10 }
11
12 int main(int argc, char **argv)
(lldb)
Process 1 stopped
* thread #1, stop reason = step in
frame #0: 0x00010488 factrv32`factorial(i=7) at factorial.c:6:7
3
4 int factorial(int i)
5 {
-> 6 if (i == 1)
7 return 1;
8 else
9 return i * factorial(i - 1);
(lldb)
Process 1 stopped
* thread #1, stop reason = step in
frame #0: 0x000104a4 factrv32`factorial(i=7) at factorial.c:9:12
6 if (i == 1)
7 return 1;
8 else
-> 9 return i * factorial(i - 1);
10 }
11
12 int main(int argc, char **argv)
(lldb)
Process 1 stopped
* thread #1, stop reason = step in
frame #0: 0x00010488 factrv32`factorial(i=6) at factorial.c:6:7
3
4 int factorial(int i)
5 {
-> 6 if (i == 1)
7 return 1;
8 else
9 return i * factorial(i - 1);
(lldb) bt
* thread #1, stop reason = step in
* frame #0: 0x00010488 factrv32`factorial(i=6) at factorial.c:6:7
frame #1: 0x000104b0 factrv32`factorial(i=7) at factorial.c:9:16
frame #2: 0x000104b0 factrv32`factorial(i=8) at factorial.c:9:16
frame #3: 0x000104b0 factrv32`factorial(i=9) at factorial.c:9:16
frame #4: 0x000104b0 factrv32`factorial(i=10) at factorial.c:9:16
frame #5: 0x000104f8 factrv32`main(argc=1, argv=0x40800604) at factorial.c:34:43
frame #6: 0x000106f0 factrv32`__libc_start_main(main=(factrv32`main at factorial.c:13), argc=1, argv=0x40800604, init=(factrv32`__libc_csu_init at elf-init.c:69:1), fini=(factrv32`__libc_csu_fini at elf-init.c:97:1), rtld_fini=0x00000000, stack_end=<unavailable>) at libc-start.c:332:16
frame #7: 0x000103d8 factrv32`_start at start.S:61
(lldb) dis
factrv32`factorial:
0x1047c <+0>: addi sp, sp, -32
0x1047e <+2>: sw ra, 28(sp)
0x10480 <+4>: sw s0, 24(sp)
0x10482 <+6>: addi s0, sp, 32
0x10484 <+8>: sw a0, -16(s0)
-> 0x10488 <+12>: lw a0, -16(s0)
0x1048c <+16>: li a1, 1
0x1048e <+18>: beq a0, a1, 0x10496
0x10492 <+22>: j 0x104a4
0x10496 <+26>: j 0x1049a
0x1049a <+30>: li a0, 1
0x1049c <+32>: sw a0, -12(s0)
0x104a0 <+36>: j 0x104c2
0x104a4 <+40>: lw a0, -16(s0)
0x104a8 <+44>: sw a0, -20(s0)
0x104ac <+48>: addi a0, a0, -1
0x104ae <+50>: jal 0x1047c
0x104b0 <+52>: mv a1, a0
0x104b2 <+54>: lw a0, -20(s0)
0x104b6 <+58>: mul a0, a0, a1
0x104ba <+62>: sw a0, -12(s0)
0x104be <+66>: j 0x104c2
0x104c2 <+70>: lw a0, -12(s0)
0x104c6 <+74>: lw ra, 28(sp)
0x104c8 <+76>: lw s0, 24(sp)
0x104ca <+78>: addi sp, sp, 32
0x104cc <+80>: ret
(lldb) c
Process 1 resuming
Factorial of 10 is 3628800
Process 1 exited with status = 0 (0x00000000)
(lldb)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D159101/new/
https://reviews.llvm.org/D159101
More information about the lldb-commits
mailing list