RiscV Debugging With QEMU, GDB, and VSCode
HTML-код
- Опубликовано: 8 сен 2024
- I walk through debugging a bare-metal hello world C program for the Risc-V architecture running under QEMU. I discuss using the GDB client and give bonus coverage for setting up VSCode to use the interactive debugger.
Resources
My prior Risc-V bare metal hello world C video that I referred to in this video is here: • Risc-V Bare Metal C He...
The FreeRTOS Project mentioned with VSCode tips: github.com/Fre...
Blog of QEMU and SBI boot process: popovicu.com/p...
My github repo with source code: github.com/chu...
Footnote
One note that I did not mention in the video...this video was shot on my Mac running Ventura. GDB was installed from homebrew. GDB will not run as is without code signing. A blog post describing how to do that is here: dev.to/jasonel.... I did not use the debugger that supposedly is bundled with the risc-v toolchain, as it is apparently not included (or was not at the time I did this) in the homebrew bottle.
waiting for more videos
Well, I put this out over the weekend...so pretty recent. I have two streams going...Risc-V Logisim SOC build and Risc-V bare metal sw. I am working on a bare-metal MicroPython with a REPL over serial and flash boot, at the moment. I stopped the Logism stream for a time but am planning to pick them back up. Which type are you hoping for?
It is wired that my vscode doesn't display registers on the variables when i run the same launch.json and tasks.json files. I don't know whate the problem is. Actually, there is a "Locals" and "Registers" below "VARIABLES", but there is nothing below "Registers", where I expect "cpu" etc.
by the way, i used gdb-multiarch instead of gdb (x86 by default)
When you set a breakpoint and actually step into the program?
@@chuckbenedict7235 Yes, I did so. And, I git cloned your github repository. When I run the debug with your launch and tasks configuration, I got an error "Unable to start debugging. Unexpected GDB output from command "-target-select remote localhost:1234". Truncated register 22 in remote 'g' packet". So I changed the "gdb" to "gdb-multiarch". This time I could ran the debug program and stop at a breakpoint, however, there is no "cpu" and registers displayed below "Registers" on the left side. 😭 I guess it's the problem of "gdb-multiarch", and I plan to try some other gdb like "riscv64-unknown-linux-gun-gdb".
@chuckbenedict7235 thank you for this helpful video. At the first time I run debug mode on qemu using vscode and i've got this error. can you help me? I am using ubuntu Ubuntu 22.04.4 LTS . This is my terminal:
tuanlv@tuanlv-E6530:~/riscv-helloworld-c-gcc$ gdb hello.elf -q -ex 'target remote :1234'
Reading symbols from hello.elf...
Remote debugging using :1234
warning: while parsing target description (at line 1): Target description specified unknown architecture "riscv:rv32"
warning: Could not load XML target description; ignoring
Truncated register 22 in remote 'g' packet
(gdb) b _start
Breakpoint 1 at 0x80000000: file start.s, line 9.
(gdb) c
The program is not being run.
(gdb)
oh. I fixed it. I need to use: riscv64-unknown-elf-gdb hello.elf -q -ex 'target remote: 1234'
It worked!