[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Soot API: VerifyError when using Chain.insertBefore() methods
> How do you construct the params list?
// creating local vars array
Local [] argv = new Local[xParameterNames.length];
// create an arraylist to hold method parameters
passed into preCondMthd and postCondMthd
ArrayList params = new ArrayList();
// Array list that holds references to previous units
operated on
Unit [] prevUnits = new Unit[xParameterNames.length +
1];
Unit prevUnit;
// set previous Unit as the first identity Statement
in chain
prevUnits[0] = firstIdentityStmt;
int j = 0;
// iterate through each method parameter
for (;j < xParameterNames.length; j++) {
Type sootType = getSootType(xParameterTypes[j]);
// Declare new local that will reference a method
param
argv[j] = Jimple.v().newLocal(xParameterNames[j],
sootType);
// Add it to locals list
locals.add(argv[j]);
// Make the new local reference a method param
Unit currentUnit =
Jimple.v().newIdentityStmt(argv[j], Jimple.v().newParameterRef(sootType,
j));
// Insert param reference into chain
units.insertAfter(currentUnit, prevUnits[j]);
// Update reference array
prevUnits[j+1] = currentUnit;
// Add to param to list
params.add((Value)argv[j]);
}
On Fri, 7 Sep 2001 13:31:17 -0400 (EDT) Patrick LAM
<plam@sable.mcgill.ca> writes:
> 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
>
>