source build/setup.sh m tools m qemu
Use the following command to start qemu with debugging:
qemu-system-riscv32 -M opentitan -kernel $ROOTDIR/out/shodan/build-out/sw_shodan/device/examples/hello_vector/hello_vector_sim_verilator.elf -bios $ROOTDIR/out/shodan/build-bin/sw/device/boot_rom/boot_rom_fpga_nexysvideo.elf -nographic -cpu rv32,x-v=true,vlen=512,vext_spec=v1.0 -s -S
Notes on above command:
-s
- starts the gdb server-S
- waits on execution for a client to connectThe above commands can be omitted to run qemu without starting a gdb server.
To exit qemu, in the same teriminal, press Ctrl-a
then Ctrl-x
.
Run GDB to create a gdb session in the CLI:
$ROOTDIR/cache/toolchain_vp/bin/riscv32-unknown-elf-gdb $ROOTDIR/out/shodan/build-bin/sw/device/examples/hello_vector/hello_vector_sim_verilator.elf --eval-command "target remote :1234"
python3 -m pip install gdbgui
Use the following command to begin gdbgui:
export PURE_PYTHON=1; gdbgui -g "$ROOTDIR/out/host/toolchain_vp/bin/riscv32-unknown-elf-gdb $ROOTDIR/out/shodan/build-bin/sw/device/examples/hello_vector/hello_vector_sim_verilator.elf --eval-command \"target remote :1234\""
lower left window takes conventional gdb commands.
To start, set up a breakpoint (e.g. b main
), then hit continue (c
)
With one of the gdb methods working, you can now step through and check register contents.
break main
(or b main
for short) - makes a breakpoint at the main, more info herecontinue
(or c
for short) - runs until breakpointstep
(or s
for short) - runs one more line, will “step into” subroutinesnext
(or n
for short) - runs one more line, will “step over” subroutinesinfo reg
- print all registersinfo reg a1
- print scalar register a1info vector
- print all vector registers and vector csr'sFirst source build/setup.sh
to set up the enviroment in the respective terminal, and then these aliases can speed up the workflow:
alias run_gdb="$ROOTDIR/cache/toolchain_vp/bin/riscv32-unknown-elf-gdb $ROOTDIR/out/shodan/build-bin/sw/device/examples/hello_vector/hello_vector_sim_verilator.elf --eval-command \"target remote :1234\"" alias run_gdb_gui="export PURE_PYTHON=1; gdbgui -g '$ROOTDIR/cache/toolchain_vp/bin/riscv32-unknown-elf-gdb $ROOTDIR/out/shodan/build-bin/sw/device/examples/hello_vector/hello_vector_sim_verilator.elf --eval-command \"target remote :1234\"'" alias run_qemu="qemu-system-riscv32 -M opentitan -kernel $ROOTDIR/out/shodan/build-out/sw_shodan/device/examples/hello_vector/hello_vector_sim_verilator.elf -bios $ROOTDIR/out/shodan/build-bin/sw/device/boot_rom/boot_rom_fpga_nexysvideo.elf -nographic -cpu rv32,x-v=true,vlen=512,vext_spec=v1.0 -s -S"
gdb --eval-command "b helper_vsetvl" --eval-command "run" --args qemu-system-riscv32 -s -S -nographic -cpu rv32,x-v=true,vlen=512,vext_spec=v1.0,s=true,mmu=true -M opentitan -kernel out/shodan/build-out/sw_shodan/device/examples/hello_vector/hello_vector_sim_verilator.elf -bios out/shodan/build-bin/sw/device/boot_rom/boot_rom_fpga_nexysvideo.elf -nographic
Above starts up qemu with the debugger and breaks the simulator on the vsetvl
instruction so that you can check the state of the cpu.
This may be useful when debugging qemu itself.