I want to code the example in "Adding profiling instructions to applications" tutorial so I write the program as the tutorial said. But when I run it I got this error:
[Thread-3] ERROR heros.solver.CountingThreadPoolExecutor - Worker thread execution failed: Field already exists : gotoCount of type
this error is correspond to
Scene.v().getMainClass().addField(gotoCounter);
I put the code I wrote:
import soot.*;
import soot.jimple.*;
import soot.util.Chain;
import java.util.Iterator;
import java.util.Map;
public class GoToInstrumenter extends BodyTransformer {
private static GoToInstrumenter instance = new GoToInstrumenter();
private GoToInstrumenter() {}
public static GoToInstrumenter v() { return instance; }
protected void internalTransform(Body body, String phaseName, Map options) {
if (!Scene.v().getMainClass().
declaresMethod("void main(java.lang.String[])"))
throw new RuntimeException("couldn't find main() in mainClass");
SootField gotoCounter;
SootClass javaIoPrintStream;
boolean addedFieldToMainClassAndLoadedPrintStream=false;
if (addedFieldToMainClassAndLoadedPrintStream)
gotoCounter = Scene.v().getMainClass().getFieldByName("gotoCount");
else
{
gotoCounter = new SootField("gotoCount", LongType.v(),
Modifier.STATIC);
Scene.v().getMainClass().addField(gotoCounter);
Scene.v().loadClassAndSupport("java.io.PrintStream");
javaIoPrintStream =Scene.v().getSootClass("java.io.PrintStream");
addedFieldToMainClassAndLoadedPrintStream = true;
}
boolean isMainMethod = body.getMethod().getSubSignature()
.equals("void main(java.lang.String[])");
Local tmpLocal = Jimple.v().newLocal("tmp", LongType.v());
body.getLocals().add(tmpLocal);
Iterator stmtIt = body.getUnits().snapshotIterator();
Chain units=body.getUnits();
while (stmtIt.hasNext()) {
Stmt s = (Stmt) stmtIt.next();
if (s instanceof GotoStmt) {
AssignStmt toAdd1 = Jimple.v().newAssignStmt(tmpLocal,
Jimple.v().newStaticFieldRef(gotoCounter.makeRef()));
units.insertBefore(toAdd1, s);
}
}
}
}
Please Help me, I can not find out what cause this problem?