Friday, January 23, 2009

Starting off with GDB

The GNU Debugger is pretty handy when developing applications in C for the Linux platform. Using it is pretty simple...

Compiling for Debug

Compile your program with gcc, adding a "-g" option to include debugging symbols

Example: gcc -g nitin.c

Run with Debugger

Execute GDB, providing the executable as a parameter

Example: gdb a.out

Start Execution

Get into the main method by typing "start main" followed by any parameters

Example: start main hello

Step Through

Go line-by-line by typing "n" or "next"


Display variable values using the "print" command

Example: print argv[1]


Set a breakpoint with the "b" or "break" command followed by the filename:line number

Example: b nitin.c:25


Run till the next breakpoint using "c" or "continue"


Press Ctrl+C to stop execution, and "q" or "quit" to close GDB.

No comments: