University of Wisconsin Platteville |...

14
Program Slicing – Based Techniques Corey Rahberger Department of Computer Science University of Wisconsin – Platteville Platteville, WI 53818 [email protected] Abstract Program Slicing is a way of simplifying a program, so that only relevant statements are included according to the point of interest. Originally it was developed to help with debugging, but it has evolved into multiple techniques that can be valuable tools in all areas of programming. More and more techniques are being added to list to improve the performance of program slicing as well as assisting in new areas. This paper will look into program slicing, how slices are extracted from a program, the main types of program slicing, the uses for program slicing, and the future of program slicing. Introduction Program slicing is the process of computing a slice of a program. A slice contains only the sections of a program that could affect the variable or point of interest. This means that only the statements that could possibly affect the point of interest will be in the slice of the program. Likewise, all the statements that could not affect the point of interest will not be in the slice of program. The slice of the program is determined by a slicing criterion. The slicing criterion is the point of interest that you are looking into. The point of finding slices of a program is to minimize the statements needed to review and boil down the

Transcript of University of Wisconsin Platteville |...

Page 1: University of Wisconsin Platteville | UW-Plattevillepeople.uwplatt.edu/.../f12/RahbergerC_Program_Slicing.docx · Web viewIn debugging, program slicing can help narrow down the search

Program Slicing – Based Techniques

Corey RahbergerDepartment of Computer Science

University of Wisconsin – PlattevillePlatteville, WI 53818

[email protected]

Abstract

Program Slicing is a way of simplifying a program, so that only relevant statements are included according to the point of interest. Originally it was developed to help with debugging, but it has evolved into multiple techniques that can be valuable tools in all areas of programming. More and more techniques are being added to list to improve the performance of program slicing as well as assisting in new areas. This paper will look into program slicing, how slices are extracted from a program, the main types of program slicing, the uses for program slicing, and the future of program slicing.

Introduction

Program slicing is the process of computing a slice of a program. A slice contains only the sections of a program that could affect the variable or point of interest. This means that only the statements that could possibly affect the point of interest will be in the slice of the program. Likewise, all the statements that could not affect the point of interest will not be in the slice of program. The slice of the program is determined by a slicing criterion. The slicing criterion is the point of interest that you are looking into. The point of finding slices of a program is to minimize the statements needed to review and boil down the program to the point of interest. The concept of program slicing to receive program slices was first introduced by Mark Weiser in 1984 [6].

Extracting a Slice

In order to obtain a slice of a program, one must first know the dependences between the different statements of the program. A control flow graph (CFG) can be made to represent the different statements and their control dependences. For example, the control flow graph of the program in Figure 1 is shown in Figure 2. Each node in Figure 2 is marked with a number, which corresponds to a statement in the program. The control flow graph is no more than a graphical representation of the statement tracing of a program. Since it only depicts the control dependences of a program, it will not provide all the information needed to compute a program slice. Data dependences are also needed to compute a program slice [4].

Page 2: University of Wisconsin Platteville | UW-Plattevillepeople.uwplatt.edu/.../f12/RahbergerC_Program_Slicing.docx · Web viewIn debugging, program slicing can help narrow down the search

2

Figure 1: Sample program [4]

Figure 2: Control flow graph of Figure 1 [4]

To be able the compute a program slice, data dependences need to be added to the control flow graph. This type of data structure is called a program dependence graph (PDG). “A PDG is an oriented graph where the nodes represent statements in the source code [and the] edges represent control and data flow dependencies between statements in such a way that they induce a partial ordering in the nodes, preserving the semantics of the program [4].” For example, a program dependence graph for Figure 1 is shown in Figure 3. The solid lines represent the control dependencies and the dotted lines represent the data dependencies. Now that both control and data dependencies are represented in the graph, the graph can be used to create program slices according to the point of interest [4].

Page 3: University of Wisconsin Platteville | UW-Plattevillepeople.uwplatt.edu/.../f12/RahbergerC_Program_Slicing.docx · Web viewIn debugging, program slicing can help narrow down the search

3

Figure 3: Program dependence graph of Figure 1 [4]

Program Slicing Techniques

Since Mark Weiser introduced program slicing, program slicing techniques has expanded in multiple directions. Techniques have been created and modified to assist with all areas of programming. Because of the wide area of techniques, there have been many surveys trying to illustrate the differences between them and which techniques are best. However, these surveys have lead to inconclusive results. This is due to the surveys looking at the techniques in different ways [4]. Although there is no definitive answer to these questions, there are still three main areas of program slicing techniques that the other techniques expand upon. These main areas are static, dynamic, and conditioned [2]. As we can see from Figure 4, these three main areas are at the center of all the other main program slicing techniques. We will now look at each of these three main techniques more closely.

Figure 4: Relationships between program slicing techniques [4]

