[Soot-list] Help: code does not pass soot process.

Sunny sunfire001 at gmail.com
Fri Apr 21 18:51:59 EDT 2006


Hi,

I am trying to monitor the assignment statements for local variables, and
then obtain the enclosing object
as well as the new value after the statement. Below is modification of the
"TestInvoke" example. When I
ran MainDriver.java, the following code produced NullPointerException. I
guess I am not on the right
track (I am having some trouble in reading the APIs, some terms and
method/parameter
semantics are not clear to me). Would you please tell me how to fix that? I
put some comments to
indicate what I intended to do. In addition, I have the following questions:

1. Earlier the only parameter of recordLocalAfter was Object, and the
program worked ok. But if I replace
it with soot.Local and start MainDriver, the instrumentation process takes
forever and it consumes all
CPU resources. Why is that?

2. How do I create an instance of MyCounter and call its instance method (if
there is one) in the transformer (the
example only shows static calls)?

public class MyCounter {
  public static void recordLocalAfter(Object enclosingObj, Object value)
 {
                System.out.println("Object " + enclosingObj + " points to "
+ value);
 }
}

public class InvokeStaticInstrumenter extends BodyTransformer
{

 static SootClass counterClass;
 static SootMethod reportLocal;

 static {
  counterClass = Scene.v().loadClassAndSupport("MyCounter");
  reportLocal = counterClass.getMethodByName("recordLocalAfter");
 }

 protected void internalTransform(Body body, String phase, Map options) {

     SootMethod method = body.getMethod();
     System.out.println("instrumenting method : " + method.getSignature());

     Chain units = body.getUnits();
     Iterator stmtIt = units.snapshotIterator();
     while (stmtIt.hasNext())
     {
          Stmt stmt = (Stmt)stmtIt.next();

      // filter non-assignment statements
      if (!(stmt instanceof AssignStmt))
       continue;

      AssignStmt assign = (AssignStmt)stmt;
      Value leftVal = assign.getLeftOp();

      // only consider assignment to local variables
      if (!(leftVal instanceof Local))
       continue;

      Local loc = (Local)leftVal;

      // get the value to be assigned
      Value rightVal = assign.getRightOp();

      // set up arguments to MyCounter.recordLocalAfter(Object, Object)
      Vector args = new Vector();
      // intend to get the enclosing object of this assignment statement.
      args.add(method.context());
      args.add(rightVal);

      InvokeExpr reportExpr= Jimple.v().newStaticInvokeExpr(
reportLocal.makeRef(), args);
      Stmt reportStmt = Jimple.v().newInvokeStmt(reportExpr);
      units.insertAfter(reportStmt, stmt);
     }
 }
}


Thank you and have a nice weekend,

Sunny
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20060421/7d79e3af/attachment.htm


More information about the Soot-list mailing list