[Soot-list] RE: Soot-list Digest, Vol 22, Issue 3

David A Weiser DWEISER at uwyo.edu
Sat Feb 3 14:56:26 EST 2007


I'm trying to run an analysis on this code:

public class MyClass {
	public static double compute (double x){
 	  double z;
	  x = Math.sin(x);
	  z = x;
	  return z;
	}
}
_____________________

My MainDriver class:

_____________________

import soot.*;
import soot.jimple.*;
import soot.util.*;
import java.io.*;
import java.util.*;


public class MainDriver {

    public static void main(String[] args) {
        PackManager.v().getPack("wjtp").add(new
Transform("wjtp.gprinter", GPrt.v()));
        soot.options.Options.v().set_whole_program(true);
        soot.options.Options.v().setPhaseOption("cg", "off");
        soot.options.Options.v().setPhaseOption("jb",
"use-original-names:true");
 
soot.options.Options.v().set_output_format(soot.options.Options.v().outp
ut_format_dava);

        soot.Main.main(args);

    }

}
_________________________

My GPrt.java (I got this code off a tutorial)
_________________________
import soot.*;
import soot.jimple.*;
import soot.util.*;
import java.io.*;
import java.util.*;


class GPrt extends SceneTransformer
{
    // Hooks needed by Framwork:
    private static GPrt instance = new GPrt();
    private GPrt() {}

    public static GPrt v() { return instance; }

    // This is the key method:
    protected void internalTransform(String phaseName, Map options)
    {
	System.out.println("Start Printer");
	System.out.println("=======================================");

	// Scene is the root of AST

	Chain classList = Scene.v().getApplicationClasses();
	Iterator classIt = classList.iterator();
	while (classIt.hasNext()){
            // Iterate over all classes
	    SootClass sc = (SootClass) classIt.next();
	    System.out.println(sc.getName());
	    
	    Iterator fIt = sc.getFields().iterator();
	    while (fIt.hasNext()){
		// Iterate over all fields of the current class
		SootField sf = (SootField) fIt.next();
		System.out.println("  "+sf.getName()+"
"+sf.getType().getClass());
		if(sf.getType() instanceof ArrayType){
		    ArrayType aType = (ArrayType)sf.getType();
		    System.out.println("\t ArrayType BT & Dim:
"+aType.baseType+
				       "; "+aType.numDimensions);
		}
	    }

	    Iterator mIt = sc.getMethods().iterator();
	    while (mIt.hasNext()){
		// Iterate over all methods of the current class
		SootMethod sm = (SootMethod) mIt.next();
		System.out.println("  "+sm.getSignature());

		if (sc.isPhantomClass()){
		    continue; 
		}
		
		Body mthdBody = sm.retrieveActiveBody();
	
		

		Iterator varIt = mthdBody.getLocals().iterator();
		while (varIt.hasNext()){
		    // Iterate over all variables of the current method 
		    Local l = (Local) varIt.next();
		    System.out.print("    "+l.getType().toString());
		    System.out.println(" "+l.getName());
		}
		System.out.println("");

		Iterator stmtIt = mthdBody.getUnits().iterator();
		while (stmtIt.hasNext()){
		    // Iterate over all statements of the current method

		    Stmt s = (Stmt) stmtIt.next();
		    System.out.println("    StmtClass:"+s.getClass());
		    System.out.println("    "+s.toString());
		    if (s instanceof AssignStmt){
			AssignStmt jassgnm = (AssignStmt)s;
			System.out.println("          AssignStmt
LHS:"+jassgnm.getLeftOp().getClass());
			System.out.println("          AssignStmt
RHS:"+jassgnm.getRightOp().getClass());
		    }
		}

	    }
	}
	System.out.println("====================================");
	System.out.println("Finished!");
    } 
}
____________________________
And here is the error I get:
C:\dweiser_workspace_local\MainDriver>java MainDriver MyClass
Soot started on Sat Feb 03 12:47:53 MST 2007
Start Printer
=======================================
MyClass
  <MyClass: void <init>()>
Exception in thread "main" java.lang.NullPointerException
        at soot.coffi.Util.getLocalForIndex(Util.java:840)
        at soot.coffi.CFG.generateJimple(CFG.java:3241)
        at soot.coffi.CFG.jimplify(CFG.java:1464)
        at soot.coffi.CFG.jimplify(CFG.java:1127)
        at
soot.coffi.CoffiMethodSource.getBody(CoffiMethodSource.java:98)
        at soot.SootMethod.getBodyFromMethodSource(SootMethod.java:80)
        at soot.SootMethod.retrieveActiveBody(SootMethod.java:304)
        at GPrt.internalTransform(GPrt.java:53)
        at soot.SceneTransformer.transform(SceneTransformer.java:39)
        at soot.Transform.apply(Transform.java:89)
        at soot.ScenePack.internalApply(ScenePack.java:44)
        at soot.Pack.apply(Pack.java:110)
        at soot.PackManager.runWholeProgramPacks(PackManager.java:358)
        at soot.PackManager.runPacks(PackManager.java:304)
        at soot.Main.run(Main.java:179)
        at soot.Main.main(Main.java:153)
        at MainDriver.main(MainDriver.java:18)
_________________________________
What is going on here?
dave



More information about the Soot-list mailing list