A precise monadic dynamic slicing method
Introduction
A program slice consists of the parts of a program that affect the values computed at some point of interest, referred to as a slicing criterion [43]. Program slicing can be divided into dynamic slicing and static slicing. A dynamic slice contains only those statements that actually affect the variables in a given slicing criterion for a given program input [1], [13], while static slicing does not take into account the program input. The applications of program slicing include program comprehension, program integration, software maintenance, debugging, testing, software measurement, reverse engineering, and services computing [2], [6], [7], [37], [51], [52], [53]. In software testing and maintenance phases, dynamic slicing is preferable because it can extract smaller slices than those obtained by static slicing [4], [34]. This paper focuses on dynamic slicing, although the methodology could also be applied to static slicers.
Some dynamic slicing methods have been proposed in [1], [13], [24], [25], [33], [36], [44], [45], [57], where the review and comparisons of such approaches were given as well. Most of them fall into two categories: backward and forward slicing. A backward slice consists of all statements of the program that can have some effect on the slicing criterion, whereas a forward slice contains those statements of the program that are affected by the slicing criterion. Backward slicing can assist a developer to locate the parts of the program which contain a bug. Forward slicing can be used to predict the parts of a program that will be affected by a modification. In forward dynamic slicing, introduced firstly by G. Tibor et al. [12], [33], [36], the dynamic slices for each statement are computed immediately after the statement is executed. Once the last statement is executed, the dynamic slices of all statements executed have been obtained. Inspired by this idea, we will build dynamic slices on the semantics of programming languages.
The main difficulty of dynamic slicing is to obtain the run time information. Most of the existing methods use relationship graphs or diagrams, and trace the execution of the program using an execution history. As a result, these methods require a fairly large amount of memory space to record the execution history, proportional to the program execution length.
In addition, the existing slicing methods are incremental, sequential, not combinatorial or not parallelizable easily for multi-core systems. However modern programming languages support modularized programming and programs often consist of a set of modules. So the program analysis should reflect this design technology, and their methods (including program slicing) should be flexible, combinable, and parallelizable for improving the efficiency.
As the behavior of a program is determined by the semantics of the programming language, it is reasonable to expect a dynamic slicing method based on the formal semantics of the programming language. On the basis of this view, this paper will give a formal approach for dynamic slicing, which is based on the formal semantics of programming languages. It can compute slices directly on abstract syntax, without explicit construction of intermediate structures such as dependence graphs, or a record for an execution history.
The paper has the following main contributions:
- •
Monad technology gives our monadic algorithms for dynamic slicing the properties of flexibility and combinability. The redesigned dynamic-slice monad transformer provides the power to transformer a given monad (which represents a computation) into a dynamic slice monad that contains both the dynamic-slice operations and those of the former monad.
- •
The clear operational interpretation of the modular monadic semantics is ready for the feasibility and implementation of monadic slicing algorithms. The descriptions of our slicing algorithms are easily integrated in the modular monadic semantics of programs analyzed, so this readily allows us to formally prove that our monadic slicing results are precise.
- •
The features such as arbitrary precision integer arithmetic, infinite lists, powerful abstraction and lazy evaluation of the implementation language Haskell [31], [35] will come in handy for our monadic slicing of programs with large execution history. What's more, Haskell's modern compiler GHC (Glasgow Haskell Compiler) makes our monadic slicer effective and parallelizable.
The rest of the paper is organized as follows: In Section 2, we briefly introduce the concepts of monads and monad transformers. Readers who are familiar with these concepts may skip this section. In Section 3, the framework of modular monadic semantics is illustrated through a simple example language. The computation of dynamic program slicing is abstracted using a dynamic slice-monad transformer in Section 4. In Sections 5 and 6, we discuss and illustrate, in detail, our dynamic slicing algorithm basing on modular monadic semantics. In Section 7, we address the implementation, the time and space complexity analysis, and the experimental evidence of the effectiveness and parallelizability of our slicing algorithm. We in Section 8 talk over related work. We conclude with Section 9, which also gives directions for future work.
Section snippets
Monads
Monads, originally coming from philosophy, were discovered in category theory in the 1950s and introduced to the semantics community by Moggi [20] in 1989. Later, Wadler [40], [41] popularized Moggi's ideas in the functional programming community. One of the distinguishing features of functional programming is the widespread use of combinators to construct programs [10]. A combinator is a function which builds a new program fragment from some existing ones. A programmer can use combinators to
Modular monadic semantics of the example language W
In this section, we first present modular monadic semantics and then give an example of modular monadic semantics with a simple imperative programming language. Modular monadic semantics specifies the semantics of a language by a mapping from terms (environments or continuations) to computations performed within a monad. Differ from traditional denotational semantics, which maps a term to an answer, monadic semantics maps terms to computations, where the details of the environment, store, etc.
Dynamic slice-monad transformer
As mentioned above, each monad transformer represents a single notion of computation. Since dynamic program slicing can be viewed as a computation, we can abstract it as a language-independent notion of a computation by using a dynamic slice-monad transformer DSliceT, which merges a dynamic slice monad DSlice (defined as follows) with an arbitrary monad m.
The dynamic slice monad DSlice represents a computation with result type a and a slice table of type st.
A monadic dynamic slicing algorithm
The main idea of dynamic slicing algorithms based on modular monadic semantics of a program can be briefly stated as follows: for obtaining a dynamic slice, we firstly apply the dynamic slice transformer DSliceT to the semantic building blocks of the program analyzed. It makes the resulting semantic description include the feature of the dynamic slice semantic. According to the semantic description, we then execute this program with an input. Finally, we obtain the dynamic slices of all single
An example
In this section we illustrate the precise algorithm proposed above using the example W-program given in Fig. 6(1). This sample comes from the Example 1 in [24], where G.B. Mund et al. considered the input values m = 2, x = 0 in the first iteration of the while loop, and x = 2 in the second iteration. The result of the dynamic slice with respect to 〈INPUT, 19, z〉 and INPUT = (m = 2, x = 0; 2), which is shown in Fig. 6(2), was obtained by adopting the forward dynamic slice algorithm. Its slice result is more
Implementation of MSlicer
With the help of the monad transformers, modular monadic semantics achieves a high level of modularity and combinability. Despite this, it is still executable: there is a clear operational interpretation of the semantics [42]. In [11], [16], [17], [18], [42], some modular compilers/interpreters using monad transformers were constructed. On the basis of these works, our monadic approach for dynamic program slicing is feasible.
On the basis of Labra's language prototyping system LPS [14], which
Related work
Relatively few program slicing methods focus on the semantics of programs. G. Canfora et al.’s conditioned slicing [3] adds a condition to a slicing criterion. Statements that do not satisfy the condition are deleted from the slice. M. Harman et al.’s amorphous slicing [8] allows for any simplifying transformations which preserve this semantic projection. However, these two methods are not really based on the formal semantics of the programming language. P.A. Hauser's denotational slicing [9],
Conclusions and future work
Program slicing methods (including static and dynamic ones) have been widely used in many software activities, such as software analyzing, understanding, debugging, testing, maintenance, and so on. In applications such as debugging, testing, and maintenance, the dynamic slicing method is preferable since it can extract more precise results.
In this paper, we introduce a formal approach for precise dynamic program slicing, called monadic dynamic slicing which is based on the monadic semantics.
Acknowledgments
The work was partially funded by the NSF of China under grant No.61300054, the Open Foundation of Guangxi Key Laboratory of Trusted Software, the Priority Academic Program Development of Jiangsu Higher Education Institutions (PAPD), and the Qing Lan Project of Jiangsu Province.
References (58)
- et al.
Program slicing
Adv. Comput.
(1996) - et al.
Conditioned program slicing
Inf. Software Technol.
(1998) Generalising monads to arrows
Sci. Comput. Program.
(2000)- et al.
Dynamic program slicing methods
Inf. Software Technol.
(1998) Notions of computation and monads
Inf. Comput.
(1991)- et al.
An efficient dynamic program slicing technique
Inf. Software Technol.
(2002) - et al.
Computation of intraprocedural dynamic program slices
Inf. Software Technol.
(2003) - et al.
Web service publishing and composition based on monadic methods and program slicing
Knowl. Based Syst.
(2013) - et al.
Dynamic program slicing
- et al.
Handling the unstructured statements in the forward dynamic slice algorithm
Semantic Lego
Using program slicing in software maintenance
IEEE Trans. Software Eng.
An overview of program slicing
Software Focus
Amorphous program slicing
Denotational program slicing
A modular interpreter built with monad transformers
Forward computation of dynamic program slices
A language prototyping system using modular monadic semantics
Reusable monadic semantics of object oriented programming languages
Monad transformers and modular interpreters
Modular denotational semantics for compiler construction
Modular Monadic Semantics and Compilation
Unions of slices are not slices
An Abstract View of Programming Languages
PATRICIA–practical algorithm to retrieve information coded in alphanumeric
J. ACM
Semantics, modularity, and rewriting logic
Fast mergeable integer maps
A denotational interprocedural program slicer
Cited by (5)
Information Development and Student Talent Cultivation of Modern Chinese Language and Literature in the Context of Big Data
2024, Applied Mathematics and Nonlinear SciencesSymPas: Symbolic Program Slicing
2021, Journal of Computer Science and TechnologySymPas: Symbolic Program Slicing
2019, arXivMonadic Dynamic Slicing of Object-Oriented Programs
2018, Proceedings - 2018 International Conference on Cyber-Enabled Distributed Computing and Knowledge Discovery, CyberC 2018Intra-procedural slicing using program dependence table
2018, CEUR Workshop Proceedings