-
Notifications
You must be signed in to change notification settings - Fork 86
gdb
Simon Gene Gottlieb edited this page Feb 15, 2022
·
1 revision
To use gdb on your tools, you have to compile them with Debug Symbols. This can be done as:
cmake ../test/unit -DCMAKE_BUILD_TYPE=Debug
Now recompile your program and you are ready to go.
gdb has as many other tools, a special file, that it loads configs from. .gdbinit must be placed in your home directory.
Example configuration
catch throw # Always stop the program, if an exception is being thrown
set print pretty on
set print thread-events off # Don't show when threads are being spawned/closed
set history save on # Better save the history data
set history size 2048
set history remove-duplicates unlimited
set history filename ~/.gdbhistory # Save history in home folder
set width 0 # remove annoying messages, when terminal window is small
set height 0
Lets say you have a program with some flags ./my_program --file test.txt --param 2.
To call this you have to call gdb --args ./my_program --file test.txt --param 2.
This will start gdb, but not start the execution of your program.
You will get a command line from gdb. Here you can execute different things:
-
(gdb) run(re-)start your program -
(gdb) break file.cpp:123will set a breakpoint in file.cpp on line 123 -
(gdb) btprint complete call stack -
(gdb) l(list) prints code from current selected call stack -
(gdb) upmoves the call stack up -
(gdb) downmoves the call stack down -
(gdb) p iprints the value of variablei -
(gdb) p size()prints the value of the functionsize() -
(gdb) ccontinues execution until next break point -
(gdb) nexecute the next line -
(gdb) ssteps into the next line (jumps into function calls) -
(gdb) finsteps out of the current function (runs until next 'return') -
(gdb) quitstop gdb (you can also just press Ctrl-D) - pressing Ctrl-C while your program is running, will pause the program and you can inspect it