[Soot-list] Access class variable added by instrumentation

Nuno Machado nmachado at gsd.inesc-id.pt
Tue Feb 7 09:56:38 EST 2012


Hi everyone,

I've instrumented a class in order to add to it a new class variable (called controller). I've also instrumented this variable initialization and it works fine. However, when I instrument a method to access that variable, I get the following error: "Exception in thread "main" java.lang.VerifyError: (class: gui/DummyTest, method: process1 signature: ()V) Register 0 contains wrong type".

Do you know what am I doing wrong?

Inside the method body, I create the controller variable field reference as follows:

(…)
//-- create ref of variable "controller" 
Local fieldLocal = Jimple.v().newLocal("$contField_"+smbody.getMethod().getName(), RefType.v(dynamicContClass));
smbody.getLocals().add(fieldLocal);
AssignStmt fieldAssignStmt = Jimple.v().newAssignStmt(fieldLocal, Jimple.v().newStaticFieldRef(Scene.v().getField(controllerSig).makeRef()));

//-- invoke "controller.accepts(...)"	
String methodSig3 ="<" + dynamicContClass +": boolean accepts(java.lang.String,java.lang.String)>"; 
SootMethodRef mr3 = Scene.v().getMethod(methodSig3).makeRef();
Value invokeAccepts = Jimple.v().newVirtualInvokeExpr(fieldLocal, mr3, tname, StringConstant.v(sm.getSignature())); 
AssignStmt newAssignStmt3 = Jimple.v().newAssignStmt(isAccepted, invokeAccepts); 


This produces the following jimple code for method "process1":

Fields: 
<gui.DummyTest: int a>
<gui.DummyTest: int b>
<gui.DummyTest: soottest.DynamicControllerTest controller>

Method <gui.DummyTest: void process1()>
$contField_process1 = <gui.DummyTest: soottest.DynamicControllerTest controller>
$thread_process1 = staticinvoke <java.lang.Thread: java.lang.Thread currentThread()>()
$tname_process1 = virtualinvoke $thread_process1.<java.lang.Thread: java.lang.String getName()>()
$isAccepted_process1 = virtualinvoke $contField_process1.<soottest.DynamicControllerTest: boolean accepts(java.lang.String,java.lang.String)>($tname_process1, "<gui.DummyTest: void process1()>")
(…)


..and the following java byte code:
 public static void process1();
     0  getstatic gui.DummyTest.controller : soottest.DynamicControllerTest [29]
     3  astore_0
     4  aload_0
     5  invokestatic java.lang.Thread.currentThread() : java.lang.Thread [35]
     8  invokevirtual java.lang.Thread.getName() : java.lang.String [46]
    11  ldc <String "<gui.DummyTest: void process1()>"> [80]
    13  invokevirtual soottest.DynamicControllerTest.accepts(java.lang.String, java.lang.String) : boolean [21]


I guess that the problem is related to how the JVM is loading the reference, but if I run the instrumented class with the JVM option "-Xverify:none", I get this error instead:
Exception in thread "main" java.lang.NullPointerException
	at gui.DummyTest.process1(DummyTest.java:11)
	at gui.DummyTest.main(DummyTest.java:28)

So, I'm certainly doing something wrong when creating the fieldref…


Thank you,
Nuno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20120207/d4bd2add/attachment.html 


More information about the Soot-list mailing list