Locate a Bug

There are several ways methods to locate a bug:

  • 202203061248#
  • 202207091744# (useful on preconditions, post conditions and invariants)
  • backtracking from where you think the problem occurred
  • divide-and-conquer by halving the codes (binary search)
  • use tracing statements (printing messages as simple as “got here” or “value of x is 2” to the screen or the following, suggested by Hunt et al.) and/or logging facilities
  • comment out code that is not involved in bug reproducing
  • make problem worse
  • scientific method (making hypothesis and verify it)
  • Check the variable’s surrounding memory area (if it is corrupted)

Note: Tracing statements and the log file should be in a regular, consistent format so one could read or parse them easily.

Deterministic Problems

To locate a deterministic problem:

  • Review logs
  • Add assertions to verify invariants
  • Use iterative debuggers, using divide-and-conquer
  • Or, add assertions, using divide-and-conquer

Non-Deterministic Problems

To locate a non-deterministic problem:

  • Review logs
  • Create a debug build
  • Add assertions to verify invariants
  • Add assertions, and/or commenting out code, using divide-and-conquer
  • Try to make the problem worse
  • Use low-overhead debugging tools
Links to this page
#debugging