[Soot-list] Trying to build call graph from with a java program

vasrivastava@hssworld.com srivastava varun0007 at gmail.com
Sat Aug 29 23:22:25 EDT 2009


Hi , I am trying to build call graph for a class from a java program. I need
to take each method the class and build a call graph as if that method is
the main method. I haven't got any way of declaring any arbitrary method as
reachableMethod and continue call graph construction.
So i did following things
 sc = Scene.v().loadClassAndSupport(classFile); //classFile is the path of
class
Iterator<SootMethod> smIterator = sc.getMethods().iterator();
while (smIterator.hasNext()) {
SootMethod smInstance = smIterator.next();
        SootMethod main = new SootMethod("main",
        Arrays.asList(new Type[] {ArrayType.v(RefType.v("java.lang.String"),
1)}),
        VoidType.v(), Modifier.PUBLIC | Modifier.STATIC);
JimpleBody body = Jimple.v().newBody(main);
        main.setActiveBody(body);
       // here wrote code to make a virtualinvoke to the method of the class
smInstance
       --
       sc.addMethod(main);
       Scene.v().setMainClass(sc);
       CHATransformer.v().transform();
}

But this code throws exception
java.lang.RuntimeException: not declared: main
at soot.SootMethod.getDeclaringClass(SootMethod.java:183)
at
soot.jimple.toolkits.callgraph.OnFlyCallGraphBuilder.getImplicitTargets(OnFlyCallGraphBuilder.java:223)
at
soot.jimple.toolkits.callgraph.OnFlyCallGraphBuilder.processNewMethod(OnFlyCallGraphBuilder.java:182)
at
soot.jimple.toolkits.callgraph.OnFlyCallGraphBuilder.processReachables(OnFlyCallGraphBuilder.java:81)
at
soot.jimple.toolkits.callgraph.CallGraphBuilder.build(CallGraphBuilder.java:84)
at
soot.jimple.toolkits.callgraph.CHATransformer.internalTransform(CHATransformer.java:43)
at soot.SceneTransformer.transform(SceneTransformer.java:39)
at soot.SceneTransformer.transform(SceneTransformer.java:45)
at soot.SceneTransformer.transform(SceneTransformer.java:50)
Although addMethod call is suppose to set declared bit for main

Please help me in debugging this problem or let me know the right way of
getting call graph for any arbitrary method of a class.
Thanks
Varun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20090829/30d3a3f2/attachment.html 


More information about the Soot-list mailing list