18
GNU Debugger [email protected] Glen Oakley

Debugging With the GNU Debugger

Embed Size (px)

DESCRIPTION

Slides from a lecture on the debugging process and using the GDB.

Citation preview

Page 1: Debugging With the GNU Debugger

GNU [email protected]

Glen Oakley

Page 2: Debugging With the GNU Debugger

What is a debugger?

Page 3: Debugging With the GNU Debugger

The Four Things● Start your program● Make your program stop● Examine what has happened● Change things in your program

Page 4: Debugging With the GNU Debugger

Your Things● Start your program● Break / Watch● Checkpoint● Next / Step / Continue● Backtrace● Print

Page 5: Debugging With the GNU Debugger

ZEROTH...

Page 7: Debugging With the GNU Debugger
Page 8: Debugging With the GNU Debugger

Debugging Flow● Testing Brute-forcing● Identify symptom - what happened?● Identify problem - why?● Locate problem● Blame someone (else)● Fix problem● Repeat with the new problems

Page 9: Debugging With the GNU Debugger

GDB Execution● Run program in ‘virtual’ environment● Run until

○ Termination○ Breakpoint

● Flow control● State Information

Page 10: Debugging With the GNU Debugger

Commands● Run

○ Execute program with args○ Redirection

● Backtrace○ Stack trace of your location in the program○ Identify where crash happened

Page 11: Debugging With the GNU Debugger

Exampleverbose_array.c

Page 12: Debugging With the GNU Debugger

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

Page 13: Debugging With the GNU Debugger

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

Page 14: Debugging With the GNU Debugger

Exampleosh.c

Page 15: Debugging With the GNU Debugger

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

Page 16: Debugging With the GNU Debugger

Examplesudoku.c

Page 17: Debugging With the GNU Debugger

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

Page 18: Debugging With the GNU Debugger

Thanks!

http://glenoakley.com/@goakley123

[email protected]