blob: 620f4118667ddb1438570280d565df3ced724aec [file] [log] [blame] [view]
gkielian1c4a1fd2021-03-24 14:35:53 -07001# Qemu Vector Testing and Debugging
2
31. [Qemu Setup](#qemu-setup)
4 1. [Build steps:](#build-steps)
5 2. [Start Qemu](#start-qemu)
6 3. [Exiting Qemu](#exiting-qemu)
gkieliand5dc6162021-04-01 15:07:58 -070072. [Running GDB](#running-gdb)
8 1. [Use the following command to run GDB](#use-the-following-command-to-run-gdb)
93. [GDBGUI Setup](#gdbgui-setup)
10 1. [Installing gdbgui](#installing-gdbgui)
gkielian1c4a1fd2021-03-24 14:35:53 -070011 2. [Running gdbgui](#running-gdbgui)
12 3. [gdbgui window](#gdbgui-window)
gkieliand5dc6162021-04-01 15:07:58 -0700134. [GDB Usage](#gdb-usage)
gkielian1c4a1fd2021-03-24 14:35:53 -070014 1. [Some Useful GDB instructions](#some-useful-gdb-instructions)
gkieliand5dc6162021-04-01 15:07:58 -0700155. [Aliases for convenience](#aliases-for-convenience)
166. [Advanced Usage](#advanced-usage)
gkielian1c4a1fd2021-03-24 14:35:53 -070017 1. [Debugging Qemu](#debugging-qemu)
18
19## Qemu Setup
20
21### Build steps:
22
23```
24source build/setup.sh
25m tools
26m qemu
27```
28
29### Start Qemu
30
31Use the following command to start qemu with debugging:
32
33```
34qemu-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
35```
36
37Notes on above command:
38
39- `-s` - starts the gdb server
40- `-S` - waits on execution for a client to connect
41
42The above commands can be omitted to run qemu without starting a gdb server.
43
44### Exiting Qemu
45
46To exit qemu, in the same teriminal, press `Ctrl-a` then `Ctrl-x`.
47
gkieliand5dc6162021-04-01 15:07:58 -070048## Running GDB
49
50### Use the following command to run GDB
51
52Run GDB to create a gdb session in the CLI:
53
54```
55$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"
56```
57
gkielian1c4a1fd2021-03-24 14:35:53 -070058## GDBGUI Setup
59
gkieliand5dc6162021-04-01 15:07:58 -070060### Installing gdbgui
gkielian1c4a1fd2021-03-24 14:35:53 -070061
62`python3 -m pip install gdbgui`
63
64### Running gdbgui
65
66Use the following command to begin gdbgui:
67
68```
gkieliand5dc6162021-04-01 15:07:58 -070069export 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\""
gkielian1c4a1fd2021-03-24 14:35:53 -070070```
71
72### gdbgui window
73
74lower left window takes conventional gdb commands.
75
76To start, set up a breakpoint (e.g. `b main`), then hit continue (`c`)
77
78![image of gdbgui](./gdbgui.png)
79
gkielian1c4a1fd2021-03-24 14:35:53 -070080## GDB Usage
81
82With one of the gdb methods working, you can now step through and check
83register contents.
84
85### Some Useful GDB instructions
86
87- `break main` (or `b main` for short) - makes a breakpoint at the main, more
88 info [here](https://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_27.html)
89- `continue` (or `c` for short) - runs until breakpoint
90- `step` (or `s` for short) - runs one more line, will "step into" subroutines
91- `next` (or `n` for short) - runs one more line, will "step over" subroutines
92- `info reg` - print all registers
93- `info reg a1` - print scalar register a1
94- `info vector` - print all vector registers and vector csr's
95
96## Aliases for convenience
97
98First source `build/setup.sh` to set up the enviroment in the respective
99terminal, and then these aliases can speed up the workflow:
100
101```
gkieliand5dc6162021-04-01 15:07:58 -0700102alias 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\""
103alias 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\"'"
gkielian1c4a1fd2021-03-24 14:35:53 -0700104alias 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"
105```
106
107## Advanced Usage
108
109### Debugging Qemu
110
111```
112gdb --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
113```
114
115Above starts up qemu with the debugger and breaks the simulator on the
116`vsetvl` instruction so that you can check the state of the cpu.
117
gkieliand5dc6162021-04-01 15:07:58 -0700118This may be useful when debugging qemu itself.