This is an old revision of the document!
Table of Contents
GDB
Cheat sheet
Starting
- #
gdb <prog-file> - #
gdb –args <prog-file> <prog-args…>: start gdb with program arguments - #
gdb <prog-file> <core-file>: inspect the core dump - #
gdb <prog-file> <pid>: attach to the running process - #
gdb –pid=<pid> –batch -ex gcore: dump the core of an alive process
Running
run <prog-args…>(short “r”) : start the programstep [count](short “s”) : step one linestepi [count](short “si”) : step one instructionnext [count](short “n”) : step one line without entering in functionscontinue(short “c”) : continue the programfinish(short “fin”) : execute until selected stack frame returnsadvance [source-file]:<line>(short “adv”) : continue up to the given locationcall <func-name>(short “ca”) : call a function (the context is copied so that it is not modified)kill(short “k”) : stop the program
Navigating
backtrace(short “bt”) : show the stackframe <frame-number>(short “f”) : move to the stack drame numberlist,list -,list [source-file]:<line|function>(short “l”) : show source code
Threads
thread <thread-num>(short “t”) : switch to threadinfo threads(short “i th”) : show list of current threadsthread apply all bt(short “t a a bt”) : show backtraces of all threads
Breakpoints
break [source-file]:<line|function> [thread <thread-num>] [if <condition>](short “b”) : set a breakpointinfo breakpoints(short “i b”) : show all current breakpointscondition <breakpoint-number> <condition>(short “cond”) : specify the breakpoint to break only if condition is truedelete breakpoints <breakpoint-number>(short “del b”, “del”) : delete a breakpointenable/disable <breakpoint-numbers…>(short “en” and “dis”) : enable or disable some breakpoints
Inspecting data
print <var-name>(short “p”) : print the value/content of the variableprint *<pointer>@<nelements>: print nelements of the arrayprint/<format> <var-name>: print with a certain format (x for hexa, …)display <var-name>(short “disp”) : display the value/content of the variable at every stepawatch <var-name>(short “aw”) : stops the execution whenever the variable is read or writtenwatch <cond-on-var>(short “wa”) : stops the execution whenever the condition on the variable becomes trueptype <var-name>: type of variablex <addr>: print the content of memory, can format with /<format> tooset variable <var-name> = <value>: change variable valueset $variable = <exp>: create an external variable
Automation
source <file-name>: load a set of commands from a file- You can define macros in ~/.gdbinit, eg to automatically set some breakpoints.
