[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Soot API: VerifyError when using Chain.insertBefore() methods



On Fri, 7 Sep 2001, nathan gulley wrote:

> What I'm trying to do (using the Soot API) is to insert a static method
> call right before
> every return statement in a method:
>
>       // create post condition static invokation
>       Unit postCondMthdUnit = Jimple.v().newInvokeStmt
>            (Jimple.v().newStaticInvokeExpr(postCondMthd, params));
>
>       // get a Unit iterator
>       Iterator unitIterator = units.snapshotIterator();
>
>       while (unitIterator.hasNext()) {
>           Unit retStmtUnit = (Unit)unitIterator.next();
>           if (nextUnit instanceof JReturnVoidStmt || nextUnit instanceof
> JReturnStmt) {
>                     units.insertBefore(postCondMthdUnit, retStmtUnit );
>            }
>       }

Well, one problem is that you're inserting the same Invoke Statement
before all of the return statements.  This *will* be rejected by Chain if
you ever try to insert the same InvokeStmt twice.  But that's not the
immediate problem.

How do you construct the params list?

> When you examine the byte code of the instrumented method, you'll notice
> that the value of a
> String constant is being stored into a DebugMsg object reference on the
> stack at byte # 8:

That's clearly the result of the cast expression.  I'm not sure how that
cast expression gets there.

pat