Home >Backend Development >C++ >Quick debugging with gdb
Here's my routine to debug quick stuff on the cli:
$ gcc myprogram.c -g -o myprogram $ gdb -tui myprogram (gdb) break main (gdb) run
You will have the program running and stopped at main. After this, here are the commands I use the most:
Command | Short version | Description |
---|---|---|
step | s | Step in |
next | n | Step over |
until 123 | unt 123 | Run until line 123 |
info locals | i lo | Prints local variables |
print myvar | p myvar | Prints myvar value once |
display myvar | disp myvar | Displays myvar value on every execution |
undisplay myvar | und myvar | Stops displaying myvar value |
set myvar = 0 | s myvar = 0 | Sets the value of myvar to 0 |
break 456 | b 456 | Adds a breakpoint on line 456 |
info breakpoints | i b | Lists all breakpoints |
delete | d | Delete all breakpoints |
list main | l main | Go to function main |
list foo.c:789 | l foo.c:789 | Go to file foo.c on line 789 |
where | whe | Prints where the execution is at right now |
kill | k | Kills the current execution |
Ctrl-l refreshes the screen if need. focus cmd makes the arrow keys work on the command line, focus src makes it scroll the source code being displayed.
The above is the detailed content of Quick debugging with gdb. For more information, please follow other related articles on the PHP Chinese website!