Chapter 18 - Debugging

  • debugging is not part of the testing domain
    • separate process performed as a consequence of testing
  • testing phase has two parts: prep, develop and execute tests (testing), if output unsuccessful - failure - new goal to find and remove bug (debugging)
  • debugging: process of identifying failure, tracing bug, locate errors causing it and fixing the errors
    • determine nature of bug
    • fix the bug

Debugging: An Art or Technique?

  • generally an unplanned activity
  • more of an art currently, thinking critically works well

Debugging Process

  • check results from executing tests, only analyze further if a failure
  • if present symptoms insufficient to find bug, do more testing
  • if symptoms sufficient, trace failure to location of error
  • correct bug
  • perform regression testing

Debugging is Difficult

  • often performed under pressure, leading to more pressure (self-induce or organizational)
  • gap b/w faults and failures is large, time-consuming
  • complex design makes debugging slow
  • experience matters
  • sometimes a bug exists without a failure, can be difficult to reproduce the failure

Debugging Techniques

  • memory dump: printout of all registers and relevant memory locations is obtained and studied, slow and inefficient - hard to link back to source program, lots of data, only see state at one instant in time
  • watch points: see value of variables at particular points in time, use output statements, breakpoint execution
  • breakpoint categories: unconditional (inserted & execution stops here), conditional (if expression True, stop), temporary (happens once), internal (set by debugger)
  • single stepping - watch each executable line of code
  • backtracking: observe failure, find site of symptom of failure, trace back to highest abstraction in design collecting all code related to this, slowly isolate module using dataflow and find the bug (if you understand program logic it is effective

Correcting the Bugs

  • evaluate coupling, logic of data structures where corrections are being made
  • understand influence of correction on other modules and plan regression testing
  • perform all the regression testing
  • debugging guidelines: fresh thinking leads to good debugging (don’t spend hours, take a break), don’t isolate the bug from you colleagues (discuss the problem), don’t modify code on first attempt, add test cases, regression testing is a must, design should be referred to before fixing the error

Debuggers

  • debuggers: illustrate dynamic nature of program, understand the program as well to find bugs, control the application to make it easier to test
  • types: kernel debugger, basic machine-level debugger, interpretive programming environment debugger