Static Slicing. Software Maintenance

Similar documents
Debugging Program Slicing

Slicing. Rupesh Nasre. CS6843 Program Analysis IIT Madras Jan 2016

Applications. Slicing. Program with Multiple Functionality. Outline. Definition. Program with Single Functionality

Class 6. Review; questions Assign (see Schedule for links) Slicing overview (cont d) Problem Set 3: due 9/8/09. Program Slicing

DEBUGGING: STATIC ANALYSIS

Extract Slice Refactoring. Rani Ettinger, Programming Tools Group, May 19th, 2003

Testing Methods: White Box Testing II

slicing An example of slicing Consider the following example:

Qualifying Exam in Programming Languages and Compilers

Program Syntax; Operational Semantics

Formal Methods. CITS5501 Software Testing and Quality Assurance

Flow Propagation Algorithm

Program Slicing for Refactoring

CS64 Week 5 Lecture 1. Kyle Dewey

THE traditional denotational semantics treats a program

Chapter 8. Statement-Level Control Structures

Data Flow Analysis. Program Analysis

Shared Variables and Interference

Topic I (d): Static Single Assignment Form (SSA)

Iterative Statements. Iterative Statements: Examples. Counter-Controlled Loops. ICOM 4036 Programming Languages Statement-Level Control Structure

Shared Variables and Interference

Decompiling Boolean Expressions from Java TM Bytecode

Chapter 8. Statement-Level Control Structures

Dataflow-based Coverage Criteria

Data Flow Analysis. Daqing Hou

Program Static Analysis. Overview

Tour of common optimizations

Limitations of Algorithmic Solvability In this Chapter we investigate the power of algorithms to solve problems Some can be solved algorithmically and

Chapter 8. Statement-Level Control Structures ISBN

Basic Verification Strategy

The Use of Program Dependence Graphs in Software Engineering

The Use of Program Dependence Graphs in Software Engineering

EECS 470 Midterm Exam Winter 2008 answers

Informed Search A* Algorithm

Introduction to Model Checking

Data Flow Analysis. Agenda CS738: Advanced Compiler Optimizations. 3-address Code Format. Assumptions

Lab 3 (Sections 300, 301 and 302) Prelab: MIPS-Control Instructions

Multiway searching. In the worst case of searching a complete binary search tree, we can make log(n) page faults Everyone knows what a page fault is?

Week 4 Selection Structures. UniMAP Sem II-11/12 DKT121 Basic Computer Programming 1

Understanding Data Dependences in the Presence of Pointers

Locating Faults Through Automated Predicate Switching

PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL)

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

In this chapter you ll learn:

Chapter 8. Statement-Level Control Structures

The IA-64 Architecture. Salient Points

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

Lab 3 (All Sections) Prelab: MIPS-Control Instructions

Statement level control structures

Special Section: Building Your Own Compiler

Operating System Control Structures

COP5621 Exam 4 - Spring 2005

DICOM Correction Item

Outline. Introduction SDV Motivation Model vs Real Implementation SLIC SDVRP SLAM-2 Comparisons Conclusions

(How Not To Do) Global Optimizations

Dataflow Analysis. Xiaokang Qiu Purdue University. October 17, 2018 ECE 468

Outline. Best-first search

High-Level Small-Step Operational Semantics for Software Transactions

Principles of Programming Languages

Forward Assignment; Strongest Postconditions

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02)

INTRODUCTION TO HEURISTIC SEARCH

On Formal Analysis of OO Languages using. OO Languages and Rewriting Logic: Designing for Performance

ACLT: Algebra, Categories, Logic in Topology - Grothendieck's generalized topological spaces (toposes)

UNIT 3

Copyright 2008 CS655 System Modeling and Analysis. Korea Advanced Institute of Science and Technology

C Programming Decision Making

Software Engineering

6. Control Statements II

Extending C Global Surveyor

Guarded Commands, Nondeterminancy and Formal Derivation of Programs. Edsger W. Dijkstra. CACM 18, 8 pp (Aug. 1975).

Algorithms (III) Yijia Chen Shanghai Jiaotong University

4/24/18. Overview. Program Static Analysis. Has anyone done static analysis? What is static analysis? Why static analysis?

Programming Fundamentals

G Programming Languages - Fall 2012

SCoLang - Language Reference Manual

Chapter 3. Algorithms for Query Processing and Optimization

Reasoning About Imperative Programs. COS 441 Slides 10

Midterm II CS164, Spring 2006

6. Operatoren. 7. Safe Programming: Assertions. Table of Operators. Table of Operators - Explanations. Tabular overview of all relevant operators

Deriving a Slicing Algorithm via FermaT Transformations

Compiling Techniques

Well-defined coverage metrics for the glass box test

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Computing with Infinitely Many Processes under assumptions on concurrency and participation -M.Merritt&G.Taubenfeld. Dean Christakos & Deva Seetharam

EE 121. Office suite. Lecture 3: Introduction to programming and C programming language

Tool demonstration: Spin

Decision Procedures in First Order Logic

Outline. Best-first search

Regression Test Selection for C++ Software

Lectures 20, 21: Axiomatic Semantics

Testing, code coverage and static analysis. COSC345 Software Engineering

Control Structures. Outline. In Text: Chapter 8. Control structures Selection. Iteration. Gotos Guarded statements. One-way Two-way Multi-way

Introduction to Optimization Local Value Numbering

Algorithms (III) Yu Yu. Shanghai Jiaotong University

Code generation for modern processors

Code generation for modern processors

Computer Programming: C++

