Debugging
An Introduction
Prof. David Bernstein
James Madison University
Computer Science Department
bernstdh@jmu.edu
Getting to Debugging
Testing
:
The output of a failed test is a symptom and
one of
the trigger conditions that gives rise to the symptom
Debugging:
Using the trigger condition to identify and correct the fault
The Debugging Process
Stabilize
- Understand the symptom and the trigger condition identified by the test so that the failure can be reproduced.
Localize
- Locate the fault.
Examine the sections of code that are likely to be influenced by the trigger condition.
Form a hypothesis about the fault.
Instrument the relevant sections of code.
Execute the code using the instrumentation.
Prove or disprove the hypothesis. If proven, go to step 3; otherwise go to step 2.
Correct
- Fix the fault.
Verify
- Test the fix and run regression tests.
Globalize
- Look for and fix similar defects in other parts of the system. Refactor if necessary.
Nerd Humor
(Courtesy of
xkcd
)
Instrumentation Techniques
Using Debug Code:
Add temporary output statements that can be used to monitor state information
Add temporary input statements that can be used to pause the execution
Using a Debugger:
Use
watches
to monitor state information
Set
breakpoints
to pause the execution
Execute statements "one at a time" (e.g.,
step into
,
step over
)
There's Always More to Learn