Thursday, September 30, 2010

How to Debug C Program using gdb in 6 Simple Steps

Finally getting to know how to debug in terminal =) Check out this post.


How to Debug C Program using gdb in 6 Simple Steps

gdb command shortcuts

Use following shortcuts for most of the frequent gdb operations.
  • l – list
  • p – print
  • c – continue
  • s – step
  • ENTER: pressing enter key would execute the previously executed command again.
  • c or continue: Debugger will continue executing until the next break point.
  • n or next: Debugger will execute the next line as single instruction.
  • s or step: Same as next, but does not treats function as a single instruction, instead goes into the function and executes it line by line.
  • l command: Use gdb command l or list to print the source code in the debug mode. Use l line-number to view a specific line number (or) l function to view a specific function.
  • bt: backtrack – Print backtrace of all stack frames, or innermost COUNT frames.
  • help – View help for a particular gdb topic — help TOPICNAME.
  • quit – Exit from the gdb debugger.

No comments:

Post a Comment