Lecture 11: Debugging
来源:互联网 发布:netbeans怎么编写java 编辑:程序博客网 时间:2024/05/23 13:05
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/
0 0
- Lecture 11: Debugging
- Lecture 11: Testing and debugging
- Lecture 8: Avoiding Debugging
- MIT 6.00 1X Lecture 7 Debugging 学习笔记
- Lecture 11: Hopfield Nets
- Debugging
- Debugging
- debugging
- Debugging
- Debugging
- Debugging
- Debugging
- Debugging
- Debugging
- Debugging
- CSCI 512 Lecture-11 Corners
- Lecture 11 Augmenting Data Structures
- Debugging DirectX 11 shaders with Visual Studio
- hibernate 入门学习 Demo
- ofo共享单车和摩拜单车背后的物联网技术分析
- String中的subString() Java方法
- java-InputStream与OutputStream类型
- 各个缩写的含义
- Lecture 11: Debugging
- linux网络协议栈内核分析
- 物体变大变小
- LeetCode:Sort Colors
- Servlet学习笔记(一)
- 垃圾回收算法之 标记-整理算法
- Android自定义控件(二)View的绘制
- unity 项目实践经验 和 架构体系
- mongodb忘记admin密码操作