Effective Debugging.

Slides:



Advertisements
Similar presentations
Well-behaved objects Debugging. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Prevention vs Detection.
Advertisements

SE 450 Software Processes & Product Metrics 1 Defect Removal.
How to Debug Debugging Detectives Debugging Desperados I GIVE UP! MyClass.java.
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
Dr. Pedro Mejia Alvarez Software Testing Slide 1 Software Testing: Building Test Cases.
Locating Causes of Program Failures Texas State University CS 5393 Software Quality Project Yin Deng.
1 VeriSoft A Tool for the Automatic Analysis of Concurrent Reactive Software Represents By Miller Ofer.
1 ENERGY 211 / CME 211 Lecture 13 October 20, 2008.
CEN 4072 Software Testing Chapter 1: How Failures Come To Be.
Debugging Strategies from Software Carpentry. Agan's Rules Many people make debugging harder than it needs to be by: Using inadequate tools Not going.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
CSE 232: C++ debugging in Visual Studio and emacs C++ Debugging (in Visual Studio and emacs) We’ve looked at programs from a text-based mode –Shell commands.
CSE 332: C++ debugging Why Debug a Program? When your program crashes –Finding out where it crashed –Examining program memory at that point When a bug.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
Fixing the Defect CEN4072 – Software Testing. From Defect to Failure How a defect becomes a failure: 1. The programmer creates a defect 2. The defect.
CPSC 873 John D. McGregor Session 9 Testing Vocabulary.
1 CEN 4072 Software Testing PPT12: Fixing the defect.
1First BlueJ Day, Houston, Texas, 1st March 2006 Debugging in BlueJ Davin McCall.
CPSC 871 John D. McGregor Module 8 Session 1 Testing.
Debugging Watch and Text Output Alice. Debugging Techniques Several techniques are helpful in eliminating errors (bugs) in programs: careful design incremental.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
Testing Overview Software Reliability Techniques Testing Concepts CEN 4010 Class 24 – 11/17.
CPSC 372 John D. McGregor Module 8 Session 1 Testing.
Content Coverity Static Analysis Use cases of Coverity Examples
Lab 7 Control-Flow Testing
Prepared by: Fatih Kızkun
Testing Tutorial 7.
5.13 Recursion Recursive functions Functions that call themselves
Types for Programs and Proofs
The Hypothetico-Deductive Model of Scientific Research
John D. McGregor Session 9 Testing Vocabulary
Testing and Debugging PPT By :Dr. R. Mall.
Dept of Computer Science University of Maryland College Park
CSE 374 Programming Concepts & Tools
Designing For Testability
Software Testing An Introduction.
Lesson 5-2 AP Computer Science Principles
Chapter 8 – Software Testing
Command Line Arguments
Testing and Debugging.
COMP280:Introduction to Software Development Week 12, Lecture 34
Testing & Testing Tools
runtime verification Brief Overview Grigore Rosu
John D. McGregor Session 9 Testing Vocabulary
COS 260 DAY 17 Tony Gauvin.
John D. McGregor Session 9 Testing Vocabulary
הרצאה 08 פרמטרים ל- main קרן כליף.
CSCE 315 – Programming Studio, Fall 2017 Tanzir Ahmed
Lesson Overview 1.2 Science in Context.
Verification and Validation Unit Testing
Stack buffer overflow.
PPT1: How failures come to be
PPT6: Scientific debugging
When your program crashes
Requirements Engineering Processes
Testing and Debugging Concurrent Code
STL Algorithms Examples of how to use some STL algorithms.
The Hypothetico-Deductive Model of Scientific Research
Strings and Pointer Arrays
IDE’s and Debugging.
Advanced Debugging With Visual Studio & OzCode
Unit 1 Programming - Assignment 3
Test Cases, Test Suites and Test Case management systems
An Overview of C.
ACM programming contest
MOPS: an Infrastructure for Examining Security Properties of Software
C++, Sorting, Convex Hull
The Scientific Method.
Presentation transcript:

Effective Debugging

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.

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

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

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

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

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

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

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

Team Debugging Activity

Argument Sorter $ ./argsort 6 1 3 Output: 1 3 6 Sorts its command-line arguments: $ ./argsort 6 1 3 Output: 1 3 6 $ ./argsort 115 1 50 42 130 Output: 1 42 50 115 130

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

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 115 1 50 42 130 Output: 1 42 50 115 130 argc = 6 argv = {“./argsort”, “115”, “1”, “50”, “42”, “130”}

Team Debugging Activity Go To: https://bit.ly/2FUPlUM 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 

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