DECISION CONTROL AND LOOPING STATEMENTS

Software Model Checking. Xiangyu Zhang

Transcription:

soma@ist.tugraz.at 1

Outline Basics Control flow graphs Slicing Motivation Static slicing with relevant variables table Static slicing with program dependency graphs Summary & Outline 2

Outline Basics Control flow graphs Slicing Motivation Static slicing with relevant variables table Static slicing with program dependency graphs Summary & Outline 3

Outline Basics Control flow graphs Slicing Motivation Static slicing with relevant variables table Static slicing with program dependency graphs Summary & Outline 4

Motivation Imagine: Your program computes the wrong value for variable x at line 312 in the file y. The statement in line 312 is correct. How can you minimize the statements you have to investigate? Solution: Computation of statements influencing the values of the variables referenced in line 312 and skip the rest. 5

What is a Slice? A Slice is a (reduced) program, that preserves the original program s behavior for a given set of variables at a chosen point in a program Characteristics: Defined for variables and a given point A slice is itself a program Ignoring other (irrelevant) statements Focus on relevant parts 6

Example 1 1. begin 2. z = 4 + a; 3. y = z + 1; 4. x = 5 + z; 5. end Slicing Criterion: (5, {x}) 7

Algorithm 1 Slicing criterion C = (i,v) with line number i, variables of interest V Relevant variables R C (n) all v V if n = I all v Ref(n) if { w w Def(n) w R C (m) n Pre(m)} all w R C (m) where w Def(n) n Pre(m) 1 2a 2b Slice S C comprises all statements n where R C (m) Def(n) { } with n Pre(m) 8

9 Example 2 1. begin 2. z = 4 + a; 3. if (a > 3) then 4. begin 5. z = z - 3; 6. end 7. fi; 8. x = 5 + z; 9. end Slicing Criterion: (9, {x})

Algorithm 2 Influence set Infl(b) Set of statements influenced by the control statement b Improved algorithm: 1. Compute R 0 C and S 0 C 2. Compute control flow stmts infl. variables in the slice: B C = { b j S 0 C, j Infl(b) } 3. Compute the slice S 1 C S 1 C = S 0 C B C 10

Example 3 1. begin 2. r = 0 ; 3. i = 0 ; 4. while ( i < n) do 5. begin 6. if (A[ i ] == 1) then 7. begin 8. r = r + 1 ; 9. end; 10. f i ; 11. i = i + 1 ; 12. end; 13. od; 14. end; Slicing Criterion: (14, {i}) 11

Example 4 1. begin 2. r = 0 ; 3. i = 0 ; 4. while ( i < n) do 5. begin 6. if (A[ i ] == 1) then 7. begin 8. r = r + 1 ; 9. end; 10. f i ; 11. i = i + 1 ; 12. n = n 1; 13. end; 14. od; 15. end; Slicing Criterion: (15, {i}) 12

Algorithm 3 1.Compute R 0 C and S 0 C 2.For i 0 a. Compute control flow statements influencing variables in the slice: B i C = { b j S i C, j Infl(b) } b. Compute statements which influence variables referenced in B i C: R i+1 C(n) = R i C(n) R 0 (b,ref(b))(n) c. Compute the slice S i+1 C S i+1 C = S i C B i C 13

Example 5 1. begin 2. a = 0 ; 3. i = 0 ; 4. while ( i < n) do 5. begin 6. a = b ; 7. b = i ; 8. i = i + 1 ; 9. end; 10. od; 11.end; Slicing Criterion: (11, {a}) 14

Program dependency graph Directed graph of a single procedure in a program Statements are the nodes Data and control dependencies are the edges Control dependency Statements in the branches of if or while statements are control dependent on the control predicate Data dependency Node j is data dependent on node i if x { x Def(i), x Ref(j) } and there exists a path P from i to j without redefining x. 15

Minimal slice Definition: Let C be a slicing criterion on a program P. A slice P of P on C is statement-minimal if no other slice of P on C has fewer statements than S. Theorem: There does not exist an algorithm to find statement-minimal slices for arbitrary programs. (Problem equivalent to halting problem) 16

17 Example 6 1. begin 2. A = constant; 3. while (K < 10) do 4. begin 5. if (C = 0) then 6. begin 7. B = A; 8. X = 1; 9. end; 10. else 11. begin 12. C = B; 13. Y = 2; 14. end; 15. fi; 16. K = K + 1 ; 17. end; 18. od; 19. Z = X + Y; 20. wr i t e (Z) 21. end; Slicing Criterion: (20, {z})

Outline Basics Control flow graphs Slicing Motivation Static slicing with relevant variables table Static slicing with program dependency graphs Summary & Outline 18

Types of slices A slice S can be obtained from a program P by deleting zero or more statements from P. S has the same values for the variables in V as P any input I (static slicing) for a given input I (dynamic slicing) 19

Slicing Criterion Static slice C = (i, V) with a line number i and a set of variables of interest V Example: C = (5, {x}) Dynamic slice C = (x, I q, V) with program input x, q th element of the trajectory I q and a set of variables of interest V Example: C = ({a = 4}, 5³, {x}) 20

Types of slices Backward Computation of statements influencing the value of a variable Forward Computation of statements influenced by a statement 21

Types of slices Input constraint Static slice Relevant variables table Program dependency graphs Dynamic slice Relevant slicing Direction Backward slice Forward slice 22

Open Problems Function calls call-by-value call-by-reference Other control flow statements goto break continue Composite data types arrays Pointer Interprocess communication 23

Questions? 24