Complile your programm with debug information
gcc -g<0,1,2,3> # 3 shows all debug info
Turn off optimization level
gcc -o<0,1,2,3> # 0 means without optimization
To show to the compilator that we will use gdb to debug use. Within linux platform it’s the same as gcc -g3
gcc -ggdb
Run your executable
gdb ./executable
If we have core dumb (memory image before process crash) and want to restore this moment in memory.
gdb ./executable -c core
to record core dumb we need to run the following command before our executable file
ulimit -c unlimited
If we want to attach to working process
gdb -p pid
info - show info about current state
where - shows stackr/runr/run argsc/continuec/continue breaks-number-to-ignore - continue ignore breakfinish - continue to the end of functionkillq/quitstep (into a function)next (next line of code)until line-numberstepi/nexti step for assembler instructionbreak function/linebreak +/- relative-position
break +3
break filename:linebreak filename:functionbreak ... if conditionbreak line thread tidenable/disablewatch conditionbt/backstrace - show stack framesf/frame [number] - change to frame to [number]up/down number - go up and down inside stackinfo frame - go into stack framelist +n -n - show source codeset listsize num - set source code sizep/print[format] variable print using format (x, o, d, f, c)