[Soot-list] Callgraphs, CHATransformer

Marco Bakera marco.bakera at tu-dortmund.de
Wed Feb 18 09:55:23 EST 2009


Hi Eric,

thank you for the fast answer. I tried the following code but again Soot exits 
when invoking the main method. Further, I was not able to see the scene 
transformer's internalTransform method being invoked.

Could you please tell me what is the problem with my simple implementation?


public class CallGraphGenerationTest {

	@Test
	public void testCallGraphGeneration() throws Exception {
		G.reset();
		
		CallGraphFetcher callGraphFetcher = new CallGraphFetcher();
		PackManager.v().getPack("wjtp").add(new Transform("wjtp.cgfetcher", 
callGraphFetcher));
		
		String args = "-w " + OmgClass.class.getName();
		System.out.println("CallGraphGenerationTest.testCallGraphGeneration() 
invoking soot with "+args);
		Main.main(args.split(" "));
	}
	
	private static class CallGraphFetcher extends SceneTransformer {

		private CallGraph callGraph;

		@Override
		protected void internalTransform(String phaseName, Map options) {
			System.out.println("CallGraphFetcher.internalTransform() fetching call 
graph from scene");
			this.callGraph = Scene.v().getCallGraph();
		}
		
		public CallGraph getCallGraph() {
			return callGraph;
		}
	}
	
	private static class OmgClass {
		
		private int a;
		private int b;
		@SuppressWarnings("unused")
		private int stop;
		
		public OmgClass(int a, int b) {
			this.a = a;
			this.b = b;
		}
		
		public void omfg(int c) {
			for (int i=a; i<c; i++) {
				System.out.println(c+b);
				omfg(--c);
			}
		}
		
		public static void main(String[] args){
			OmgClass it = new OmgClass(1, 10);
			it.omfg(6);
		}
	}
}


Best regards,
Marco.

On Wednesday 18 February 2009 15:21:03 Eric Bodden wrote:
> Hi.
>
> At the point at which you call transform(), nothing at all has been
> initialized. You should put your call to transform() into a
> SceneTransformer, preferably within the wjtp pack. Then you have to
> call Soot's main method. This will automatically take care of parsing
> the command line, initializing Soot accordingly and then calling your
> transformer.
>
> You may want to look at our tutorials, especially into this one here
> that explains the various packs and also how to insert a transform:
> http://www.bodden.de/2008/11/26/soot-packs/
>
> Eric
>
> 2009/2/18 André Lobitz <andre-lobitz at gmx.de>:
> > I am trying to create callgraphs using soot. Therefore i've added the
> > Soot-classes.jar to my library list and written a small class (see
> > below). I am only getting the error message
> >     [Call Graph] For information on where the call graph may be
> > incomplete, use the verbose option to the cg phase.
> > and a NullPointerException. It seems to be the call
> >     CHATransformer.v().transform();
> > throwing the Exception. Can anyone help me?
> >
> > Thanx,
> > André
> >
> > -------------------------------------------------------------------------
> >--------------------------------------------------------------------------
> >-----------------
> >
> > package diplom.main;
> >
> > import soot.jimple.toolkits.callgraph.*;
> > import java.util.Iterator;
> > import soot.Scene;
> > import soot.SootClass;
> > import soot.SootMethod;
> > import soot.options.Options;
> >
> > public class SootTest {
> >
> >     public static void main(String[] args) {
> >         CHATransformer.v().transform();
> >
> >         Options.v().set_whole_program(true);
> >         SootClass mainClass =
> > Scene.v().loadClassAndSupport("diplom.testers.omg");
> >         mainClass.setApplicationClass();
> >         Scene.v().setMainClass(mainClass);
> >
> >         SootMethod src = mainClass.getMethodByName("main");
> >         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);
> >         }
> >     }
> > }
> > -------------------------------------------------------------------------
> >--------------------------------------------------------------------------
> >-----------------
> >
> > package diplom.testers;
> >
> > public class omg {
> >
> >     int a;
> >     int b;
> >     int stop;
> >
> >     public omg(int a, int b){
> >         this.a = a;
> >         this.b = b;
> >     }
> >
> >     public void omfg(int c){
> >         for (int i=a; i<c; i++){
> >             System.out.println(c+b);
> >             omfg(--c);
> >         }
> >     }
> >
> >     public static void main(String[] args){
> >         omg it = new omg(1, 10);
> >         it.omfg(6);
> >     }
> >
> > }
> >
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20090218/1b284cf5/attachment-0001.bin 


More information about the Soot-list mailing list