ZSI / Debugging

Debugging

Základy softvérového inžinierstva

Sergej Chodarev (sergejx.net)

Write code without errors!

The End

But mistakes happen

A Bug

Debugging

Prevention

There are two ways to write code:
write code so simple there are obviously no bugs in it,
or write code so complex that there are no obvious bugs in it.

Tony Hoare

Collect information

Error Tracking

Logging

Tools

What about growing log files?

Log Rotation

What if a bug occurs anyway?

Don’t Panic

This is true for galactic hitchhikers and for developers.

The Pragmatic Programmer

What do we need?

Proces

  1. Reproduce
  2. Diagnose
  3. Fix
  4. Reflect

1. Reproduce

Generally, if you can’t reproduce it, it’s almost impossible to fix.

— Anonymous programmer, Practices of Software Maintenance, Janice Singer

Reproduce

Simplify Reproduction

Failing Test Before Fixing Code

Create a focussed test that reveals the bug before you try fixing it.

The Pragmatic Programmer

2. Diagnose

Read the Damn Error Message

Most exceptions tell both what failed and where it failed. If you’re lucky you might even get parameter values.

The Pragmatic Programmer

Scientific Method

Instrumentation

Heisenbug

Divide and Conquer

Version Comparison

Focus on differences

Debugger

Debugger

3. Fix

Fix

4. Reflect

The six stages of debugging

  1. That can’t happen.
  2. That doesn’t happen on my machine.
  3. That shouldn’t happen.
  4. Why is that happening?
  5. Oh, I see.
  6. How did that ever work?

Reflection

Conclusion