====== GDB ====== ===== Cheat sheet ===== ==== Starting ==== * **# ''gdb ''** * **# ''gdb --args ''** : start gdb with program arguments * **# ''gdb ''** : inspect the core dump * **# ''gdb ''** : attach to the running process * **# ''gdb --pid= --batch -ex gcore''** : dump the core of an alive process ==== Running ==== * **''run ''** (short "r") : start the program * **''step [count]''** (short "s") : step one line * **''stepi [count]''** (short "si") : step one instruction * **''next [count]''** (short "n") : step one line without entering in functions * **''continue''** (short "c") : continue the program * **''finish''** (short "fin") : execute until selected stack frame returns * **''advance [source-file]:''** (short "adv") : continue up to the given location * **''call ''** (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 stack * **''frame ''** (short "f") : move to the stack drame number * **''list''**, **''list -''**, **''list [source-file]:''** (short "l") : show source code ==== Threads ==== * **''thread ''** (short "t") : switch to thread * **''info threads''** (short "i th") : show list of current threads * **''thread apply all bt''** (short "t a a bt") : show backtraces of all threads ==== Breakpoints ==== * **''break [source-file]: [thread ] [if ]''** (short "b") : set a breakpoint * **''info breakpoints''** (short "i b") : show all current breakpoints * **''condition ''** (short "cond") : specify the breakpoint to break only if condition is true * **''delete breakpoints ''** (short "del b", "del") : delete a breakpoint * **''enable/disable ''** (short "en" and "dis") : enable or disable some breakpoints ==== Inspecting data ==== * **''print ''** (short "p") : print the value/content of the variable * **''print *@''** : print nelements of the array * **''print/ ''** : print with a certain format (x for hexa, ...) * **''display ''** (short "disp") : display the value/content of the variable at every step * **''awatch ''** (short "aw") : stops the execution whenever the variable is read or written * **''watch ''** (short "wa") : stops the execution whenever the condition on the variable becomes true * **''ptype ''** : type of variable * **''x ''** : print the content of memory, can format with / too * **''set variable = ''** : change variable value * **''set $variable = ''** : create an external variable ==== Automation ==== * **''source ''** : load a set of commands from a file * You can define macros in ~/.gdbinit, eg to automatically set some breakpoints.