gdb basics

Step 1:
Create debug enabled binary. Use -g flag for that while compiling
Eg:  cc test.c -g -o test.bin

step 2 :
Run gdb 
Use -tui option to enable text user interface too see the code whike running gdb
Need to pass the binary and c file as argument 
COMMAND: gdb -tui test.bin test.c

Step 3: use the following commands to debug

break <function name> to set break point 
Eg: break main <-----------This sets breakpoint at main.

run
This command will execute the entire program if there is no break point present. 
If break point is present it will halt the execution there.

print <Variable  name> 
To print the variable value.

n
n command executes the next instruction

s
s command steps to next instruction ( if the next line is a function , s command will execute the first line in the function,but n command will execute all the codes in the function and return)

q
q command stops the gdb and exit.

Comments