tfm-report/Secciones/motivation.tex

131 lines
6.7 KiB
TeX
Raw Normal View History

2019-11-15 22:34:58 +01:00
% !TEX encoding = UTF-8
% !TEX spellcheck = en_US
% !TEX root = ../paper.tex
\chapter{Introduction}
\label{cha:introduction}
\section{Motivation}
\label{sec:motivation}
2019-12-03 15:12:13 +01:00
Program slicing~\cite{Wei81} is a debugging technique that, given a line of
code and a set of variables of a program, simplifies such program so that the only parts
left of it are those that affect or are affected by the values of the selected variables.
2019-11-15 22:34:58 +01:00
\begin{example}[Program slicing in a simple method]
2019-12-03 15:12:13 +01:00
If the left program is sliced on (line 5, variable \texttt{x}), the
result would be the program on the right, with the \texttt{if} block
removed, as it does not affect the value of \texttt{x}.
2019-11-15 22:34:58 +01:00
\label{exa:program-slicing}
\begin{center}
\begin{minipage}{0.49\linewidth}
\begin{lstlisting}[stepnumber=1]
void f(int x) {
if (x < 0)
System.err.println(x);
x++;
System.out.println(x);
}
\end{lstlisting}
\end{minipage}
\begin{minipage}{0.49\linewidth}
\begin{lstlisting}[stepnumber=1]
void f(int x) {
x++;
System.out.println(x);
}
\end{lstlisting}
\end{minipage}
\end{center}
\end{example}
2019-12-03 15:12:13 +01:00
Slices are executable programs whose execution produces the same values
for the specified line and variable as the original program, and they are used to
facilitate debugging of large and complex programs, where the control and data flow may not
2019-11-15 22:34:58 +01:00
be easily understandable.
Though it may seem a really powerful technique, the whole Java language is not
completely covered by it, and that makes it difficult to apply in practical
2019-12-03 15:12:13 +01:00
settings. An area that has been investigated, yet does not have a definitive
2019-11-15 22:34:58 +01:00
solution yet is exception handling. Example~\ref{exa:program-slicing2}
demonstrates how, even using the latest developments in program
2019-12-03 15:12:13 +01:00
slicing~\cite{AllH03}, the sliced version does not include the catch block, and
therefore does not produce a correct slice.
2019-11-15 22:34:58 +01:00
2019-12-03 15:12:13 +01:00
\begin{example}[Program slicing with exceptions]
If the following program is sliced using Allen and Horwitz's proposal~\cite{AllH03} with respect to (line 17, variable \texttt{a}), the
2019-11-15 22:34:58 +01:00
slice is incomplete, as it lacks the \texttt{catch} block from lines 4-6.
\label{exa:program-slicing2}
\begin{center}
\begin{minipage}{0.49\linewidth}
\begin{lstlisting}[stepnumber=1]
2019-12-03 15:12:13 +01:00
void f(int x) throws Exception {
2019-11-15 22:34:58 +01:00
try {
g(x);
2019-12-03 15:12:13 +01:00
} catch (Exception e) {
2019-11-15 22:34:58 +01:00
System.err.println("Error");
}
System.out.println("g() was ok");
2019-12-03 15:12:13 +01:00
g(x + 1);
2019-11-15 22:34:58 +01:00
}
2019-12-03 15:12:13 +01:00
void g(int a) throws Exception {
if (a == 0) {
throw new Exception();
2019-11-15 22:34:58 +01:00
}
2019-12-03 15:12:13 +01:00
System.out.println(a);
2019-11-15 22:34:58 +01:00
}
\end{lstlisting}
\end{minipage}
\begin{minipage}{0.49\linewidth}
\begin{lstlisting}[stepnumber=1]
2019-12-03 15:12:13 +01:00
void f(int x) throws Exception {
2019-11-15 22:34:58 +01:00
try {
g(x);
}
2019-12-03 15:12:13 +01:00
g(x + 1);
2019-11-15 22:34:58 +01:00
}
2019-12-03 15:12:13 +01:00
void g(int a) throws Exception {
if (a == 0) {
throw new Exception();
}
System.out.println(a);
2019-11-15 22:34:58 +01:00
}
\end{lstlisting}
\end{minipage}
\end{center}
2019-12-03 15:12:13 +01:00
When the program is executed as \texttt{f(0)}, the execution log would be: \texttt{1, 2, 3, 13, 14, 15, 4, 5, 8, 10, 13, 14, 17}. In the only execution of line \texttt{17}, variable \texttt{a} has value 1 in that line. However, in the slice produced, the execution log is \texttt{1, 2, 3, 13, 14, 15}. The exception thrown in \texttt{g()} is not caught in \texttt{f()}, so it returns with an exception and line \texttt{17} never executes.
2019-11-18 14:49:48 +01:00
2019-12-03 15:12:13 +01:00
The problem in this example is that the \texttt{catch} block in line \texttt{4} is not included, because ---according to the dependency graph shown below--- it does not influence the execution of line \texttt{17}. Two kinds of dependencies among statements are considered: data dependence (a variable is read that may have gotten its value from a given statement) and control dependence (the instruction controls whether another executes).
In the graph, the slicing criterion is marked in bold, the nodes that represent the slice are filled in grey, and dependencies are displayed as edges, with control dependencies in black and data dependencies in red. Nodes with a dashed outline represent elements that are not statements of the program.
2019-11-18 14:49:48 +01:00
2019-12-03 15:12:13 +01:00
\begin{center}
\includegraphics[width=\linewidth]{img/motivation-example-pdg}
\end{center}
\end{example}
2019-11-18 14:49:48 +01:00
2019-12-03 15:12:13 +01:00
Example~\ref{exa:program-slicing2} showcases an important error in the current slicing procedure for programs that handle errors with exceptions; because the \texttt{catch} block is disregarded. The only way a \texttt{catch} block can be included in the slice is if a statement inside it is needed for another reason. However, Allen and Horwitz did not encounter this problem in their paper~\cite{AllH03}, as the values outputted by method calls are extracted after the \texttt{normal return} and each \texttt{catch}, and in a typical method call with output, the \texttt{catch} is included by default when the outputted value is used. This detail makes the error much smaller, as most \texttt{try-catch} structures are run to obtain a value.
2019-11-15 22:34:58 +01:00
2019-12-03 15:12:13 +01:00
A notable case where a method that may throw an exception is run and no value is recovered (at least from the point of view of program slicing) is when writing to the filesystem or making connections to servers, such as a database or a webservice to store information. In this case, if no confirmation is outputted signaling whether the storage of information was correct, the \texttt{catch} block will be omitted, and the slicer software will produce an incorrect result.
2019-11-15 22:34:58 +01:00
\section{Contributions}
2019-12-03 15:12:13 +01:00
The main contribution of this paper is a complete technique for program slicing programs in the presence of exception handling constructs for Java. This technique extends the previous technique by Allen et al. \cite{AllH03}. It considers all cases considered in that work, but it also provides a solution to cases not considered by them.
2019-11-18 14:49:48 +01:00
2019-12-03 15:12:13 +01:00
For the sake of completeness and in order to understand the process that leaded us to this solution, we will present a brief history of program slicing, specifically those changes that have affected exception handling. Furthermore, we provide a summary of the
2019-11-15 22:34:58 +01:00
different contributions each author has made to the field.
2019-12-03 15:12:13 +01:00
The rest of the paper is structured as follows: chapter~\ref{cha:background} summarizes the theoretical background required in program slicing and exception handling, chapter~\ref{cha:incremental} will analyze each structure used in exception handling, explore the already available solution and propose a new technique that subsumes all of the existing solutions and provides correct slices for each case.
Chapter~\ref{cha:state-art} provides a bird's eye view of the current state of the art, chapter~\ref{cha:solution} provides a summarized description of the new algorithm with all the changes proposed in chapter~\ref{cha:incremental}, and finally, chapter~\ref{cha:conclusion} summarizes the paper and explores future avenues of work.
2019-11-15 22:34:58 +01:00
% vim: set noexpandtab:tabstop=2:shiftwidth=2:softtabstop=2:wrap