Geeks With Blogs
Josh Reuben
Last year I spent some time debugging Qt C++11 code using the GNU Debugger GDB https://www.gnu.org/software/gdb/ (as well as profiling with Valgrind http://valgrind.org/ ).
To skill up on this, I read the "Art of Debugging with GDB, DDD & Eclipse" http://www.amazon.com/The-Art-Debugging-GDB-Eclipse/dp/1593271743 (from the excellent as always No-Starch Press). I got to know its command syntax - here are my notes, for the next time I dive back into C++ !

  •     run p a       - execute a program p under debug. can pass in args a
Breakpoints:
  •     break n/f   - break at line n / at function f
  •     tbreak n     - temporary breakpoint - break once
  •     condition b (c)  - specify condition for breakpoint b
  •     break b if (c)  - combine break & condition into 1 line
  •     catch e       - catchpoint for event e
  •     info break   - list breakpoints + #times they have been hit
  •     delete n     - delete breakpoint n
  •     clear f     - delete breakpoint at function f
  •     disable b   - disable breakpoints
  •     enable b     - enable breakpoints
  •     enable once b
  •     commands b   - execute command list when a breakpoint is hit
Stepping through:
  •     next         - step over
  •     step         - step in
  •     finish       - step out
  •     until       - step out of a recursive function or a loop
  •     continue     - resume
  •     jump n       - move the program counter to a different code location
Macros:
  •     define m     - define a macro
  •     end         - end command list / macro definition
  •     show user   - show list of macros
Navigating:
  •     list f       - list the contents of a function in the code pane --> switch between source files to give it focus
  •     Ctrl XA       - toggle TUI mode
  •     Ctrl P / N   - switch to previous / next source file
  •     i           - switch focus to command pane
  •     esc         - switch focus to code pane
  •     j/k         - down / up navigation in source pane
  •     /           - search in source pane
Inspecting:
  •     watch x      - create a watchpoint on a variable change / condition
  •     frame n      - look at a specific stack frame
  •     up / down    - navigate call stack
  •     backtrace    - show the entire stack
  •     disassemble - show machine code
  •     p/x         - print in hex format. other formats: c, s , f (char, string, float)
  •     $pc         - current location
  •     print x     - print the value of a variable
  •     printf       - formatted print
  •     display *x   - automatically print an object whenever a breakpoint is hit
  •     p *a@n     - print out n elements of dynamic array a
  •     ptype o     - print out a C++ object's class definition
  •     info locals - print out local vars
  •     examine     - examine the memory at a particular address
  •     enable d     - enable a display
  •     disable d   - disable a display
  •     delete d     - delete a display
  •     info args   - print out args
  •     p *$1       - print out something from the value history
  •     p errno     - print error code
  •     strace c     - print trace - shows system calls for a command
  •     info threads        - determine what each thread is doing. (after this, bt).
  •     x/4w $esp   - examine memory (x) - eg 4 words (4w) at the stack pointer ($esp)
Interacting with program under debug:
  •     call f       - call a function - eg from a breakpoint command list
  •     set x=v     - set a variable x to a value v
  •     set args     - for next run
  •     set $q = p   - create a debugger variable that points to some memory address
  •     thread t     - switch to thread t
  •     break b thread t if (c) - combo
misc:
  •     ENTER       - repeat last command
  •     handle       - dont break on signals
  •     help
  •     quit
While this year I have focused mainly on Scala, I am now investigating Scala JNI docs.oracle.com/javase/7/docs/technotes/guides/jni(or Swig www.swig.org/ ) for wrapping a native library (CGAL www.cgal.org/ ) for use in Spark spark.apache.org/ - as I have not yet had the time to investigate LLDB, this refresher may come in handy !
Posted on Friday, October 9, 2015 11:56 AM C++ | Back to top


Comments on this post: GDB - notes from the field

# Ball valve Manufacturers|Balancing Valve|Industrial Valve|castlevalves.com
Requesting Gravatar...
nice post thanks
Left by prem on Oct 09, 2015 2:32 PM

# re: GDB - notes from the field
Requesting Gravatar...
Great information! It is something very important to learn now. - Dr. Thomas Devlin
Left by Robert Nyers on Jan 04, 2017 11:43 AM

Your comment:
 (will show your gravatar)


Copyright © JoshReuben | Powered by: GeeksWithBlogs.net