Sie sind auf Seite 1von 2

gdb Cheat Sheet

GDB Cheat Sheet =============== Start up gdb with a program: >gdb programName --OR-- run gdb from within emacs. This is preferable, as you can then have multiple buffers open showing you context, etc. Start emacs and type: M-x gdb Very helpful to use the speedbar while debugging to aid in visiting files and switching between buffers (gdb) [RET] Repeat previous comamnd. After you have entered a command once, hitting return repeats that command. For example, (gdb) n steps one command. Then just hit return to continue stepping. Set a breakpoint at the entry point to main Run to first breakpoint Runs to the beginning of main Run to first breakpoint, using a command-line arg Next command (step over) Backtrace, shows where in the stack from you are "s"tep into a function Go up # levels in the call stack. Eg, "up 1" shows cur. call

(gdb) break main (gdb) run (gdb) start (gdb) run CL_arg (gdb) n (gdb) bt (gdb) s (gdb) up # ing function.

Use "finish" to step out of current function. (gdb) file execName Starts a new file to be debugged (can use tabbing and d ired to find). (gdb) info breakpoints Displays all break points. "info b" also works (gdb) C-x [SPACE] Within gdb mode in emacs, sets a BP at the point in the source file you are editing. (gdb) break NS::ClasssName::FunctionName Set a breakpoint in a namespace, class, function (gdb) break NS1::NS2::ClasssName::FunctionName Set a breakpoint in nested namespaces, class, function Can type tab during entering of the namespace / class / function for emacs-like auto-completion. (gdb) break filename:line# Set a breakpoint in a file at the line #. (gdb) l "l"ist source lines for context (lists several lines above and below current line). (gdb) info locals shows local variable values (gdb) return (exp) steps out of a function. (exp) will optionally override actual return val. (gdb) continue re-start program execution. (gdb) disable # Disable the breakpoint # (use "info breakoints" to see breakpoint numbers). (gdb) enable # Enables BP # (gdb) delete # Deletes BP # (also "d #") (gdb) delete Deletes all BPs (also "d") (gdb) finish Continues until current function has ended (gdb) until NS1::NS2::ClasssName::FunctionName Runs until reaches this point or another line past this. Can use filename:line# syntax like break.

(gdb) print var Prints the contents of a variable (gdb) print vect[1].val() prints from a vector called vect, the [1] positioned element, the value returned by calling the function val(). (gdb) display var Display the value of var after each step (gdb) kill Kill execution of program being debugged. (gdb) quit Quit gdb altogether (gdb) cd ... cd to a new working directory. This sets the cwd for the session (in case you want to start the session in a differen t working directory than the one where the exe is located.) (gdb) print var.px->func() how to print the value a function from a variable that is a boost::smart_ptr. (gdb) break [place] if cond breaks at [place] (choose a place as with BPs abo ve) if the condiditon cond is met. EX: (gdb) break TestGame.cpp:250 if (boolVar == false) (gdb) where ------------A lot of commands can be accessed by: M-x gdb-xxxxxxxx where the xxxxxxx is a gbd command. - display local vars in a separate buffer Displays where you are as well as the calling chain (the sequence of func calls that lead us to this point.)

M-x gdb-display-locals-buffer

Das könnte Ihnen auch gefallen