Page 4: University of Wisconsin Platteville | UW-Plattevillepeople.uwplatt.edu/.../f12/RahbergerC_Program_Slicing.docx · Web viewIn debugging, program slicing can help narrow down the search

4

Static Slicing

Static Slicing is similar to the original version of program slicing that Weiser developed in 1984. In static slicing, the input is not considered when slicing the program with the slicing criterion. The resulting slice will then work for all input. Static slicing uses the slicing criterion (s, v). In this slicing criterion, “s” represents the line number of the statement in the program and “v” represents the variable(s) in program that are of interest [4].

Static Slicing Example

We will now look at an example of static slicing in Figure 5. The static slice of the sample program in Figure 5(a) using the slicing criterion (10, product) results in Figure 5(b). Note that, not all the statements in the resulting slice have the variable “product” in it. This is because the variable “i” and in turn the variable “n” effect the result of the variable “product”, because variable “product” is within a while loop that is controlled by variable “i” and “n”.

Dynamic Slicing

In dynamic slicing, the input used for the program is used to help determine where a problem could be occurring in the execution of the program. This type of slicing is therefore very useful for debugging a program [2]. Since dynamic slices only work for select inputs, they are usually smaller than static slices. The slicing criterion for a dynamic slicing is (si, v, {a1, …, an}). In this slicing criterion, “s” represents the statement number, “i” represents the position in the execution history of statement “s”, “v” represents the variable(s), and “{a1, …, an}” represents the initial values or inputs [4].

Figure 5: (a) Example program. (b) A slice of the program w.r.t. criterion (10, product) [5]

Page 5: University of Wisconsin Platteville | UW-Plattevillepeople.uwplatt.edu/.../f12/RahbergerC_Program_Slicing.docx · Web viewIn debugging, program slicing can help narrow down the search

5

Dynamic Slicing Example

We will now look at a sample of dynamic slicing in Figure 6. The dynamic slice of the sample program in Figure 6(a) using the slicing criterion (81, x, {n = 2}) results in Figure 6(b). Same as for static slicing, not all the statements in the slice contain the variable “x”. This is because the other variables in the slice must affect the value of variable “x” in some way. As you can see, the statement number 6 has been removed since it is not reached given this slicing criterion. The ability for dynamic slicing to remove unreached conditional statements, results in smaller slices compared to that of static slicing.

Conditioned Slicing

Conditioned slicing is a combination of static and dynamic slicing. In conditioned slicing, the slicing criterion provides information about the input values, but doesn’t specify them exactly. This type of slicing is useful in trying to comprehend a program piece by piece [2]. The slicing criterion for a conditioned slice is (i, F, s, v). In the slicing criterion, the “I” represents the input variable(s), “F” represents a logical formula on “i”, “s” represents the statement number, and “v” represents the variable(s) interested in. The logical formula, “F”, specifies the possible inputs for the program [4].

Figure 6: (a) Example program. (b) Dynamic slice w.r.t. criterion (81, x, {n = 2}) [5]

Page 6: University of Wisconsin Platteville | UW-Plattevillepeople.uwplatt.edu/.../f12/RahbergerC_Program_Slicing.docx · Web viewIn debugging, program slicing can help narrow down the search

6

Conditioned Slicing Example

We will now look at a sample of conditioned slicing in Figure 7. The dynamic slice of the example program in Figure 7(Left) using the slicing criterion ((text, n), F, 18, {subtext}), where F = (¥ c € text, c != ‘\n’ . n > 0), results in Figure 7(Right). Similar to the dynamic slicing example, some statements in the slice do not contain variable “subtext” and some of the conditional statements have been removed in the slice because they are no longer reached. However, since we do not exactly set the input variables, we will receive a slice that will work for multiple different input variables. Just not all inputs like static slicing would.

Applications

All the different types of program slicing have made it a very useful tool in all areas of programming. Some of the main areas that program slicing can help with are debugging, cohesion measurement, comprehension, maintenance and reengineering, and testing. In debugging, program slicing can help narrow down the search for the error(s). For cohesion measurement, program slicing can help to make sure that a program is following good object-oriented programming. For comprehension, program slicing can help in the maintenance by splitting it into understandable pieces. For maintenance and reengineering, program slicing can help separate sections of code to be modified. In testing, program slicing can simplify the section of the program to be tested and can increase the speed of the testing [3]. As you can see, program slicing can help in all the different areas of programming.

Figure 7: (Left) example program. (Right) Conditioned slice w.r.t. ((text, n), F, 18, {subtext}), where F = (¥ c € text, c != ‘\n’ . n > 0) [4].

Page 7: University of Wisconsin Platteville | UW-Plattevillepeople.uwplatt.edu/.../f12/RahbergerC_Program_Slicing.docx · Web viewIn debugging, program slicing can help narrow down the search

7

Slicing Tools

In this section we will look at the slicing tools CodeSurfer and Sprite. We will than compare the two slicing tools based on the resulting slices that they produce for several programs. The results will then be compared and will be examined to see if one of these slicing tools is better than the other.

