<<

GDB cheatsheet - page 1 Running next # gdb [] function_name Go to next instruction (source line) but Start GDB (with optional core dump). Break/watch the named function. donʻt dive into functions. # gdb --args line_number finish Start GDB and pass arguments Break/watch the line number in the cur- Continue until the current function re- rent source file. turns. # gdb --pid Start GDB and attach to . file:line_number continue Break/watch the line number in the Continue normal execution. set args named source file. Set arguments to pass to program to Variables and memory be debugged. Conditions print/format Print content of variable/memory locati- run break/watch if on/register. Run the program to be debugged. Break/watch at the given location if the condition is met. display/format kill Conditions may be almost any ex- Like „print“, but print the information Kill the running program. pression that evaluate to true or false. after each stepping instruction. Breakpoints condition undisplay break Set/change the condition of an existing Remove the „display“ with the given Set a new breakpoint. break- or watchpoint. number. delete Examining the stack enable display Remove a breakpoint. backtrace disable display clear where En- or disable the „display“ with the gi- Delete all breakpoints. Show call stack. ven number. enable backtrace full x/nfu

Enable a disabled breakpoint. where full Print memory. Show call stack, also print the local va- n: How many units to print (default 1). disable riables in each frame. f: Format character (like „print“). Disable a breakpoint. u: Unit. frame Watchpoints Select the stack frame to operate on. Unit is one of: watch b: Byte, Set a new watchpoint. Stepping h: Half-word (two bytes) step delete/enable/disable w: Word (four bytes) Go to next instruction (source line), di- Like breakpoints. g: Giant word (eight bytes)). ving into function.

© 2007 Marc Haisenko GDB cheatsheet - page 2 Format Manipulating the program Informations a Pointer. set var = disassemble c Read as integer, print as character. Change the content of a variable to the disassemble d Integer, signed decimal. given value. Disassemble the current function or given location. f Floating point number. return o Integer, print as octal. Force the current function to return im- info args s Try to treat as C string. mediately, passing the given value. Print the arguments to the function of t Integer, print as binary (t = „two“). the current stack frame. u Integer, unsigned decimal. Sources x Integer, print as hexadecimal. directory info breakpoints Add directory to the list of directories Print informations about the break- and watchpoints. expression that is searched for sources. Almost any C expression, including list info display function calls (must be prefixed with a list : Print informations about the „displays“. cast to tell GDB the return value type). list : info locals file_name::variable_name list , Print the local variables in the currently Content of the variable defined in the Shows the current or given source con- selected stack frame. named file (static variables). text. The filename may be omitted. If last is omitted the context starting at info sharedlibrary function::variable_name start is printed instead of centered a- List loaded shared libraries. Content of the variable defined in the round it. info signals named function (if on the stack). set listsize List all signals and how they are cur- {type}address Set how many lines to show in „list“. rently handled. Content at address, interpreted as info threads being of the C type type. Signals List all threads. $register handle Set how to handle signles. Options are: show directories Content of named register. Interesting Print all directories in which GDB sear- registers are $esp (stack pointer), $ebp (no)print: (Donʻt) print a message when ches for source files. (frame pointer) and $eip (instruction signals occurs. pointer). show listsize (no)stop: (Donʻt) stop the program Print how many are shown in the „list“ Threads when signals occurs. command. (no)pass: (Donʻt) pass the to the whatis variable_name Chose thread to operate on. program. Print type of named variable.

© 2007 Marc Haisenko