PROGRAM SLICING BASED TECHNIQUES By Corey Rahberger Overview
PROGRAM SLICING – BASED TECHNIQUES By Corey Rahberger
Overview � What is program slicing? � History � How to extract a slice � Program slicing techniques � Applications � Program slicing tools � Current Problems � Future
What is program slicing? � The process of computing a slice of a program � A slice is a subset of the original program, which contains portions of the program that are related to the slicing criterion used to create the slice � The slicing criterion is the point of interest or variable(s) that are being investigated
Program Slicing Example int i; int sum = 0; int product = 1; for(i = 0; i < N; i++) { sum = sum + 1; product = product * I; } write(sum); write(product); int i; int sum = 0; Original Program Slice on statement “write(sum)” for(i = 0; i < N; i++) { sum = sum + 1; } write(sum);
History First introduced by Mark Weiser in 1984 through publication in IEEE Transactions on Software Engineering � Original ideas were in his Ph. D. dissertation (1979) from University of Michigan, Ann Arbor � Chief scientist at Xerox PARC � Switched his focus to ubiquitous computing � http: //www-sul. stanford. edu/weiser/
History � Researchers have expanded on Weiser’s original definition into multiple directions � Huge amounts of program slicing techniques have been created to encompass all programming paradigms � Different surveys have been made to compare the techniques, but the results have been inconclusive
How to extract a slice � First, the dependences must be found between the different statements � These dependences can be represented in a data structure called a control flow graph (CFG) � A control flow graph shows all the execution paths that a program might take
Control Flow Graph 1) 2) 3) 4) 5) 6) 7) 8) 9) 10) 11) 12) 13) 14) 15) 16) 17) 18) read(text); read(n); lines = 1; chars = 1; subtext = “”; c = get. Char(text); while ( c != ‘eof’) if (c == ‘n’) then lines = lines + 1; chars = chars + 1; else chars = chars + 1; if (n != 0) then subtext = subtext + c; n = n – 1; c = get. Char(text); write(lines); write(chars); write(subtext); � In the CFG, each node is represented by a number that corresponds to a line number of the program
Problem with Control Flow Graph � Problem with control flow graph �Does not include data dependences � Solution �Add data dependencies to the graph
Program Dependence Graph � This new 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. ” (Silva)
Program Dependence Graph 1) 2) 3) 4) 5) 6) 7) 8) 9) 10) 11) 12) 13) 14) 15) 16) 17) 18) read(text); read(n); lines = 1; chars = 1; subtext = “”; c = get. Char(text); while ( c != ‘eof’) if (c == ‘n’) then lines = lines + 1; chars = chars + 1; else chars = chars + 1; if (n != 0) then subtext = subtext + c; n = n – 1; c = get. Char(text); write(lines); write(chars); write(subtext);
Program Dependence Graph � Since both flow and data dependences are now found for the program, the program dependence graph can be used to compute slices of the program according to the slicing criterion � Graphs can get quite large and complex
Program Slicing Techniques There a huge amount of different techniques � We will look more closely into the three main techniques � � Static slicing � Dynamic slicing � Conditioned slicing
Static Slicing � Similar to what Weiser originally introduced � The resulting slice will work for all inputs � Usually results in a bigger slice
Static Slicing – Slicing Criterion � (s, v) �‘s’ represents the line number in the program �‘v’ represents the variable(s) that are of interest � Example �(7, x)
Static Slicing Example read(n); i : = 1; sum : = 0; product : = 1; while i <= n do begin 6) sum : = sum + 1; 7) product : = product * i; 8) i : = i + 1; end; 9) write(sum); 10) write(product); read(n); i : = 1; Original Program Slice of program w. r. t. criterion (10, product) 1) 2) 3) 4) 5) product : = 1; while i <= n do begin product : = product * i; i : = i + 1; end; write(product);
Static Slicing Uses � Debugging � Dead code removal � Program analysis � Software maintenance � Module cohesion analysis � Many more
Dynamic Slicing � Input(s) for the program are used to help determine the slice � Removes portions of the program that are not reached for the given input(s) � The resulting slice will not work for all executions of the program � Resulting slice is usually smaller than static slicing, but takes longer to compute
Dynamic Slicing – Slicing Criterion � (si, v, {ai, …, an}) �‘s’ represents the line number in the program �‘i’ represents the position in the execution history of statement ‘s’ �‘v’ represents the variable(s) that are of interest �‘{ai, …, an}’ represents the initial values or inputs � Example �(71, sum, {x = 1})
Dynamic Slicing Example (1) (2) (3) read(n); i : = 1; while (i <= n) do begin (4) if (i mod 2 = 0) then (5) x : = 17; else (6) x : = 18; (7) i : = i + 1; end; (8) write(x); read(n); i : = 1; while (i <= n) do begin if (i mod 2 = 0) then x : = 17; else ; i : = i + 1; end; write(x); Original Program Slice of program w. r. t. criterion (81, x, {n = 2})
Dynamic Slicing Uses � Debugging � Testing � Tuning Compilers
Conditioned Slicing � Combination of static and dynamic slicing � Provides information about the inputs values, but does not specify them exactly � Resulting slice is ranges between static and dynamic in size
Conditioned Slicing – Slicing Criterion � (i, F, s, v) �‘i’ represents the input variable(s) �‘F’ represents a logical formula on ‘i’ �‘s’ represents the line number in the program �‘v’ represents the variable(s) that are of interest � Example �(sales, F, 11, {total}), where F = (sales > 0)
Conditioned Slicing Example 1) 2) 3) 4) 5) 6) 7) 8) 9) 10) 11) 12) 13) 14) 15) 16) 17) 18) read(text); read(n); lines = 1; chars = 1; subtext = “”; c = get. Char(text); while ( c != ‘eof’) if (c == ‘n’) then lines = lines + 1; chars = chars + 1; else chars = chars + 1; if (n != 0) then subtext = subtext + c; n = n – 1; c = get. Char(text); write(lines); write(chars); write(subtext); Original Program (1) read(text); (2) read(n); (5) subtext = “”; (6) c = get. Char(text); (7) while ( c != ‘eof’) (8) if (c == ‘n’) then (12) if (n != 0) then (13) subtext = subtext + c; (14) n = n – 1; (15) c = get. Char(text); (18) write(subtext); Slice of program w. r. t. criterion ((text, n), F, 18, {subtext}), where F = (∀ c ∈ text, c != ‘n’. n > 0)
Conditioned Slicing Uses � Debugging � Software reuse � Ripple effect analysis � Understanding legacy code � Program comprehension
Applications � All the different techniques have made program slicing a useful tool in all areas of programming � Examples �Debugging �Cohesion measurement �Comprehension �Maintenance and reengineering �Testing
Program Slicing Tools � Sprite �Open source � Unravel �National Institute of Standards and Technology � Code. Surfer �University of Wisconsin Slicing Tool �Gramma. Tech
Code. Surfer � University of Wisconsin Slicing Tool �Developed 1996 -2000 �Susan Horwitz, Thomas Reps and others � Code. Surfer 1. 0 �Released in June 1999 �Derived from Wisconsin’s Slicing Tool
Code. Surfer � Language �C/C++ � Platforms �Windows �Linux �Solaris � Cost �Basic – (Locked) $795 (Floating) $1495 �Suite – (Locked) $3995 (Floating) $5995
NASA’s evaluation of Code. Surfer Johnson Space Center Safety and Mission Assurance Directorate, Flight Equipment Division � Reviewed the efficiency of Code. Surfer compared to doing it manually � Compared results from two projects � �Space Integrated Global Positioning System/Inertial Navigation System (SIGI) �Health Management System Defibrillator (Defib) Power and Data Interface Module (PDIM)
NASA’s evaluation of Code. Surfer COMBINED SIGI AND PDIM INSPECTION DATA Metric Manual Code inspection With Code. Surfer Inspection Time (hr) 17 12. 25 Lines of Code (LOC) 10650 Inspection Rate (LOC/hr) 626 869 Total Defects Found Using Method 8 18 Defects Found per Hour 0. 47 1. 47 Unique Defects Found Using Method 2 12
NASA’s evaluation of Code. Surfer � Drawbacks from Code. Surfer �Must be compiled using on a compiler provided with the tool �Training is required, which is expensive �Must use it regularly to remain knowledgeable on using Code. Surfer
Current Problems � Resources need to compute slices � It can take a while to compute slices � Usability of program slicing tools
Future � Rate at which slices can be computed � Usability � Integration into mainstream development tools
Conclusion � Program slicing techniques have been and are still constantly improving � Can be used in all the different programming paradigms � As soon as the usability has been increased, program slicing should become a well known and useful tool
Questions?
References � 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/Fac. Pubs/loy/Binkley. DW/Survey. Of. Empirical-04. pdf � 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%253 A 3%253 C 85%253 AAOOPS%253 E/ww w. brunel. ac. uk%252 F~cssrllh%252 FGustt. Review%252 FPublications_dir%252 Ffocus. pdf � 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/0711 ijsea 04. pdf � 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 � 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/CSE 705/Papers/Tip-Slicing. Survey. pdf � 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/CSE 705/Papers/Weiser-Static. Slicing. pdf
References (cont. ) � Lyle, Jim. "The Unravel Project. " The Unravel Program Slicing Tool. National Institute of Standards and Technology, 37 Mar. 1998. Web. 10 Dec. 2012. http: //hissa. nist. gov/unravel/ � Brown, Aaron. "Code. Surfer: It Slices, It Chops, But Doesn't Make Julienne Fries. " Gramma. Tech, n. d. Web. 10 Dec. 2012. http: //hiper. cis. udel. edu/lp/lib/exe/fetch. php/courses/cisc 879/codesurfer-demo. pdf � United States. Johnson Space Center Safety and Mission Assurance Directorate. Flight Equipment Division. Can Code. Surfer Increase Code Inspection Efficiency? By Markovich and Dan Freund. N. p. , n. d. Web. 10 Dec. 2012. http: //www. nasa. gov/centers/ivv/ppt/172689 main_Can. XCode. Surfer. XIncrease. XCode. XI nspection. XEfficiency. V 31. ppt � "Wisconsin Program-Slicing Project. " N. p. , n. d. Web. 10 Dec. 2012. http: //research. cs. wisc. edu/wpis/html/ � "Code. Surfer. " Gramma. Tech. N. p. , 2012. Web. 12 Dec. 2012. http: //www. grammatech. com/products/codesurfer/overview. html
- Slides: 38