Debugging Techniques

My notes of Back to Basics: Debugging Techniques

Relation of report to defects

                                        1..n
/===============\    1..n /========\-------->/=======\
| Problem Report|-------->|Symptoms|         |Defects|
\===============/         \========/<--------\=======/
                                     1..n

Procedure

bool MyJob::Debug(Product const& curr, Problem const& issue)
{
  ReviewProblemReport(curr, issue);
  CharacterizeAndReproduceProblem(curr, issue);
  auto next = Clone(curr);

  while (ReproduceProblem(next) && ResourcesAvailableToRepair(next))
  {
    auto insight  = async(launch::async, &MyJob::UnderstandProblem, this, next);
    auto location = async(launch::async, &MyJob::LocateProblem, this, next);
    auto category = async(launch::async, &MyJob::ClassifyProblem, this, next);
    WaitFor(insight, location, category);

    next = AttemptToRepair(next);
  }

  return (ProblemFixed()) ? Deliver(next), true
                          : PossiblyUpdateResume(), false;
}

ReviewProblemReport

Problem reports can be misleading. Author of report might know much less about the system or have wrong assumptions. Thus: distinguish between facts and guesses, maybe get clarification.

Characterizing

Determining the environment (version, platform, config, ...) in which symptoms were observed.

Reproducing

Understanding the Problem

Gain enough knowledge that you believe you can carry out a repair.

  1. locate incorrect lines
  2. determine root cause
  3. Formulate a set of proposed changes
  4. How do these changes affect the system?
  5. Do these changes fix the problem?

Locating the Problem

trace logging

generating output describing the program state during execution.

Tools

assertions

Check pre-, post-conditions, invariants.

backtracking

binary search

simplification

Gradually remove sections of irrelevant code/input.

make the problem worse

Force failures more frequently.

scientific method

  1. Form hypothesis consistent with observation.
  2. Implement tests to refute hypothesis.
  3. If refuted: for new hypothesis.
  4. Repeat until hypothesis cannot be refuted.

Classifying the problem

Repairing the problem

Delivering the fix