gdb is a useful debugger
for c segmentation faults, you may also want address sanitizer
useful commands ¶
gdb has tons of commands. these are the ones i use most often.
abbrev | command | description |
r | run | start execution, from the beginning |
b | break | create a breakpoint |
d | delete | delete a breakpoint or clear all breakpoints |
s | step | do one instruction |
n | next | step until the next line |
f | frame | show where you are in execution again |
fin | finish | step until the current funtion returns |
l | list | show the source code |
p | print | get the value of variable |
bt | backtrace | show the backtrace |
logging ¶
enable logging to gdb.txt
with set log en on
(short for set
logging enabled on
)
full backtrace ¶
an extra verbose backtrace can be obtained with bt full
. if the
program has multiple threads, this can be applied to all of them with
th a a bt full
(short for thread apply all backtrace full
)
debuginfod ¶
gdb supports an automatic debug symbol downloading service called debuginfod. this means you will usually not have to go search for a package providing debug symbols for some library and restart your debugging.