Program Slicing; Andreas Linder eXtreme Programming lab course 2004.

Slides:



Advertisements
Similar presentations
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
Advertisements

Overview Structural Testing Introduction – General Concepts
A Survey of Program Slicing Techniques A Survey of Program Slicing Techniques Sections 3.1,3.6 Swathy Shankar
Program Slicing – Based Techniques
The OWASP Foundation OWASP OWASP Conference 2008 Application Security – The code analysis way Maty Siman CTO Checkmarx.
Register Allocation CS 671 March 27, CS 671 – Spring Register Allocation - Motivation Consider adding two numbers together: Advantages: Fewer.
Chair of Software Engineering From Program slicing to Abstract Interpretation Dr. Manuel Oriol.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
 Program Slicing Long Li. Program Slicing ? It is an important way to help developers and maintainers to understand and analyze the structure.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Graph Coverage for Design Elements 1.  Use of data abstraction and object oriented software has increased importance on modularity and reuse.  Therefore.
Program Slicing Mark Weiser and Precise Dynamic Slicing Algorithms Xiangyu Zhang, Rajiv Gupta & Youtao Zhang Presented by Harini Ramaprasad.
1 Program Slicing Purvi Patel. 2 Contents Introduction What is program slicing? Principle of dependences Variants of program slicing Slicing classifications.
Presented By: Krishna Balasubramanian
Introduction to Program Slicing Presenter: M. Amin Alipour Software Design Laboratory
Interprocedural Slicing using Dependence Graphs Susan Horwitz, Thomas Reps, and David Binkley University of Wisconsin-Madison.
Csci 565 Spring  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance.
SwE 455 Program Slicing. Our Goals Debug your thousands lines of code easily by reducing the complexity of the program Write a robust program before testing.
The Application of Graph Criteria: Source Code  It is usually defined with the control flow graph (CFG)  Node coverage is used to execute every statement.
Software Engineering and Design Principles Chapter 1.
COMP171 Data Structure & Algorithm Tutorial 1 TA: M.Y.Chan.
ISBN Chapter 10 Implementing Subprograms.
Program Slicing for Refactoring Advanced SW Tools Seminar Jan 2005Yossi Peery.
Chapter 13 Reduced Instruction Set Computers (RISC) Pipelining.
Survey of program slicing techniques
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
CODING Research Data Management. Research Data Management Coding When writing software or analytical code it is important that others and your future.
Technical University of Valencia Computer Science Department SOFSEM’07 (22/01/2007) A Program Slicing Based Method to Filter XML/DTD documents.
© 2003 G. Drew Kessler and William M. Pottenger1 Subroutines (Part 1) CSE 262, Spring 2003.
Software (Program) Analysis. Automated Static Analysis Static analyzers are software tools for source text processing They parse the program text and.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Regression Testing. 2  So far  Unit testing  System testing  Test coverage  All of these are about the first round of testing  Testing is performed.
Bug Localization with Machine Learning Techniques Wujie Zheng
Compiler Construction
Chapter 06 (Part I) Functions and an Introduction to Recursion.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 9 Def: The subprogram call and return operations of a language are together called its subprogram.
Foundations of Software Testing Chapter 1: Preliminaries Last update: September 3, 2007 These slides are copyrighted. They are for use with the Foundations.
 Program Slicing : Analysis technique of extracting parts of a given program, relevant to the aspects being analyzed (the slicing criterion). E.g. slicing.
