Compile your program with -g
flag and run your program using gdb: gdb yourprogname
.
From there, you can debug using GDB commands. Use help
to list commands and their options.
?inline Set a breakpoint to pause execution at a certain line or a function:
break main
b 42
?inline Run your program inside gdb after setting breakpoints:
run
r
?inline Print value of expression:
print my_var
p (char) ch
?inline
Execute next line of code, where next
stays in the function and step
enters functions:
n
s
?inline Continue execution until (Nth) next breakpoint
continue
c 3
?inline Print backtrace of all or N stack frames:
backtrace -full
bt 3
?creditFooter 847492919136354364