🛠️ Docker image with QEMU configured for RISC-V emulation. Perfectly suited for cross-debugging RISC-V.
I created this image while I was developing cryptographic optimizations of know algorithms for RISC-V. I installed the riscv-gnu-toolchain
in my MacBook Pro M1 using brew install riscv-tools
. While I succeed installing the cross-compilation toolchain, I couldn't achieve cross-debugging with QEMU in Apple Silicon (building the source didn't work).
Docker image based on Ubuntu with QEMU configured for RISC-V emulation (both system and user space).
qemu-system-riscv32
: System emulation of RISC-V 32 bits;qemu-system-riscv64
: System emulation of RISC-V 64 bits;qemu-riscv32
: User space emulation of RISC-V 32 bits;qemu-riscv64
: User space emulation of RISC-V 64 bits;
- QEMU for RISC-V for cross debugging
-
riscv-gnu-toolchain
for cross-compilation
This image is very useful to create a light linux VM for cross-debugging RISC-V, using qemu
and gdb
(the gdb
required is the one installed together with riscv-gnu-toolchain
). The example/
folder in this repo contain a simple C code used this tutorial:
- Cross-compile your C code for debugging:
riscv64-unknown-elf-gcc example/main.c -static -o -g main.elf
- Run the
qemu-riscv
container sharing the directory the code is being built as a volume, port mapping the port `1234``, and, run bash thru it:
docker run --name=qemu-riscv -dit -v $(pwd):/root -p 1234:1234 paulopacitti/qemu-riscv:latest
docker exec -it qemu-riscv bash
- Inside the container, run QEMU in debug mode with the
-g
flag in port1234
passing your the ELF built:
qemu-riscv64 -g 1234 /root/main.elf
- While QEMU is hanging, in your local machine run
gdb
from theriscv-gnu-toolchain
:
riscv64-unknown-elf-gdb main.elf
- Add breaks, enable features and then add the container as a remoter target:
(gdb) b main
(gdb) tui enable
(gdb) tui reg all
(gdb) target extended-remote :1234
- Now you can debug with
gdb
as you normally would :)