Debugging With the GNU Debugger
-
Upload
goakley123 -
Category
Technology
-
view
369 -
download
2
description
Transcript of Debugging With the GNU Debugger
Glen Oakley
What is a debugger?
The Four Things● Start your program● Make your program stop● Examine what has happened● Change things in your program
Your Things● Start your program● Break / Watch● Checkpoint● Next / Step / Continue● Backtrace● Print
ZEROTH...
https://sourceware.org/gdb/current/onlinedocs/gdb/
Debugging Flow● Testing Brute-forcing● Identify symptom - what happened?● Identify problem - why?● Locate problem● Blame someone (else)● Fix problem● Repeat with the new problems
GDB Execution● Run program in ‘virtual’ environment● Run until
○ Termination○ Breakpoint
● Flow control● State Information
Commands● Run
○ Execute program with args○ Redirection
● Backtrace○ Stack trace of your location in the program○ Identify where crash happened
Exampleverbose_array.c
Commands● Break
○ Location at which to halt the program○ Breaks before execution of statement(s)
● Watch○ Monitors a variable for changes○ Requires variable to be in scope
● Clear○ Remove breakpoints
Commands● Checkpoint
○ Store the state of the program○ Programs can be restarted at checkpoints
● Step○ Step through the program line by line
● Next○ Execute the next line in the current frame○ Does not step through sub-functions
Exampleosh.c
Commands● Print
○ Show the state of memory/variables○ Works with array and struct/union notation○ Will assume c-strings when applicable○ @ can be used on arrays for grouping prints
● Set Var○ Change memory/variables
● Continue○ Run until another break/watch point is triggered
Examplesudoku.c
Recap● Debugging process is unavoidable● GDB provides assistance
○ If I see one more stray printf()...
● Basic flow control commands○ Allow tracing a stopped program○ Set breakpoints to stop the program○ Enable querying/modifying the program state
Thanks!
http://glenoakley.com/@goakley123