1 Program Slicing Amir Saeidi PhD Student UTRECHT UNIVERSITY.
1 Program Testing (Lecture 14) Prof. R. Mall Dept. of CSE, IIT, Kharagpur.
Chapter 11: Dynamic Analysis Omar Meqdadi SE 3860 Lecture 11 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
CASE/Re-factoring and program slicing
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University IWPSE 2003 Program.
Software Engineering1  Verification: The software should conform to its specification  Validation: The software should do what the user really requires.
C OHERENT D EPENDENCE C LUSTERS Syed Islam 1. A GENDA 2 Coherent Clusters (Specialized Dependence Cluster) Mapping Source Code Constructs to Clusters.
Graph Coverage for Design Elements 1.  Use of data abstraction and object oriented software has increased importance on modularity and reuse.  Therefore.
1 Chapter 10 © 2002 by Addison Wesley Longman, Inc The General Semantics of Calls and Returns - Def: The subprogram call and return operations of.
Program Slicing Techniques CSE 6329 Spring 2013 Parikksit Bhisay
1 Software Testing & Quality Assurance Lecture 13 Created by: Paulo Alencar Modified by: Frank Xu.
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;
/ PSWLAB Evidence-Based Analysis and Inferring Preconditions for Bug Detection By D. Brand, M. Buss, V. C. Sreedhar published in ICSM 2007.
White-Box Testing Statement coverage Branch coverage Path coverage
Phoenix Based Dynamic Slicing Debugging Tool Eric Cheng Lin Xu Matt Gruskin Ravi Ramaseshan Microsoft Phoenix Intern Team (Summer '06)
Implementing Subprograms Chapter 10
Software Metrics 1.
Software Testing.
Software Testing and Maintenance 1
Implementing Subprograms
Compositional Pointer and Escape Analysis for Java Programs
SwE 455 Program Slicing.
Mark Weiser University of Maryland, College Park IEEE CHI, 1981
A Survey of Program Slicing Techniques: Section 4
Program Slicing Baishakhi Ray University of Virginia
Implementing Subprograms
Code Optimization Overview and Examples Control Flow Graph
자바 언어를 위한 정적 분석 (Static Analyses for Java) ‘99 한국정보과학회 가을학술발표회 튜토리얼
UNIT V Run Time Environments.
C. M. Overstreet Old Dominion University Fall 2005
Chapter 10 Def: The subprogram call and return operations of
Software Testing and QA Theory and Practice (Chapter 5: Data Flow Testing) © Naik & Tripathy 1 Software Testing and Quality Assurance Theory and Practice.
Presentation transcript:

program Slicing; Andreas Linder eXtreme Programming lab course 2004

2 Roadmap What is Program Slicing?(1) History and Intention(2) Basic Knowledge(2) Common Techniques(~14) Specialization „Cross the rubicon“(1) Two More Metrics(2)

3 What is Program Slicing? Definition: Reduces programs to those statements that are relevant for a particular computation What the question is: „What program statements potentially affect the value of variable v at statement s?“ int main() { int sum = 0; int i = 1; while (i < 11) { sum = sum + i; i = i + 1; } printf("%d\n", sum); printf("%d\n", i); } int main() { int sum = 0; int i = 1; while (i < 11) { sum = sum + i; i = i + 1; } printf("%d\n", sum); printf("%d\n", i); } Variable i, Last Statement

4 History: Foundation Stone Mark Weiser (1981) „Program Slicing“ „Program Slices: Formal psychological and practical investigations of an automatic program abstraction method“ (1979)

5 History: Intention Creating slices of programs was intended for use in debugging phases. 67% of programming effort goes into maintenance. (Zelkowitz et. al.) Experienced Programmers™ can reproduce functionality from memory. (Shneiderman) Slices will be remembered when debugging. (Weiser)

6 Roadmap/Intermission What is Program Slicing? History and Intention Basic Knowledge Common Techniques Specialization „Cross the rubicon“ Two More Metrics

7 Basic Knowledge Precondition: Slicing Criterion Pair (n, V) n is a line number V is a set of observed variables e.g. (8, {i}) Constraint 1. Source code must terminate. Constraint 2. Slices will be executable. Constraint 3. Slices will provide the same (subset of) behaviour. Constraint 4. There will always be at least one slice: The program itself.

8 Basic Knowledge Static vs. dynamic slices Static Analysis: All relevant Code. Dynamic Analysis: There will be assumptions about the input. Backward vs. forward slices Piece of Cake

9 Common Techniques Control Flow Graph (CFG) Control Dependence Graph Data Flow Graph Program Dependence Graph (PDC) Procedure Dependence Graph System Dependence Graph (SDC) Intra- und Interprocedural Slicing

10 Intraprocedural Slicing Example Program (1)read(n); (2)i := 1; (3)sum := 0; (4)product := 1; (5)while i <= n do begin (6)sum := sum + i; (7)product := product * i; (8)i := i + 1; end; (9)write(sum); (10)write(product); Criterion: (10, product)

11 Control FLOW Graph (1)read(n); (2)i := 1; (3)sum := 0; (4)product := 1; (5)while i <= n do begin (6)sum := sum + i; (7)product := product * i; (8)i := i + 1; end; (9)write(sum); (10)write(product);

12 Control DEPENDENCE Graph (1)read(n); (2)i := 1; (3)sum := 0; (4)product := 1; (5)while i <= n do begin (6)sum := sum + i; (7)product := product * i; (8)i := i + 1; end; (9)write(sum); (10)write(product);

13 DATA Flow Graph (1)read(n); (2)i := 1; (3)sum := 0; (4)product := 1; (5)while i <= n do begin (6)sum := sum + i; (7)product := product * i; (8)i := i + 1; end; (9)write(sum); (10)write(product);

14 PROGRAM Dependence Graph PDG Easy.

15 Interprocedural Slicing Method Build the Inverse Graph Perform a Depth First Search on the vertex containing the slicing criterion. Prevent circles! Mark every visited vertex! Assuming the existence of the PDC, slices can be retrieved in O(n).

16 Interprocedural Slicing Example Program procedure Example; begin read(n); i := 1; sum := 0; product := 1; while i <= n do begin Add(sum, i); Multiply(product, i); Add(i, 1); end; (9)write(sum); (10)write(product); end; Criterion: (10, product) procedure Add(a, b); begin a := a + b; end; procedure Multiply(c, d); begin j := 1; k := 0; while j <= d do begin Add(k, c); Add(j, 1); end; c := k; end;

17 SYSTEM Dependence Graph (Horwitz, Reps, Binkley) Easy, too.

18 Program Dependence Graph as a member of the SDG Multiply(product, i)

19 Preparing a method call Before the Call: Calling procedure copies actual parameters to temporary variables Parameter-in edges Parameter-out edges

20 PROCEDURE Dependence Graph as a member of the SDG Method call: Initialize formal parameters Before returning: Save formal parameters back to temporary vars.

21 Procedure Dependence Graph Quite the same for the Multiply procedure.

22 Interprocedural Slicing Method Invert the Graph! Phase 1: Start from criterion and ascend. Follow Data Flow, Control Flow, Call and Parameter-In DO NOT follow Def-Order, Parameter-Out Phase 2: Restart and descend. Follow Data Flow, Control Flow, Parameter-Out DO NOT follow Def-Order, Call, Parameter-In Again: Remember your visits!

23 Roadmap/Intermission What is Program Slicing? History and Intention Basic Knowledge Common Techniques Specialization „Cross the rubicon“ Two More Metrics

24 Crossing the Rubicon Another possibility to use Slicing is in implementing a special Refactoring “Extract method” Idea: Identifying procedures with a low Coverage value. Statement Extraction: Build slices for each/some value(s) computed in the method. Saving one of these back to its old name.

25 Very simple stupid Example begin dog = 0; for i := 0 to 5 do dog = dog + i; write(dog); dog = 0; for i := 5 downto 1 do dog = dog * i; write(dog); end;

26 Very simple stupid Example begin 1dog = 0; 2for i := 0 to 5 do 3dog = dog + i; 4write(dog); 5 dog = 0; 6for i := 5 downto 1 do 7dog = dog * i; 8write(dog); end; Criterion (7,{dog}) begin 1dog = 0; 2for i := 0 to 5 do 3dog = dog + i; 4write(dog); 5 dog = 0; 6for i := 5 downto 1 do 7dog = dog * i; 8write(dog); end; Criterion (4,{dog}) Coverage = 0,5Clustering = 1

27 Very simple stupid Example extractedProcedure2: begin dog = 0; for i := 5 downto 1 do dog = dog * i; write(dog); end; extractedProcedure1: begin dog = 0; for i := 0 to 5 do dog = dog + i; write(dog); end;

28 Roadmap/Intermission What is Program Slicing? History and Intention Basic Knowledge Common Techniques Specialization „Cross the rubicon“ Two More Metrics

29 Coverage Metric Compare the length of slices to the length of program/procedure! ~ ratio of mean slice length to program/procedure length. Low value (= long program, many short slices): Several distinct conceptual purposes

30 Overlap Slice How many statements in a slice are found only in that slice? ~ mean of the ratios of non-unique to unique statements. High overlap indicates very independent code.

31 Clustering Metric Are slices reflected in the code layout? ~ mean of the ratio of statements formerly adjacent to total statements in each slice. Low Value: Slices are intertwined spaghettically High Value: good statement grouping

32 Remember? Static slice dynamic slice Backward slice Forward slice Control Flow Graph Control Dependence Graph Program Dependence Graph Procedure Dependence Graph System Dependence Graph Data Flow Graph Coverage Overlap Clustering Interprocedural Slicing Intraprocedural Slicing Slicing Criterion Weiser First kiss Parameter-In/Out Extract Method QUESTIONS ? Thank you.