[Soot-list] about the code coverage

Eric Bodden eric.bodden at mail.mcgill.ca
Tue Oct 7 19:25:57 EDT 2008


> I am using soot to do code coverage. So i modify the code in the tutorial
> about profiling. But i find all the two example are use static field to
> store the counter. I try to use non-static thing.

This should generally be no problem. The reason for why the tutorial
uses static counters is that those counters can be accessed quite
easily: You just reference a static field or call a static method. If
the counter is stored in an object then one has to fetch the object
first (somehow) in order to increment the counter.

> en, my way is as the follow: i find i can use blockGraph to get every block
> and i find every statement in block will be executed same times. so i try
> insert the add counter statement in one block not with every statement which
> to be analysis.

That sounds like a very good idea.

> because one body will have more than one blocks, so i want
> to use List to store the counter information of every block and  the print
> the list when return statement.

I would rather assign a unique number to each block at compile time
and then use a mapping (i.e. java.util.Map) to map each block number
to the number of times this block has been executed. As an alternative
you could also use an int array. Looking at your code I don't see how
the following lines make sense:

        if(blkCnt.size() <= blkIdx){
            blkCnt.add(0);
        }

This would work if it was a while-loop instead of an if-block but that
would be quite inefficient.

> After running the program, now i should have
> the infomation about how many time every block executing. then i use another
> program to get the information about source line number contianed by every
> block. So at last, i get the how many times every statement have executed.
> en, but i think my way is so complex, has there some easy way?

You can get the line numbers directly from Soot. If you pass
-keep-line-number to Soot then it will generate a Tag on each Stmt
which contains line number information. You can then for example
generate instrumentation code (at compile time; in Jimple) that looks
like the following Java code:

SourceLocation[] lineNumbers = {
   new SourceLocation(/*file of block 1*/, /*line of block 1*/),
   new SourceLocation(/*file of block 2*/, /*line of block 2*/),
   new SourceLocation(/*file of block 3*/, /*line of block 3*/),
   ...
};

In the end you can then just fetch the source location for each block
directly from the array. SourceLocation here is just a little class
that you have to implement yourself. It's just a tuple that holds a
String (the source file name) and a line number.

> question2:
> i have write the code and use soot to deal with the class which to be
> tested. but when i run the class which had been add some instrution, it
> report the error like this:
>>>>>>xj at xj-laptop:~/workspace/test/sootOutput$ java tester.TestClass
> Exception in thread "main" java.lang.VerifyError: (class: tester/TestClass,
> method: main signature: ([Ljava/lang/String;)V) Illegal use of nonvirtual
> function call
> Could not find the main class: tester.TestClass.  Program will exit.
> <<<<<
> can you give some suggestion?

That's a little hard to say. Apparently you generate invalid code. You
can try adding the -validate switch to Soot. This will validate your
generated Jimple code and may give you a clue about what's wrong.

Eric

-- 
Eric Bodden
Sable Research Group
McGill University, Montréal, Canada


More information about the Soot-list mailing list