[Soot-list] Re: Call-graph example code not working

Eric Bodden eric.bodden at mail.mcgill.ca
Wed Jul 16 16:27:11 EDT 2008


Luckily I had some spare time to look into this. Turns out that this
is a documentation bug rather than a Soot bug. The guide just omitted
some crucial initialization calls. The default way of using soot is to
register a Transform and the just call soot.Main (see below). This
works.


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import soot.PackManager;
import soot.Scene;
import soot.SceneTransformer;
import soot.SootClass;
import soot.SootMethod;
import soot.Transform;
import soot.jimple.toolkits.callgraph.CHATransformer;
import soot.jimple.toolkits.callgraph.CallGraph;
import soot.jimple.toolkits.callgraph.Targets;

public class CallGraphExample
{
   public static void main(String[] args) {
	   List<String> argsList = new ArrayList<String>(Arrays.asList(args));
	   argsList.addAll(Arrays.asList(new String[]{
			   "-w",
			   "-main-class",
			   "testers.CallGraphs",//main-class
			   "testers.CallGraphs",//argument classes
			   "testers.A"			//
	   }));

	   PackManager.v().getPack("wjtp").add(new Transform("wjtp.myTrans", new
SceneTransformer() {

		@Override
		protected void internalTransform(String phaseName, Map options) {
		       CHATransformer.v().transform();
		       SootClass a = Scene.v().loadClassAndSupport("testers.A");
		       a.setApplicationClass();

		       SootMethod src = Scene.v().getMainClass().getMethodByName("doStuff");
		       CallGraph cg = Scene.v().getCallGraph();

		       Iterator targets = new Targets(cg.edgesOutOf(src));
		       while (targets.hasNext()) {
		           SootMethod tgt = (SootMethod)targets.next();
		           System.out.println(src + " may call " + tgt);
		       }
		}
		
	   }));
	
       args = argsList.toArray(new String[0]);

       soot.Main.main(args);
   }
}


2008/7/16 Gerald Sit <Gerald.Sit at student.cityu.edu.hk>:
> Hi.
>
> Bug filed. Thanks in advance.
>
> Gerald
>
>> Hi again.
>
>> I could look into this, the only problem is that I will be super busy
>> traveling and moving over the next couple of weeks. So unless this is
>> absolutely blocking you please file a bug report so that we don't
>> forget about it and I'll fix it later.
>
>> https://svn.sable.mcgill.ca/bugzilla/
>
>> Thanks a lot.
>> Eric
>



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


More information about the Soot-list mailing list