J
jacob navia
Suppose that you want to know where your program has
passed, i.e. the exact flow of the program.
A brute force solution is to make an array of n lines, n being
the number of lines in the function. At each line then, you increment
a variable like this:
// NRLINES is the number of lines in the program module
int lines[NRLINES];
int fn(int a)
{
int s;
a = a + 1; lines[__LINE__]++;
s = a -= 1; lines[__LINE__]++;
etc
}
At the end of the run, you write into a file all those arrays. For each
source file you get one.
Obviously this is very inefficient. In the concrete example
above it would suffice a single counter since if you get
into that function at all, all the counters must have the
same value, there are no iterations constructs, gotos etc.
Refining this we could say that it suffices a single counter
for each basic block, i.e. between a label and a control
flow instruction (jump).
Function calls are a problem because they could indirectly call
longjmp and jump to a function higher in the stack.
I would like to research this a bit. Does anyone here know of
references to this problem in the literature?
Thanks in advance
jacob
passed, i.e. the exact flow of the program.
A brute force solution is to make an array of n lines, n being
the number of lines in the function. At each line then, you increment
a variable like this:
// NRLINES is the number of lines in the program module
int lines[NRLINES];
int fn(int a)
{
int s;
a = a + 1; lines[__LINE__]++;
s = a -= 1; lines[__LINE__]++;
etc
}
At the end of the run, you write into a file all those arrays. For each
source file you get one.
Obviously this is very inefficient. In the concrete example
above it would suffice a single counter since if you get
into that function at all, all the counters must have the
same value, there are no iterations constructs, gotos etc.
Refining this we could say that it suffices a single counter
for each basic block, i.e. between a label and a control
flow instruction (jump).
Function calls are a problem because they could indirectly call
longjmp and jump to a function higher in the stack.
I would like to research this a bit. Does anyone here know of
references to this problem in the literature?
Thanks in advance
jacob