GCC Debugging/gdb

Preping for the debugger

 * program must first be compiled for debugging:
 * gcc -g  -o
 * eg: gcc -g debug_me.c -o debug_me
 * the "-g" flag is important (To create symbol table)

Starting the debugger

 * start the debugger with:
 * gdb
 * eg: gdb debug_me

common commands

 * run, print, where, break, cond, step, next, set, ignore

run

 * runs the program
 * to pass arguments to the program on run:
 * run
 * eg: run 12 35
 * eg: run "hello world" "goodbye world"

break

 * sets a "breakpoint" at a certain area \ funtion
 * break
 * eg: break main
 * or
 * eg: b main
 * break :
 * eg: break debug_me.c:5
 * eg: break debug_me.c:5

b

 * shorthand for break

next

 * execute next line of code
 * eg: next

step

 * next line of code, stepping into functions
 * eg: step

continue

 * go to next breakpoint or end of program

cont

 * shorthand for continue

print

 * print out a variables \ expressions contents
 * print
 * eg: print x

disp

 * prints out a variable \ expression value every step
 * eg: disp x

undisplay

 * cancel a display command
 * eg: undisplay 3
 * would stop the var at pos 3 from displaying every time

where

 * move within the call stack

up and down

 * up: previous step inside call stack
 * down: next step inside call stack

list

 * shows code at a certain location
 * list
 * code at current location and then at next location if typed again
 * eg: list
 * list -
 * shows code at previous location and then at the location before that if typed again
 * list
 * shows code in funtion definition
 * eg: list func1
 * shows code in funtion definition
 * eg: list func1

cond

 * conditional
 * cond
 * eg: cond 1 val>0
 * stop at breakpoint "1" when "val" becomes greater then 0

set

 * change a value, eg
 * set variable x = 12
 * will change x's value to 12

ignore
ignore a breakpoint for a user specified number of times.

usage: ignore 

ignore 2 20 --> Breakpoint 2 will not be hit for 20 times.

quit

 * exits the gdb

q

 * shorthand for quit