Table of Contents

Debugging Process

(1) Describe the problem

  • Write down the problem in a text file, bug tracker or on a piece of paper.
  • Describe the expected result and the observed result.
  • State all relevant facts which are necessary to enable someone else to reproduce the problem, e.g. the operating system and user interaction.
  • If possible, there should be a minimal script with which the problem can be demonstrated.
  • Collect all relevant log files and error messages.

(2) Create a concept diagram

Creating a concept diagram helps to get a grasp on all the moving parts involved in the problem.

Identify components involved and their interactions. How is the system supposed to work? Read one tutorial with a setup description each unfamilier component.

(3) Trying stuff until it works

Debugging_ScientificMethod.jpg (Image source: Andreas Zeller, Scientific Method, Creative Commons 1.0)

  1. Analze the systems diagnostic data and its source code. Ask questions.
  2. Formulate a hypothesis ("an educated guess") about the infection chain. Should be testable and falsifiable.
  3. Based on this hypothesis, conduct an experiment to try out a possible step towards the solution.
  4. Based on the observed result, decide whether the hypothesis needs to be refined or rejected.
  5. Repeat these steps until the problem is resolved.

(4) Implement the solution

  • Fix the root cause of the problem, not just the symptoms.
  • If a workaround cannot is necessary, take it as a temporary solution and create a follow-up task.
  • Take preventive measures (e.g. regression tests), so that this class of issue cannot resurface.
  • Refactor the solution along with a clean code checklist.

Tipps and tricks

Seek to understand how the system works

  • What components are involved in the problem and how do they interact?
  • Create a model to reduce the cognitive load (e.g. UML).
  • Reference to the architecture documentation (e.g. arc42).
  • Then use this understanding to locate the problem origin.
  • Read the documentation and manuals.


Figure 1: Example for System Analysis utils, by Brendan Gregg

Divide and conquer

  • Create a new sandbox project.
  • Extract the problematic part from the main project and reproduce the problem there.
  • Remove all code which is not related the actual problem step by step.
  • Then solve the problem.
  • Integrate the solution in the main program.

Scrutinize the error messages

More often than not they are giving hints about what is going wrong. It may be possible to increase the log level to get more detailed information.

Search the internet

Keep a debugging logbook

Everything gets written down, formally, so that you know al all times where you are, where you've been, where you're going, and where you want to get. In scientific work and electronics technology this is necessary because otherwise the problems get so complex you get lost in them and confused and forget what you know and what you don't know and have to give up. – Zen and the Art of Motorsycle Maintenance, Robert M. Pirsig


Figure 2: Don't get lost in the debugging maze

For subtle bugs in large programs, the amount of state you need to keep track of can rapidly get out of hand. (…) This is the point at which you should be writing down every single command you type in any relevant prompts, and every single code change (or, since we have technology, obsessively saving the output of `history`, making commits to test branches, and recording the correlation between them). – Nelson Elhage

Have a positive attitude

  • Replace frustration with curiosity. Every problem is an opportunity for personal growth.
  • Be persisent. There is a solution for every problem, waiting patiently to be found.

Gather program state information


Figure 3: Andreas Zeller, How failures come to be , Creative Commons 1.0

Find out how the infection came to be. Debug log messages and debuggers may be useful for this purpose.

Diff Debugging

Take a break

  • work on different task
  • go home, try again next morning
  • go for a walk
  • fresh air
  • relax
  • sleep

Ask for help

  • If you get stuck, ask your collegues for help.
  • They might be happy to help you out.
  • If you cannot find a solution together, consider posting the question on Stackoverflow.

Cut the Gordian knot

You might cut the "Gordian knot" by rewriting (parts of) the code.

Debugging stories


Why Programs Fail

TRAFFIC algorithm

(T)rack: The first step of the debugging algorithm is to track the problem report in the bug tracker database.

(R)eproduce: The problem needs to be reproducible to the developers in order to get fixed.

(A)utomate: The steps to reproduce should be optimized into a minimal test case which can be executed automatically.

(F)ind: Now that we can reproduce the problem fastly, we need to find the origins of the defect by tracking the origins of values.

(F)ocus: In the search of the problem origins we should focus on the usual suspects, e.g. code smells, known infections and earlier defects.

(I)solate: The next step is to isolate the root cause of the infection with the help of the scientific method.

(C)orrection: Finally we can fix the defect and re-run all the tests for verification.