Lecture Notes - Copyright © 2006. S. C. Kothari, All rights reserved.1 Efficient Debugging CPRE 556 Lecture 19.

Slides:



Advertisements
Similar presentations
A Survey of Program Slicing Techniques A Survey of Program Slicing Techniques Sections 3.1,3.6 Swathy Shankar
Advertisements

Python Programming Chapter 5: Fruitful Functions Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
Static Single Assignment CS 540. Spring Efficient Representations for Reachability Efficiency is measured in terms of the size of the representation.
Data-Flow Analysis Framework Domain – What kind of solution is the analysis looking for? Ex. Variables have not yet been defined – Algorithm assigns a.
Program Slice Program slice was a concept first discussed by Mark Weiser in the early 1980’s –He especially noticed that when people debug, they trace.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 7: User-Defined Functions II.
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
Program Slicing. 2 CS510 S o f t w a r e E n g i n e e r i n g Outline What is slicing? Why use slicing? Static slicing of programs Dynamic Program Slicing.
1 Program Slicing Purvi Patel. 2 Contents Introduction What is program slicing? Principle of dependences Variants of program slicing Slicing classifications.
CS590F Software Reliability What is a slice? S: …. = f (v)  Slice of v at S is the set of statements involved in computing v’s value at S. [Mark Weiser,
{ Dominion - Test Plan Version 1 – 22 nd Apr Aravind Palanisami.
Motivating the OO Way COMP 401, Fall 2014 Lecture 05 9/2/2014.
Chapter 10 Recursion. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Explain the underlying concepts of recursion.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
1 Software Testing and Quality Assurance Lecture 5 - Software Testing Techniques.
Classifying Triangles Students will classify triangles using the lengths of the sides and the angles. S. Calahan October 2010.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
Software (Program) Analysis. Automated Static Analysis Static analyzers are software tools for source text processing They parse the program text and.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Chapter 4 Recursion. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Explain the underlying concepts of recursion.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
CSE403 Software Engineering Autumn 2001 More Testing Gary Kimura Lecture #10 October 22, 2001.
Summarizing “Structural” Testing Now that we have learned to create test cases through both: – a) Functional (blackbox)and – b) Structural (whitebox) testing.
1 Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
Triangle A polygon with three sides and three angles. A triangle can be names by its’ side lengths and angles. – Side lengths: isosceles, equilateral,
Chapter 11: Dynamic Analysis Omar Meqdadi SE 3860 Lecture 11 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Software Development Problem Analysis and Specification Design Implementation (Coding) Testing, Execution and Debugging Maintenance.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 8: Recursion Presentation slides for Java Software Solutions for AP* Computer Science 3rd.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Triangle Angle Sum Theorem Isosceles Triangles Equilateral Triangle.
Classifying Triangles Math 7 Ms. Conway Math 7 Ms. Conway.
Chapter 3: User-Defined Functions I
The Hashemite University Computer Engineering Department
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
1 Graph Coverage (3). Reading Assignment P. Ammann and J. Offutt “Introduction to Software Testing” ◦ Section 2.2 ◦ Section
Control Flow Graphs : The if Statement 1 if (x < y) { y = 0; x = x + 1; } else { x = y; } x >= yx < y x = y y = 0 x = x + 1 if (x < y) { y = 0;
Classifying Triangles. Two Ways to Classify Triangles  By Their Sides  By Their Angles.
Lesson 8.3 Concept: How to classify triangles by their sides and angles. An equilateral triangle has three sides of the same length. An isosceles triangle.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Notes Over 10.1 Finding the Distance Between Two Points Find the distance between the two points.
Chapter 6: User-Defined Functions I
CprE 185: Intro to Problem Solving (using C)
Chapter 7: User-Defined Functions II
Testing and Debugging PPT By :Dr. R. Mall.
Static Slicing Static slice is the set of statements that COULD influence the value of a variable for ANY input. Construct static dependence graph Control.
IIT Kharagpur & Kingston Uni
Input Space Partition Testing CS 4501 / 6501 Software Testing
TRI NGLES 2 ways to classify: By Sides By Angles 60 4” 4” 4” 60 60
Faults, Errors, Failures CS 4501 / 6501 Software Testing
Lecture 2 Introduction to Programming
SwE 455 Program Slicing.
User-Defined Functions
Classifying Triangles
Program Slicing Baishakhi Ray University of Virginia
Human Complexity of Software
Classifying Triangles
Java Programming Control Structures Part 1
Objective - To classify triangles.
Chapter 7: User-Defined Functions II
CSE403 Software Engineering Autumn 2000 More Testing
CPRE 416-Software Evolution and Maintenance-Lecture 11
Classifying Triangles
Classifying Triangles
CHAPTER 6 Testing and Debugging.
Area and Perimeter Triangles.
Presentation transcript:

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.1 Efficient Debugging CPRE 556 Lecture 19

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.2 Contents Debugging challenge Use of program slicing Static vs. dynamic slicing Reaching definitions Program slice browser

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.3 Debugging Challenge Debugging is a complex and difficult activity. The failure may be manifested far away from the fault (bug) itself. Analysis is needed determine the cause and the location of a program failure. Analysis is often tedious and time consuming because of many dependencies and many execution paths

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.4 Sample Program The program computes the sum of the areas of N triangles. It reads the value of N, followed by the lengths of the three sides of each of these N triangles. It classifies each triangle as an equilateral, isosceles, right, or a scalene triangle. Then it computes the area of the triangle using an appropriate formula. Finally, the program prints the sum of the areas.

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.5

6 Start Debugging Suppose this program is executed for the test case #1 when N = 2 and sides of the two triangles are (5, 4, 3) and (4, 4, 2) respectively. If the final sum of areas printed is incorrect, how should we go about locating the bug in the program?

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.7 Many Possibilities for Bugs Looking backwards from the printf statement on line 46, there are several possibilities: –sum is not being updated properly –one or more of the formulas for computing the area of a triangle are incorrect –the triangle is being classified incorrectly –the values for the three sides of the triangle are not being read correctly.

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.8 Debugging Steps 1.Determine which statements in the code have an influence on the value of sum at line Select one (or more) of these statements at which to examine the program state. 3.Recreate the program state at those statements to examine specific variables.

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.9 Program Slicing It is used to find all those statements in a program that directly or indirectly affect the value of a given variable occurrence (variable name and statement location). The statements that affect the value constitute the slice of the program with respect to the given variable occurrence

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.10 Two Types of Program Slices Two types of slices: static and dynamic. A static slice includes all statements that could influence the value of a variable occurrence for all possible inputs to the program. A dynamic slice includes only those statements that influence the value of a variable occurrence for a given test case.

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.11 Data vs. Control Slices A data slice is one that is defined with respect to a data value—a variable occurrence. –Useful when we are trying to determine the source of a wrong value for a variable occurrence. A control slice is one that is defined with respect to control reaching a certain program location. –Useful when we are trying to determine why the control has reached a wrong location.

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.12 Reaching Definitions Looking at the whole slice at once may be overwhelming. It may be useful to analyze the inter- statement program dependencies one at a time – incremental slicing. Reaching definitions are the assignments (or modifications) of variables that reach and affect the given variable occurrence.

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.13 Terminology Def: a definition of a variable x is a statement that assigns a value to x Use: a use of a variable x is a statement that reads the value of x Kill: a definition of a variable x on a path is said to be killed on a control flow path if we encounter another definition of variable. Reaches: a definition d reaches a point p if there is a path from the point immediately following d to p - such that d is not killed along p.

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.14 Example 1: I := M - 2; 2: J := N; 3: A:= U1; 4: 5: DO 6: I := I +1; 7: J := J-1; 8: if (E1) then 9: A:= A + 2; 10: else 11: I := u3; 12: endif 13: WHILE e2 def of A at 3 and 9 The definition at line 9 kills the definition of A from line 3 The definition of A from line 3 reaches line 9

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.15 Program Slice Browser We developed a program slice browser (PSB) to provide the user a visual representation of the slice. Using the PSB: –A slice can be viewed at different levels of granularity: statements, control blocks, and procedures. –By coupling the visual representation and the corresponding source one can conveniently navigate through the code.

Lecture Notes - Copyright © S. C. Kothari, All rights reserved.16 References Efficient debugging with slicing and backtracking: due/TR80P.pdf due/TR80P.pdf Program slice browser: /WPC /WPC