[Soot-list] variable name conflict

Sergio Ferrero sferrero at ensoftcorp.com
Wed Jul 10 13:09:58 EDT 2013


I would like to extend the capabilities of the Jimple Editor that comes
with the Soot eclipse plugin.
One feature that I need to provide is Mark Occurrences. It should work as
the Eclipse editor for java files. Basically, when a variable identifier is
selected the editor should highlight the declaration and the places where
the variable is used.

I wondered how Soot handled the situation where same variable names are
declared in different blocks in the same method body, so that's why I
created the sample java code I posted in this thread.

This is a draft of the code I wrote to get the occurrences of a local
variable in a SootClass object.

private Set<ValueBox> getOccurrences(JimpleLocal l, SootClass c) {
 SootMethod m = getMethodDefiningLocal(l, c);
Body b = m.retrieveActiveBody();
        List<ValueBox> useAndDefBoxes = b.getUseAndDefBoxes();
        Set<ValueBox> occurrences = new HashSet<ValueBox>();
        for (ValueBox valueBox : useAndDefBoxes) {
        if (valueBox.getValue().equals(l)) {
        occurrences.add(valueBox);
        }
 }
        return occurrences;
}

private SootMethod getMethodDefiningLocal(JimpleLocal l, SootClass c) {

 for( Iterator<SootMethod> mIt = c.methodIterator(); mIt.hasNext(); ) {
            final SootMethod m = (SootMethod) mIt.next();
            if( !m.isConcrete() ) continue;
            Body b = m.retrieveActiveBody();
            if (b.getLocals().contains(l)) {
            return m;
            }
        }
 return null;
}

I'm pasting the Java and corresponding Jimple code from the original post
just for the purpose of self-containment.


public class Locals {
 public void testDeclarations() {
  // Block 1
{
 String x = "hello";
 }

// Block 2
 {
 char x = 'a';
 }

 // Block 3
 for (int x = 0; x < 10; x++) {
 }
 }
}


    public void testDeclarations()
    {
        soot.test.Locals this;
        java.lang.String x;
        char x;
        int x, temp$0, temp$1;

        this := @this: soot.test.Locals;
        x = "hello";
        x = 97;
        x = 0;

     label0:
        nop;
        if x < 10 goto label1;

        goto label2;

     label1:
        nop;
        nop;
        temp$0 = x;
        temp$1 = temp$0 + 1;
        x = temp$1;
        goto label0;

     label2:
        nop;
        return;
    }

As I said in my original post, all the occurrences of "x" in the body of
the method for the generated Jimple code refer to the last declaration of
"x" which is "int x" and this is wrong.
I would just expect Soot to handle this situation, maybe using different
variables names for x in the generated Jimple code.

Thanks
-S


On Wed, Jul 10, 2013 at 12:10 PM, Quentin Sabah <quentin.sabah at inria.fr>wrote:

> Could you package a minimal example demonstrating the problem ?
> With the minimal analysis code checking the usage of each Local and a
> minimal java program like the one you posted before ?
>
> Thanks.
>
> --
> Quentin Sabah, CIFRE Ph.D. student
> Grenoble University
> INRIA-SPADES                   | STMicroelectronics/AST
> Montbonnot, France             | Grenoble, France
> mailto:quentin.sabah at inria.fr  | mailto:quentin.sabah at st.com
> phone: +33 476 61 54 57        | phone: +33 476 58 44 14
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20130710/c4d92f47/attachment.html 


More information about the Soot-list mailing list