Hello, we know how RISC-V GDB and OpenOCD work together to interact with SHAKTI. So now what is debugging? and how risc-v gdb
is used for that, Lets see!.
Have you seen movies where programmers are shown typing so fast that they could pick the keys apart? If only it were that easy! When in reality, it involves a lot less typing and a lot more staring! Mostly because we don’t know where the problem is. Enters GDB! It gives a faster and a very less frustrating way to debug the program. GDB lets you dissect the program and inspect it part by part. So that you can figure out the exact cause of the error.
Now we are going to see the list of various commands used for debugging in RISC-V GDB.
GDB command completion: Use TAB key
info reg
+ TAB will complete the command resulting in info registers.
Press TAB twice to see all available options if more than one option is available.
Starting a GDB session:
Type riscv-unknown-elf-gdb
to invoke the gdb session for this specific architecture.
For instance, use riscv64-unknown-elf-gdb
for 64 bit architecture and riscv32-unknown-elf-gdb
for 32 bit.
Quitting a session:
Press ctrl-d
or quit
or q
RISC-V GDB Commands:
1. File |
Uses the file “filename” as the program to be debugged. Symbols and contents of memory are read. |
file asm-program.elf |
2. Load |
Loads the program into the memory |
load |
3. Set |
changes the value associated with a variable, memory address, or expression that is accessible according to the scope and visibility rules |
set a =10 /set *((char *)0x11304)=67 |
4. Info Registers |
Displays the names and values of all registers except floating-point/CSR registers. |
info reg / i r / info registers |
5. Info all-registers |
Displays the values of all the registers including floating point and csr registers. |
info all-registers / i all-registers |
6. Continue |
Continues running the program until the next breakpoint or error |
|
7. Step in / next in |
Executes one machine instruction, then stops and returns to the debugger |
si / stepi / nexti / ni |
8. Break |
Sets a break point at the specified line number or address or a function. |
break <address> or break *0x00001012 break <line-number> or b 12 break <function-name> or b main or b loop break <file-name>:<line-number> |
9. Info breakpoints |
Displays information about all the breakpoints set inside a program. |
info breakpoints/ info break / i b |
10. info breakpoint <breakpoint-number> |
Displays information about the specific breakpoint |
info breakpoint 1 / info break 1 / i b 1 |
11. Delete |
Deletes all or specific breakpoint |
delete delete <breakpoint-number> or delete 1 or d 1 |
12. Disable |
Disables the breakpoint but not delete it from the memory. You can disable the breakpoints entirely or a specific one. |
disable breakpoints disable disable |
13. Enable |
Enables the breakpoints previously disabled. |
enable breakpoints |
Step-in and Continue:
Continuing means resuming program execution until your program completes normally. In contrast, stepping means executing just one more “step” of your program, where “step” may mean either one line of source code, or one machine instruction.
Delete and Disable:
delete
command deletes the breakpoint whereas disable
command simply disables it, i.e its still available in memory. It can be enabled whenever required using enable
command.
Continue and jump:
Continuing means resuming program execution until your program completes normally. However jump goes to the specified address and resumes execution.
Learn more about Debugging with GDB,
Beginners guide to GDB with SHAKTI
Akshaya currently works at the RISE labs. Her favorite subjects are Web designing and Microprocessors. She loves learning about new things and writing about them!