∆ of what you have to what you want

It's an inefficient way to find and fix bugs — it can consume your project!

Before you debug:

Methods for preventing bugs

Debugging Strategy

Debugging Commands

(gdb) r a b # run the program with given argument
(gdb) stepi # step in into one machine code
(gdb) step (s)# single step through the source code
(gdb) next (n) # go to the next sourcecode line within function
(gdb) fin # finishes execution of function
(gdb) b <label> # add a breaking point on the given label
(gdb) c # continue till next break point/return
(gdb) info break # gives out information of breakpoints
(gdb) ^C # to regain control of the program being debugged
(gdb) bt # backtrace the function
# once in backtrace
	(gdb) up # going up in the backtrace
	(gdb) down # going donw in the backtrace
# the backtrace process is basically exploring a program execution
(gdb) p <EXPR> # evalutae EXPR and print the result
               # we are actually executing <EXPR> in the debugging program
					     # create machine code and put into memory and executes it 
(gdb) set cwd /etc # change the working directory of the program
(gdb) set env PATH /usr/bin:/Bin # change the environment for the program
(gdb) set disable-randomization on/off # turn on/off the security feature that
																			 # runs program in random location in stack
(gdb) attach PID # assuming curr is not running, stop PID and continue w/ curr
(gdb) detach # reverse the attach behavior
(gdb) watch <EXPR> # keep watching the expr until it chanegs
(gdb) rc # like 'c' but "runs" the program in reverse, operates by consulting gdb history
         # only aviliable on several platforms upon request
(gdb) checkpoint # save the program state and gives out an id
(gdb) restart <ID> # restart on checkpoint ID

best strategy: try not to use a debugger when you can...

try use a print statement first

Auxiliary build tools