[Soot-list] Re: Help Needed

Ondrej Lhotak olhotak at uwaterloo.ca
Mon Feb 19 10:03:09 EST 2007


Attached is code that I use to build and print out a Soot call graph.
I ran it with the following command line to print out a call graph
for your example:
    java olhotak.CallGraphDumper -w HelloWorld
Hopefully you can use it as a starting point for your own code.

On Mon, Feb 19, 2007 at 04:31:48PM +0530, John Chaitanya Kati wrote:
> Hi,
>    This personal mail is because of the my inability to make out the things
> to work by the answers i got in the mailing list. I am in real need of
> getting the call graph for my program. I dont know what i am missing, but
> i am writing the detailed steps i am following.
> 
> The program is Call.java(which is there in the mailing list) which is
> supposed to construct call graph for HelloWorld.java '
> 
> /*******************Call.java***********************************/ 
> import soot.*;
> import soot.util.*;
> import soot.jimple.toolkits.callgraph.CallGraph;
> public class Call
> {
> 
> 	public static void main(String args[])
> 	{
> 		String strClass = "HelloWorld";
> 		Scene.v().loadBasicClasses();
> 		SootClass sootClass = 
> 		Scene.v().loadClassAndSupport(strClass);
> 
> 		System.out.println("Number of methods in " + 
> 		sootClass.getName() + ": " + sootClass.getMethodCount());
> 		String[] opts = {"-w" , strClass};
> 
> 		System.out.println("Set Application classes");
> 		sootClass.setApplicationClass();
> 		Scene.v().setMainClass(sootClass);
> 		Main.main(opts);
> 		CallGraph cg = Scene.v().getCallGraph();
> 		if(cg==null)
> 		{
> 		System.out.println("Call graph is equal to null,exiting!");
> 		}
> 		else
> 		{
> 			System.out.println("Call graph is non null");
> 		}
> 
> 	}
> }
> 
> /**********************My HelloWorld.java is *******************/
> Class HelloWorld
> {
> 	static public void main(String args[])
> 	{
> 		System.out.println("Hai");
> 	}
> }
> 
> Initially i run javac Call.java and javac HelloWorld.java
> 
> then i run java soot.Main -app Call
> then it writes the output to sootOutput/Call.class
> 
> then i tried running java Call
> but it gives the SIGNATURE error
> Exception in thread "main" java.lang.RuntimeException: This operation 
> requires resolving level SIGNATURES but java.lang.Thread is at resolving 
> level HIERARCHY
> 
> 
> Please help me, i must be missing something badly. And i am not able to 
> make out. Waiting for your answer.
> 
> 
> 
> 
> -- 
> Thanking you
> yours sincerely
> John
> 
-------------- next part --------------
package olhotak;
import soot.*;
import java.util.*;
import java.io.*;
import soot.jimple.*;
import soot.util.queue.*;
import soot.jimple.toolkits.callgraph.*;

public class CallGraphDumper extends SceneTransformer {
    public static void main(String[] args) 
    {
	PackManager.v().getPack("wjtp").add(
	    new Transform("wjtp.dumpcg", new CallGraphDumper()));

	soot.Main.main(args);
    }

    protected void internalTransform(String phaseName, Map options)
    {
        CallGraph cg = Scene.v().getCallGraph();

        Iterator it = cg.listener();
        while( it.hasNext() ) {
            soot.jimple.toolkits.callgraph.Edge e =
                (soot.jimple.toolkits.callgraph.Edge) it.next();
            System.out.println(""+e.src()+e.srcStmt()+" ="+e.kind()+"=> "+e.tgt());
        }
    }
}



More information about the Soot-list mailing list