Presentation is loading. Please wait.

Presentation is loading. Please wait.

Effective Debugging.

Similar presentations


Presentation on theme: "Effective Debugging."— Presentation transcript:

1 Effective Debugging

2 Why Debugging Matters There will be bugs
Debugging (and testing) take 50% of software development time [1] Not just for software: any complex system [1] Beizer, B. (1990). Software Testing Techniques. International Thomson Computer Press.

3 Debugging Attitude Debugging is a learned skill
You can learn to debug effectively The system is not magic You can understand it Debugging can be deeply rewarding Driven by curiosity & creativity Satisfaction of understanding a bug’s root cause

4 Today Systematic Approach to Debugging Interactive Debugging Demo
Infection Model Wolf-Fence Algorithm Detective Method Interactive Debugging Demo Team Debugging Activity

5 Infection Model       Software systems are causal
States/ Program variables Software systems are causal So are many other types of systems… A faulty operation causes an infection The infection spreads through the program state Eventually an infection causes an observable failure Example: crash, print wrong value, … Faulty code Infected state Observed Failure

6 Wolf-Fence Algorithm How to find a wolf in Alaska? ?

7 Identifying the Root Cause
Variables Identifying the Root Cause Time Potential set of root causes is huge! Need to systematically eliminate possible causes Goal: most information for least effort Quickly identify root cause Tools: Wolf-fence Causal control flow of program How to build a wolf-fence? * Inspect values with debugger * Print-lining Observed Failure

8 Detective (or Scientific) Method
Description Examples Inspect program state Validate/Invalidate hypothesis View stdout/stderr Inspect variables with debugger Observe Hypothesize Predict Experiment Develop potential cause for observed behaviour This SEGFAULT is caused by exceeding bounds of array ‘street_segments’ Predict expected behaviour for hypothesized cause Variable ‘i’ will exceed ‘street_segments.size()’ at some point Observe/Predict/Experiment largely mechanical Hard part is generating good hypothesise. Hypothesis goals: Easily testable, quickly lead to root cause (may take several iterations) Improves greatly with experience! Perform a controlled experiment to verify prediction Re-run identical scenario in debugger

9 Debugging Demo Demo example from their project (e.g. M2 graphics crash) Also illustrate differences between build-types: Release/Debug/DebugOpt

10 Team Debugging Activity

11 Argument Sorter $ ./argsort 6 1 3 Output: 1 3 6
Sorts its command-line arguments: $ ./argsort 6 1 3 Output: 1 3 6 $ ./argsort Output:

12 Argument Sorter Code int main(int argc, char* argv[]) {
std::vector<int> vec; for (int i = 0; i < argc - 1; ++i) { std::stringstream ss(argv[i]); int v; ss >> v; } shell_sort(vec); std::cout << "Output: "; for (int i = 0; i < vec.size(); ++i) { std::cout << i << " "; std::cout << "\n"; void shell_sort(std::vector<int>& vec) { int h = 1; do { h = h * 3 + 1; } while (h <= vec.size()); h /= 3; for (int i = h; i < vec.size(); ++i) { char j, v = vec[i]; for (j = i; j >= h && vec[j - h] > v; j -= h) { vec[j] = vec[j - h]; } if (i != j) { vec[j] = v; } while (h != 1); Demo web gui

13 Argument Sorter $ ./argsort 6 1 3 Output: 1 3 6
Sorts its command-line arguments: $ ./argsort 6 1 3 Output: 1 3 6 argc = 4 argv = {“./argsort”, “6”, “1”, “3”} $ ./argsort Output: argc = 6 argv = {“./argsort”, “115”, “1”, “50”, “42”, “130”}

14 Team Debugging Activity
Go To: argsorter code in web-based IDE Try to fix all the bugs! Detective/Scientific Method Infection Model Wolf-Fences ? Brainstorm ideas w/ students: * Good wolf-fences * Hypothesises, how to test? Observe Hypothesize Predict Experiment Faulty code Infected Value

15 More Resources A. Zeller, “Why programs fail: a guide to systematic debugging”, Morgan Kaufmann, 2009 EJ Gauss, “The Wolf Fence Algorithm for Debugging”, Communications of the ACM, 1982


Download ppt "Effective Debugging."

Similar presentations


Ads by Google