Presentation is loading. Please wait.

Presentation is loading. Please wait.

 Program Slicing 1001024238 Long Li. Program Slicing ? It is an important way to help developers and maintainers to understand and analyze the structure.

Similar presentations


Presentation on theme: " Program Slicing 1001024238 Long Li. Program Slicing ? It is an important way to help developers and maintainers to understand and analyze the structure."— Presentation transcript:

1  Program Slicing 1001024238 Long Li

2 Program Slicing ? It is an important way to help developers and maintainers to understand and analyze the structure and activities of the programs.

3 How did it create?  Mark D. Weiser ( July 23, 1952 – April 27, 1999)  He describes a method of using the program dependence graph to achieve the slicing technique in 1979

4 How did it create?  Horwitz proposed program slicing algorithm, to take program dependence graph (PDG) extended system dependence graph (SDG), this algorithm to solve the procedure calls which can not be solved by weiser.  Korel and Laski proposed the concept of dynamic slicing  Canfora proposed condition slicing technique

5 Development process  From static to dynamic  From Forward slicing to Backward slicing  From single process to multiple processes  From process-oriented programming to the object -oriented programming  From the non- distributed program to distributed program

6 Definition  Program slicing is that to extracted a piece of codes to create a new program which user are interesting from the source program, the new program is the source program’s slice.  Program slicing can be used in the form of S (V, N)

7 About the S(V, N) ??  Wherein V represents the set of a particular process variable or variables in the program, N represents the process in a certain position ( where the statement variable V )  S(V, N) is the most basic form of program slicing, in any form by slicing can be obtained by expansion of this standard

8 Static program slicing  Static program slicing refers to the analysis of the structure of the program when using a static slice data flow and control flow.  The analysis of static slicing made entirely dependent on the static information of program.  The current state variable V is irrelevant, its value will not affect the result of the slice.

9 Static program slicing  Static slicing method need to consider all the state of variable V  Need to traverse all the corresponding tracks in the program , therefore, when using this method of analysis procedures can be very large workload  It is mainly used in the field of program comprehension and software maintenance

10 Static program slicing Example 1:A=temp1; 2:B=temp2; 3:C=temp3; 4:if(A>B){ 5:C=A; 6:A=0; 7:B=0:} 8:else{ 9:C=B: 10:A=0; 11:B=0;} 12:cout<<“ C is ”<< C<<endl; Using S (C, 12 ) to slicing above program

