[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EdgesOutOf



On Tue, 21 Sep 2004, Navindra Umanee wrote:

> Navindra Umanee <navindra@cs.mcgill.ca> wrote:
> > I will look at this closely and see what needs to be done to fix this.
>
> It seems that long ago I fixed this bug in my own internal/working
> copy, but forgot to update trunk (or maybe I didn't think anyone else
> was really using whole-shimple). :(
>
> It is very simple, but you will have to patch soot/PackManager.java
> and recompile it.  Guillaume, can you make this update to your copy of
> Soot and give it a try?  Let me know if you need any assistance.

Thanks for your help. I patched the file, and rebuilt soot using ant,
but it doesn't seem to fix my problem: I still have an empty Iterator
when asking for edgesOutOf(theStmt)

I'm attaching a sample file (EdgesOutOfAnalysis.java) that demonstrates
the problem :
The whole program is analyzed, statement by statement, but the callgraph
still fails to tell us which method a statement could actually call.
(the tgtIt iterator is always empty)

Navindra, could you please execute my analysis with *your* version of
soot, and tell me if it works ?
Maybe i've missed something while patching/rebuilding soot.

thanks,

-G
-- 
Guillaume Salagnac
Equipe "Systèmes Temporisés et Hybrides." Verimag. Grenoble. France.
# Makefile - Guillaume Salagnac  - mar 14 sep 2004, 13:51
# Time-stamp: "2004-09-21 18:35:44 salagnac" 


JCC=javac


auto: all

exec: all
	java -mx400m Main Foo RefObject
	bell

all: $(addsuffix .class,$(basename $(wildcard *.java)))

%.class: %.java
	$(JCC) $^


##############"

clean:
	rm -f *.class *~ 

remake: clean all
// EdgesOutOfAnalysis.java - Guillaume Salagnac  - lun 13 sep 2004,  9:53
// Time-stamp: "2004-09-21 18:51:45 salagnac" 


import java.io.*;
import java.util.*;
import java.lang.*;

import soot.*;
import soot.jimple.*;
import soot.shimple.*;
import soot.jimple.toolkits.callgraph.*;
import soot.tagkit.*;
import soot.toolkits.graph.*;
import soot.toolkits.scalar.*;
import soot.tools.*;
import soot.util.*;

class EdgesOutOfAnalysis extends SceneTransformer
{
    private static EdgesOutOfAnalysis instance = new EdgesOutOfAnalysis();
    private EdgesOutOfAnalysis() {}

    public static EdgesOutOfAnalysis v() { return instance; }

    protected void internalTransform(String phaseName, Map options)
    {
        System.out.println("======================================== Start freshness analysis");

        CallGraph cg=Scene.v().getCallGraph();
        
        Iterator clIt=Scene.v().getApplicationClasses().iterator();
        System.out.println("Application classes:\n");
        while(clIt.hasNext())
        {
            SootClass cl=(SootClass)clIt.next();
            System.out.println("==================== "+cl);
            Iterator mIt=cl.getMethods().iterator();
            while(mIt.hasNext())
            {
                SootMethod theMethod = (SootMethod) mIt.next();
                System.out.println("========== "+theMethod);
                
                if(!theMethod.hasActiveBody()) continue;
                
                Body body=theMethod.getActiveBody();
                
   
                /*******************/
                Chain units = body.getUnits();
                
                System.out.println(units.size()+" instructions");
                    
                Iterator stmtIt = units.iterator();
                while(stmtIt.hasNext())
                {
                    System.out.println("");
                    Stmt theStmt = (Stmt) stmtIt.next();
                    System.out.println(theStmt+" ("+theStmt.getClass()+")");

                    if(theStmt.containsInvokeExpr())
                    {

                        InvokeExpr ie=theStmt.getInvokeExpr();
                        System.out.println("invokeExpr: "+ie);

                        // the simple way, incorrect
                        SootMethod targetBySig=ie.getMethod();
                        System.out.println("    calls (sig)"+targetBySig);

                        // the correct way, if it worked !
                        Iterator tgtIt=cg.edgesOutOf(theStmt);
                        while(tgtIt.hasNext())
                        {
                            Edge e=(Edge)tgtIt.next();
                            SootMethod targetByCG=e.getTgt().method();
                            System.out.println("    calls (CG)"+targetByCG);
                            
                        }
                    }

                }//stmtIt.hasNext()
            }//mIt.hasNext();
        }//clIt.hasNext();
            
        System.out.println("======================================= Finished freshness analysis");
    }


}

// Main.java - Guillaume Salagnac  - lun 13 sep 2004,  9:51
// Time-stamp: "2004-09-21 18:24:37 salagnac" 

import soot.*;
import soot.jimple.*;
import soot.tagkit.LineNumberTag;
import soot.tagkit.Tag;
import soot.toolkits.scalar.*;
import soot.toolkits.graph.CompleteUnitGraph;
import soot.util.*;

import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        if(args.length == 0)
        {
            System.out.println("Syntax: Main [soot options] ClassToAnalyze");
            System.exit(0);
        }

        String[] optsDefault = {"-ws",
                                "-f","S",
                                "-p","cg","verbose:true"};
        String[] opts= new String[optsDefault.length + args.length];
        for(int i=0;i<optsDefault.length;i++)
            opts[i]=optsDefault[i];
        for(int i=0;i<args.length;i++)
            opts[i+optsDefault.length]=args[i];

        PackManager.v().getPack("wstp").add(new Transform("wstp.EdgesOutOfAnalysis",
                                                         EdgesOutOfAnalysis.v()));
        
        soot.Main.main(opts);
        
    }

}
// RefObject.java - Guillaume Salagnac  - lun 20 sep 2004, 15:32
// Time-stamp: "2004-09-20 15:32:59 salagnac" 

class RefObject
{
    Object f;

    public void ref(Object t)
    {
        f=t;
    }

    public String toString()
    {
        return "RefObject: "+f;
    }
}
// Foo.java - Guillaume Salagnac  - ven 17 sep 2004, 10:45
// Time-stamp: "2004-09-20 15:35:14 salagnac" 


import java.io.*;


public class Foo
{
    public static void main(String[] args)
    {
        Foo f=new Foo();

        RefObject o=new RefObject();
        Object a=f.m1(o);

        System.out.println("main:"+a);
    }

    

    RefObject m1(RefObject x)
    {
        Object g=new String("bli");
        x.ref(g);
        m2(g);

        RefObject r=m3();

        RefObject h=new RefObject();

        h.f=x;
        x.ref(r);
        
        return h;
    }

    void m2(Object x)
    {
        RefObject o=m4();
        o.f=x;
        System.out.println("m2:"+o);
    }

    RefObject m3p()
    {
        RefObject ret=new RefObject();

        return ret;
    }

    RefObject m3()
    {
        return new RefObject();
    }

    
    RefObject m4()
    {
        RefObject r=m3();
        return r;
    }
}