Elsevier

Knowledge-Based Systems

Volume 115, 1 January 2017, Pages 40-54
Knowledge-Based Systems

A precise monadic dynamic slicing method

https://doi.org/10.1016/j.knosys.2016.10.013Get rights and content

Abstract

Dynamic program slicing is useful in software debugging, testing and maintenance, because it can extract more precise results than those obtained by static slicing. In this paper, we propose a precise approach for dynamic program slicing, monadic dynamic slicing, which is based on modular monadic semantics. Firstly, we abstract the computation of dynamic slicing as an object of independent language, dynamic slice-monad transformer. Then we discuss and illustrate a modular monadic dynamic slice algorithm in detail. In this monadic algorithm, dynamic slices are computed on abstract syntax directly, without the need to explicitly construct intermediate structures such as dependence graphs, or to record an execution history. Finally, we address the implementation and complexity analysis of this algorithm. We conclude that the monadic approach has excellent flexibility, combinability and parallelizability properties.

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. newtypeDSlicelsta=DSlice{runDSlice::(

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)

  • D. Espinosa

    Semantic Lego

    (1995)
  • K.B. Gallagher et al.

    Using program slicing in software maintenance

    IEEE Trans. Software Eng.

    (1991)
  • M. Harman et al.

    An overview of program slicing

    Software Focus

    (2001)
  • M. Harman et al.

    Amorphous program slicing

  • P.A. Hausler

    Denotational program slicing

  • W. Kahl

    A modular interpreter built with monad transformers

  • B. Korel et al.

    Forward computation of dynamic program slices

  • J.E. Labra Gayo et al.

    A language prototyping system using modular monadic semantics

  • J.E. Labra Gayo et al.

    Reusable monadic semantics of object oriented programming languages

  • S. Liang et al.

    Monad transformers and modular interpreters

  • S. Liang et al.

    Modular denotational semantics for compiler construction

  • S. Liang

    Modular Monadic Semantics and Compilation

    (1998)
  • A. De Lucia et al.

    Unions of slices are not slices

  • E. Moggi

    An Abstract View of Programming Languages

    (1989)
  • D.R. Morrison

    PATRICIA–practical algorithm to retrieve information coded in alphanumeric

    J. ACM

    (1968)
  • P.D Mosses

    Semantics, modularity, and rewriting logic

  • J. Newbern
  • C. Okasaki et al.

    Fast mergeable integer maps

  • L. Ouarbya et al.

    A denotational interprocedural program slicer

  • Cited by (5)

    View full text