[Soot-list] a strange error

Eric Bodden eric.bodden at mail.mcgill.ca
Tue Dec 16 11:29:59 EST 2008


Hi Jian.

2008/12/16 Jian Xu <fightmyway at gmail.com>:
> Hi Eric:

You should not assume that I am the only one answering questions on
this list. ;-)

Regarding your problem: Usually, when people use the reset
functionality then they don't use soot.Main.main(..), and in
particular they don't write out any output multiple times (which
usually does not make sense anyway). It seems that Soot is getting
into trouble when attempting to write output to disk multiple times
(because not all of Soot's internal state is properly reset when you
call reset()).

Can you try disabling the output? Call...

soot.options.Options.v().set_output_format(soot.options.Options.output_format_none);

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);
>             }
>
>         }
>
>     }
>
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
>



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


More information about the Soot-list mailing list