7.7 Program slice strategy 195
7.7 Program slice strategy
7.7.1
Program slice assumptions
The program slice strategy assumes that a tool is available that will perform
control and data-flow analysis on the application and provide the slicing
information. Doing this analysis by hand can be quite tedious. If the vari-
able that has an incorrect value is a local variable, intraprocedural analysis
may suffice. Otherwise, interprocedural analysis is needed.
A program slice of a program, with respect to a specific location in a
program and a set of variables referenced at that location, is the set of state-
ments and predicates in the program that may affect the value of the vari-
ables at that location.
Intraprocedural analysis is performed within the scope of an individual
procedure (C++ function, Java method), lnterprocedural analysis is per-
formed across the boundaries of individual procedures (C++ functions, Java
methods) and is performed on all of the procedures in an executable pro-
gram. It can sometimes make sense to perform interprocedural analyses
within an intermediate level, such as a library or a Java package.
7.7.2
Program slice control structure
The next code sample shows the control structure for the program slice
strategy.
Identify a variable that has an incorrect value
Generate a slice of the application that shows all the
calculations that contributed to the value of
that variable, considering both control flow
and data flow
Do while there are more unexamined contributing
variables
Observe the values taken on by one of the variables
If any of the values of this variable are invalid,
Then
repeat the slicing process on this variable
End-if
End-do
The code segments that have all valid input values but
which contribute invalid values are the cause of the bug
I Chapter 7

Get Debugging by Thinking now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.