Lecture 11: Debugging - After the System is Deployed

1 Reproduce the Bug

  • Start by finding a small, repeatable test case that produces the failure.
  • Once you’ve found a small test case, find and fix the bug using that smaller test case, and then go back to the original buggy input and confirm that you fixed the same bug.

2 Understand the Location and Cause of the Bug

Step1: Study the Data
  • test input that causes the bug
  • the incorrect results
  • failed assertions
  • stack trace from an exception.

Step2: Hypothesize

  • Propose a hypothesis, consistent with all the data, about where the bug might be, or where it cannot be.
  • It helps to think about your program as modules, or steps in an algorithm, and try to rule out whole sections of the program at once.

Step3: Experiment - Devise an experiment that tests your hypothesis

  • Run a different test case
  • Insert a print statement or assertion in the running program, to check something about its internal state.
  • Set a breakpoint using a debugger, then single-step through the code and look at variable and object values.

2.1 Other Tips for the Location of the Bug

  • Bug localization by binary search
  • Prioritize your hypotheses
    • Different parts of the system have different likelihoods of failure.
    • Old, well-tested code is probably more trustworthy than recently-added code.
    • Java library code is probably more trustworthy than yours.
  • Swap components.
    • If you suspect the Java runtime, run with a different version of Java.
    • If you suspect the operating system, run your program on a different OS.
    • If you suspect the hardware, run on a different machine.
    • If you suspect your binarySearch() implementation, then substitute a simpler linearSearch() instead.
  • Make sure your source code and object code are up to date.
  • Get help.
  • Sleep on it, If you’re too tired, you won’t be an effective debugger. Trade latency for efficiency. :)

3 Fix the Bug

  • Ask yourself whether the bug was a coding error, like a misspelled variable or interchanged method parameters, or a design error, like an underspecified or insufficient interface.
  • Think also whether the bug has any relatives.

Reference

[1] 6.005 — Software Construction on MIT OpenCourseWare | OCW 6.005 Homepage at https://ocw.mit.edu/ans7870/6/6.005/s16/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值