Software Debugging

Udacity CS259 摘要分享

About this course

強調系統性的方式

強調自動化工具

Agenda

  • How Debuggers work

  • Asserting Expectations

  • Simplifying Failures

  • Tracking Origins

  • Reproducing Failures

  • Learning from Mistakes

Agenda

  • How Debuggers work

  • Asserting Expectations

  • Simplifying Failures(Delta Debugging)

  • Tracking Origins (PEX)

  • Reproducing Failures

  • Learning from Mistakes

How Debuggers work

Definitions

Input

Output

Definitions: Error有兩種

Input

Output

Defect:(

Failure:(

How Failures Come to Be

Input

Output

Infection

Debugging is to ...

Identify & Break the cause-effect chain

Scientific Method

Hypotheses

Prediction

Experiment

Observation

Explicit Degugging

Input    Expected    Output
--------------------------------------
"foo"     "foo"            "foo"

I've tried:
1. Set foo to "bar" (don't work)

2. ....

Reproducing Failures

四大魔王

BohrBug

reliably repeatable under well defined conditions.

Heisenbug

disappears or alters behaviour as you explore it.

 

 

Usually comes from debugging tools

Mandelbug

appears chaotic or non-deterministic.

Schrödingbug

does not manifest until someone realises the program should never have worked in the first place.

 

 

Never been seen in practice!

Input

Output

What to Reproduce?

Input

Static data

OS,hardware,libraries

User interaction

Physics

Time of day

Randomness

debugging tools

Topics

  • Reproducing User Interaction
  • Statistical Debug

Learning from Mistakes

Crucial information

  • Steps to reproduce (problem history, what users was were doing)
  • Diagnostics: core dumps, stack frames, logs.
  • User experience: what the user saw (e.g. preview crashed)
  • User expectation: what they thought would happen.
  • One line summary: forms the basis for search of bug database.

Use bug Database

Interesting Facts

  • 更有經驗的開發者有更多bug,因為難的東西都找他們寫
  • 有更多bug的模組,一般會有更多還沒發現的bug
  • 程式碼的複雜程度和bug多寡,有時相關有時不相關
  • 被加重測試的程式碼,一般會有更多bug(非因果關係)
  • 團隊管理架構有顯著影響。領導階層越多層,bug會更多
  • 使用的語言、函式庫、模組也可以拿來預測bug的多寡

Suggestions

7 steps of debugging

Track problem (bug database)

Reproduce problem

Automate and simplify (test asserts, ddmin)

Find possible infection origins

Focus on most likely origin (stastical debugging)

Isolate infection chain - develop hypotheses

Correct defect, then verify fix.

Avoid Debugging!

  • Get initial requirements right.

  • Use automation to find bugs. Develop and automate testing.

  • Reduce program complexity.

  • Set up assertions.

  • Test early, test often.

  • Review your code

  • analyse problem history.

Made with Slides.com