11 Static program slicing Analysis: 6,7,10,11 ;these four statements have no effect on the statement 12 variable C, so removal of these statements, you can get corresponding to S (C, 12) of program slicing. Result: 1:A=temp1; 2:B=temp2; 3:C=temp3; 4:if(A>B){ 5:C=A; 8:else{ 9:C=B: 12:cout<<“ C is ”<< C<<endl;

12 Dynamic program slicing  Dynamic program slicing technique uses dynamic data flow and control flow analysis method  It depends on the program for a specific input variables, different input may cause different results slice.  It emphasizes the program in a specific execution, affects the state of variables in a certain point in the program all the statements.

13 Dynamic program slicing  Dynamic program slicing is a subset of the corresponding static program slicing  The workload is smaller than static program slicing  Suitable for use in program testing and debugging work has larger work itself

14 Dynamic program slicing  Dynamic circular slice is a kind of dynamic slicing, it can be defined as : S ( V, N, X, I ).  It indicates the program in the input for the X, will affect the variable V in I time executing the statement N, a collection of all statements describe current state.

15 Dynamic program slicing Example for dynamic circular slice: 1:i=0; 2:while(i<10){ 3:if(A<5) 4:A++; 5:else 6:A--; 7:cout<<“ A is ” <<A<<endl 8:i++;} Result: When meet S (A, 7, 0, 3 ), program slicing by 1, 2, 3, 4, 7, 8, of six statements; when meet S (A, 7, 0, 6 ), program slicing by 1, 2, 3, 5, 6, 7, 8, of seven statements.

16 Condition slicing  Conditions slicing is a kind of technology that between static slicing and dynamic slicing  It is neither limited to analyze the application of static information nor only limited to rely on the external input to obtain the information of the program  When tectonic conditions slicing, only those who meet the slice condition statements can be extracted.

17 Condition slicing  The condition slicing’s definition can be expressed as S ( V, N, X, W ), it means that when input X that is satisfied the condition W , all affect the variable V in the N status of the set of statements.  If the program from a slice conditions of any initial state is likely to trigger statement to remove, so the rest of the statement is to satisfy the conditions of a slice.

18 Condition slicing Example: 1:B=2*A 2:if(B>A) 3:B=B+1; 4:else 5:A=A+1; 6:cout<<“ A: ”<<A<<“ B: ”<<B<<endl; When S ( A, 6, 2, A>0 ); the slicing is ?

19 Condition slicing Result: 1:B=2*A 2:if(B>A) 3:B=B+1; 4:cout<<“ A: ”<<A<<“ B: ”<<B<<endl; Analysis: Only when A zero or negative, the value of B can be less than or equal to the value of the A

20 Program dependence graph  Before slice the program, the first we need to through PDG to obtain some basic information. PDG is a graphical representation of the program, It is a kind of common structure of program slicing method.  PDG can be expressed as G (N, E), N={n ∈ N | n means that one of the statement in the program}, E={( m, n)|m, n ∈ N Whether statement m implementation depends on the true and false statement n, or exist variable V which is defined by m and referenced by n }.

21 Program dependence graph In the PDG there exist two kinds of dependence: One is control dependence, it describes in a program the conditional statements and circular statements with the statements embedded in them, their control relationships. The other kind is data dependence, it describes in the assignment statements the left value to the right value dependence relationship.

22 Program dependence graph Example for program and its PDG: void sum{ Int i, sum; sum=0; i=1; while(i<11){ sum=sum+i; i=i+1; }} If we want the above program at i++ to slice the i ?

23 Program dependence graph Result : void sum{ int i; i=1; while(i<11){ i=i+1; }} We just need to left the nodes which on the left side of assignment statement contains variable i.

24 System dependence graph  PDG is usually used to describe a single application of the process, but in the actual software development, there are few program contains only one single process, the program is usually composed of multiple processes.  We need a new structure to reflect multiple processes program, so SDG could describe it.

25 System dependence graph  We should not only consider the interdependencies of statements within process, but also to consider the invocation of the relationship between process and process, process parameters between transitive relation, etc.  SDG is extended by PDG, it can be expressed as PDG and a series of process get together as a set.

26 System dependence graph Through the following steps to construct a system dependence graph, first of all, on the basis of PDG increased some new nodes: (1) For each of the called process set an Entry node (2) For each argument set an Actual - in node finally set an Actural - out node together, their relationship with the call statement is control dependence. (3) For each parameter set a Formal - in node, if the parameter value is changed in the procedure call, then again for this row and add a Formal - out node.

27 The dependence relationship between new nodes and original nodes Called statement node Actural-in node Actural-out node Process Entry node Formal-out node Process Entry node Call relationship N/A Actural-in nodeControl dependence N/A Actural-out nodeControl dependence Summary relationship Summary relationship N/A Formal-in nodeN/AParameter- in(data dependence) Control dependence Parameter- in(data dependence) Formal-out nodeN/A Control dependence N/A

28 System dependence graph Example: If we want to condition slicing of the program S (B, 6, 2, B>0 ), based on the definition of condition slicing, we removed the statements related to the function call, then we get the program slicing what we need.

29

30 System dependence graph Result:

31 END Questions?


Download ppt " Program Slicing 1001024238 Long Li. Program Slicing ? It is an important way to help developers and maintainers to understand and analyze the structure."

Similar presentations


Ads by Google