Debugging C Program using gdb Step 1. Compile the C program with debugging option -g Compile your C program with -g option. This allows the compiler to collect the debugging information. Eg: $cc -g test.c //test.c is the sample program to debug Step 2. Launch gdb Launch the C debugger (gdb) as shown below. $gdb a.out Step 3. Set up a break point inside C program Syntax: break [file_name]:line_number Eg: break test.c:3 // this will set a break point at line number3 Places break point in the C program, where you suspect errors. While executing the program, the debugger will stop at the break point, and gives you the prompt to debug. Step 4. Execute the C program in gdb debugger You can start running the program using the run command in the gdb debugger. Eg: run [args] // args are optional Step 5. Printing the variable values inside gdb debugger Syntax: print {variable} Example: print i Step 6. Continue, stepping over and in – gdb comm
EST 102 Programming in C Theory and Lab-KTU FIRST YEAR 2019 scheme - Dr.Binu V P, 9847390760