[Soot-list] a strange error

Eric Bodden eric.bodden at mail.mcgill.ca
Wed Dec 17 06:17:08 EST 2008


Hi Jian, first of all, your code was just plain wrong in a few places.
The attached code works for me on a small example. It may not work on
your example, though, in which case you should email it to the list.

Here's what you did wrong:

You load class ".Counter" in your main class but it should be "Counter"

You cannot initialize counterClass and increaseCounter in your static
initializer !!!
when the static initializer is called, Soot has not at all been initialized yet

You obviously should not call loadBasicClasses() before calling
addBasicClass(..). In fact, when you call soot.Main.main(..) then you
should never call loadBasicClasses() at all. The reason is that the
call to will initialize the soot-classpath, which has not yet properly
set from the command line yet at this point, because
soot.Main.main(..) has not (yet) been called.

Note to self: we should check this within Soot, actually

Please try the attached code and see if it works for you. If not,
please email the program that you are analyzing.

Eric

2008/12/17 Eric Bodden <eric.bodden at mail.mcgill.ca>:
> What is the program that you are analyzing?
>
> 2008/12/17 Eric Bodden <eric.bodden at mail.mcgill.ca>:
>> Hmm, in that case we need to fix this bug, I think.
>>
>> I was hoping there would be a workaround for you, but if you really do
>> need to write out these files then there isn't. I will see if there's
>> an easy fix.
>>
>> Eric
>>
>> 2008/12/17 Jian Xu <fightmyway at gmail.com>:
>>> Hi:
>>> In my program, I call many times soot.Main to write out bytecode file. If I
>>> set
>>> soot.options.Options.v().set_output_format(soot.options.Options.output_format_none);
>>> soot won't create file anymore. I use soot in my own eclipse plugin, so the
>>> plugin call
>>> soot many times. what should I do? Don't the soot eclipse plugin call
>>> soot.Main?
>>> I also find sometimes call soot.Main many times and reset it works well, it
>>> happens at other condition
>>> when I call soot, but not at that when I do transfer.
>>>
>>> On Wed, Dec 17, 2008 at 12:29 AM, Eric Bodden <eric.bodden at mail.mcgill.ca>
>>> wrote:
>>>>
>>>> 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
>>>
>>>
>>
>>
>>
>> --
>> Eric Bodden
>> Sable Research Group, McGill University
>> Montréal, Québec, Canada
>>
>
>
>
> --
> Eric Bodden
> Sable Research Group, McGill University
> Montréal, Québec, Canada
>



-- 
Eric Bodden
Sable Research Group, McGill University
Montréal, Québec, Canada
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Counter.java
Type: text/x-java
Size: 136 bytes
Desc: not available
Url : http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20081217/7b5a5ed6/Counter.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Instrument.java
Type: text/x-java
Size: 488 bytes
Desc: not available
Url : http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20081217/7b5a5ed6/Instrument.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: InstrumentTest.java
Type: text/x-java
Size: 210 bytes
Desc: not available
Url : http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20081217/7b5a5ed6/InstrumentTest.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: StmtInstrument.java
Type: text/x-java
Size: 2665 bytes
Desc: not available
Url : http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20081217/7b5a5ed6/StmtInstrument.bin


More information about the Soot-list mailing list