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

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



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 );
           }
      }

However,  when you examine the resulting Jimple code there is an extra
line of code 
that I didn't add using the Soot API:

   r5 = (com.rtscinc.util.DebugMsg) r4;

This extra line that's mysteriously inserted before the line I did add
causes the Verify Error
 because a DebugMsg object is being assigned to a String. These two
classes are 
entirely unrelated.

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:

Method java.lang.String v(java.lang.String, java.io.InputStream,
com.rtscinc.uti
       l.DebugMsg)
      0 aload_1
      1 aload_2
      2 aload_3
      3 invokestatic #15 <Method void precondition_v(java.lang.String,
java.io.Inpu
      tStream, com.rtscinc.util.DebugMsg)>
     6 ldc #30 <String "Hello">
     8 astore_3
     9 aload_3
    10 invokestatic #111 <Method void print(java.lang.String)>
    13 aload_1
    14 aload_2
    15 aload_3
    16 invokestatic #123 <Method void postcondition_v(java.lang.String,
java.io.In
    putStream, com.rtscinc.util.DebugMsg)>
   19 aload_3
   20 areturn

 Byte # 8 should be "8 astore 4" instead.

Nathan





On Thu, 6 Sep 2001 17:20:46 -0400 (EDT) Patrick LAM
<plam@sable.mcgill.ca> writes:
> On Thu, 6 Sep 2001, nathan gulley wrote:
> 
> > I would appreciate any advice on what may be the cause of this 
> problem.
> > I have attatched the Jimple
> > code for this instrumented class also.
> 
> The code of the v() method looks fishy:
> 
>         r4 = "Hello";
>         staticinvoke <com.rtscinc.util.DebugMsg: void
>           print(java.lang.String)>(r4);
>         r5 = (com.rtscinc.util.DebugMsg) r4;
>         staticinvoke <test.LoadMe_Assertion: void
>           postcondition_v(java.lang.String,java.io.InputStream,
>           com.rtscinc.util.DebugMsg)>(r1, r2, r5);
> 
> So you're passing the postcondition_v method a String (r4 is a 
> String, and
> r5 is r4; if the method executed, you'd probably get a
> ClassCastException), not a DebugMsg.  I suppose that DebugMsg could 
> be a
> subclass of String.  Is it?
> 
> pat
> 
> 
>