< GCC Debugging print
Preping for the debugger
- program must first be compiled for debugging:
- gcc -g <filname.c> -o <output filename>
- 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 <program name>
- eg: gdb debug_me
common commands
- run, print, where, break, cond, step, next, set
run
- runs the program
- to pass arguments to the program on run:
- run <arg1> <arg2>
- eg: run 12 35
- eg: run "hello world" "goodbye world"
break
- sets a "breakpoint" at a certain area \ funtion
- break <function name>
- eg: break main
- or
- eg: b main
- break <filename>:<line of code to stop in>
- 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 out a variables \ expressions contents
- print <variable name>
- 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 <no args>
- 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 <function name>
- shows code in funtion definition
- eg: list func1
cond
- conditional
- cond <breakpoint> <condition>
- 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
quit
- exits the gdb
q
- shorthand for quit
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.