CodeSurfer

CodeSurfer is a static analysis tool for C++/C that is created by GammaTech. It favors precision instead of performance. CodeSurfer uses an Andersen’s cubic time pointer analysis and uses summary edges to provide infinite context sensitivity [1].

Sprite

Sprite is an open source program slicer. It favors performance instead of precision. Sprite uses Steensgaard’s almost linear points-to analysis. Sprite also performs context insensitivity slices [1].

Comparison

We now turn to Figure 8 for the results of the comparison between CodeSurfer and Sprite. The intersection columns in the table are used for comparison and are the corresponding slices that were returned by CodeSurfer and Sprite. The abbreviation “PM” stands for precision margin, which is the slice size divided by the size of the intersected slice [1].

As we look at these results, we can see that in some cases they are pretty similar in the resulting slice size that they return. However, there are several cases where the slice size returned by Sprite is quite a bit larger than that returned by CodeSurfer. So as we can see from this comparison, CodeSurfer is more precise in its program slicing and will return the lowest slice size most of the time. However, this comparison does not take into account the amount of time that it takes both CodeSurfer and Sprite to compute the slices. This leaves the question of which is the best unanswered, since time is a valuable resource that should not be ignored.

Page 8: University of Wisconsin Platteville | UW-Plattevillepeople.uwplatt.edu/.../f12/RahbergerC_Program_Slicing.docx · Web viewIn debugging, program slicing can help narrow down the search

8

Future of Program Slicing

Since the beginning of program slicing, the number of techniques has been rapidly increasing. These techniques have been created or modified to help with all areas of programming, but there is always the next step. The current slicing techniques can use great amounts of resources to compute a slice. The next step would be to improve the slicing techniques so they are not so expensive, but can also give an exact representation of the point of interest.

The future of program slicing could also be pushing towards usability. Slicing tools that require less work on the programmer to set and define all the variables would increase the use among programmers across the board. As of right now, unless the program is quite large, it would be easier for the programmer to logically read over the code instead of determining the variables to compute a slice. Increasing the usability to a plug-in to the developing tools such as Visual Studio would greatly improve program slicing and its usability.

Figure 8: Comparison Between CodeSurfer and Sprite [1]

Page 9: University of Wisconsin Platteville | UW-Plattevillepeople.uwplatt.edu/.../f12/RahbergerC_Program_Slicing.docx · Web viewIn debugging, program slicing can help narrow down the search

9

Conclusions

Program slicing through its evolution has been able to solve a wide range of problems. The newer techniques are more precise and have better performance compared to their predecessors. Also, as the different techniques are combined with each other they will be able to help solve problems that were previously unanswered. The resulting slices from these techniques, as long as they are precise, can only help programmers improve their performance as well as their understanding of different programs. Although, at the moment, the resources needed to compute larger more precise slices is an issue. But as the speed of computers continues to climb, so does the size and precision of program slicing. Overall, program slicing can help any programmer from the debugging and testing stages all the way up to the maintenance and reengineering stages.

References

[1]. Binkley, D., & Harman, M. (2004). A Survey of Empirical Results on Program Slicing. Advanced Computing, 62, 105-178. Retrieved October 27, 2012, from http://eres.lndproxy.org/edoc/FacPubs/loy/BinkleyDW/SurveyOfEmpirical-04.pdf

[2]. Harman, M., & Hierons, R. (2001). An Overview of Program Slicing. Software Focus, 2(3), 85-92. Retrieved October 27, 2012, from http://docis.info/strip/docis/lib/ligo/rclis/dbl/soffoc/(2001)2%253A3%253C85%253AAOOPS%253E/www.brunel.ac.uk%252F~cssrllh%252FGusttReview%252FPublications_dir%252Ffocus.pdf

[3]. Sasirekha, N., Robert, A. E., & Hemalatha, M. (2011, July). Program Slicing Techniques and Its Applications. International Journal of Software Engineering & Applications, 2(3), 50-64. Retrieved October 21, 2012, from http://airccse.org/journal/ijsea/papers/0711ijsea04.pdf

[4]. Silva, J. (2012, June). A Vocabulary of Program Slicing-Based Techniques. ACM Computing Surveys, 44(3), 12:1-12:41. Retrieved September 12, 2012, from http://dl.acm.org/citation.cfm?id=2187674

[5]. Tip, F. (1995). A Survey of Program Slicing Techniques. Java Programming Language, 3, 121-189. Retrieved October 27, 2012, from http://www.cse.buffalo.edu/LRG/CSE705/Papers/Tip-Slicing-Survey.pdf

[6]. Weiser, M. (1984, July). Program Slicing. IEEE Transactions of Software Engineering, 10(4), 352-357. Retrieved October 21, 2012, from http://www.cse.buffalo.edu/LRG/CSE705/Papers/Weiser-Static-Slicing.pdf