gcc -g -o hello hello.c
- -g
flag adds debugging information to the executable
gdb ./a.out
- Attach debugger to the program
(gdb) help
(gdb) help <section>
(gdb) run or r // Run Program
(gdb) run arg1 arg2 .. // Command line arguments of the program
(gdb) list or l// list specified function or filw
(gdb) list main // list function main
(gdb) help breakpoint
(gdb) break or b // Sets breakpoint at specified line or function
(gdb) break main // Sets a Breakpoint at statrting of main function
(gdb) run // runs the program and stops at breakpoint
(gdb) next or n // step to the next line
(gdb) n // step to next line
(gdb) print (or p) var // prints the value stored in the variable
(gdb) continue or c // Continue execution till next breakpoint
(gdb) quit // Quit gdb