[Soot-list] a strange error

Jian Xu fightmyway at gmail.com
Tue Dec 16 09:16:00 EST 2008


Hi Eric:

I add new transform into "jap" pack. And In my program, the transform will
be called many times. It looks like this:

public class InstrumentTest {
    public static void main(String[] args){
       Instrument().main(new String[]{"FindMid"});
        soot.G.reset();
       Instrument().main(new String[]{"FindMid"});
    }
}

The first time it rum correctly. but when call two times, the second one
wrong

the error message is :

Exception in thread "main" java.lang.RuntimeException: Negative Stack
Logical height has been attained:
StackHeight: -1
At instruction:pop
Block:
Block 0:
[preds: ] [succs: ]
r0 := @this:FindMid;
load.r r0;
specialinvoke <java.lang.Object: void <init>()>;
push "FindMid";
push "void <init>()";
push 0;
staticinvoke <Counter: void
increase(java.lang.String,java.lang.String,int)>;
pop;
return;


Method: <init>
<FindMid: void <init>()>
    at
soot.baf.JasminClass.calculateLogicalStackHeightCheck(JasminClass.java:1864)
    at soot.baf.JasminClass.emitMethodBody(JasminClass.java:275)
    at soot.AbstractJasminClass.emitMethod(AbstractJasminClass.java:689)
    at soot.AbstractJasminClass.<init>(AbstractJasminClass.java:568)
    at soot.baf.JasminClass.<init>(JasminClass.java:44)
    at soot.PackManager.writeClass(PackManager.java:874)
    at soot.PackManager.writeOutput(PackManager.java:464)
    at soot.PackManager.writeOutput(PackManager.java:391)
    at soot.Main.run(Main.java:203)
    at soot.Main.main(Main.java:145)
    at Instrument.main(Instrument.java:52)
    at InstrumentTest.main(InstrumentTest.java:9)



public class Instrument {
  public static void  main(String[] args) {
        Options.v().set_keep_line_number(true);

        PackManager.v().getPack("jap").add(
                new Transform("jap.instrumenter", StmtInstrument.v()));
        Scene.v().loadBasicClasses();
        Scene.v().addBasicClass(".Counter", SootClass.SIGNATURES);
        soot.Main.main(args);
    }


}

class StmtInstrument extends BodyTransformer {
    private static StmtInstrument instance = new StmtInstrument();
    private StmtInstrument() {
    }

    public static StmtInstrument v() {
        return instance;
    }


    static SootClass counterClass;
    static SootMethod increaseCounter, reportCounter;
    static {
        counterClass = Scene.v().loadClassAndSupport("Counter");
        increaseCounter = counterClass.getMethod("void
increase(java.lang.String,java.lang.String,int)");
    }


    @Override
    protected void internalTransform(Body b, String phaseName, Map options)
{
        // TODO Auto-generated method stub

        ExceptionalBlockGraph bGraph = new ExceptionalBlockGraph(b);

        Iterator<Block> blockIt = bGraph.getBlocks().iterator();
        Local counterLocal = Jimple.v().newLocal("counterRef",
                counterClass.getType());
        b.getLocals().add(counterLocal);
        String methodName = b.getMethod().toString();
        String className = methodName.substring(1, methodName.indexOf(":"));
        methodName = methodName.substring(methodName.indexOf(":")+2,
methodName.length()-1);

        while (blockIt.hasNext()) {
            Block block = (Block) blockIt.next();
            int blkIdx = block.getIndexInMethod();

            List args = new ArrayList();
            args.add(StringConstant.v(className));
            args.add(StringConstant.v(methodName));
            args.add(IntConstant.v(blkIdx));
            InvokeExpr incExpr = Jimple.v().newStaticInvokeExpr(
                    increaseCounter.makeRef(), args);
            InvokeStmt incStmt = Jimple.v().newInvokeStmt(incExpr);
            Unit uh = block.getTail();
            incStmt.addTag(uh.getTag("LineNumberTag"));

            if (uh instanceof IdentityStmt) {
                block.insertAfter(incStmt, uh);
            }else{
                block.insertBefore(incStmt, uh);
                uh.redirectJumpsToThisTo(incStmt);
            }

        }

    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20081216/9730dc84/attachment.htm


More information about the Soot-list mailing list