0

I am developing my customized debugger as an eclipse plugin. I am using the JPDA API to this end. I would like to retrieve the value of some object-reference variable. Therefore, I try to use ObjectReference.invokeMethod by invoking toString() method. My code is as follows:

if(thread.isSuspended()){
    Method method = retriveToStringMethod(...);
    Value messageValue = objValue.invokeMethod(thread, method, new ArrayList<Value>(), ObjectReference.INVOKE_SINGLE_THREADED); 
    stringValue = messageValue.toString();

}

However, it sometime does not work. For example, Given the following code:

1. public static void main(String[] args) {
2.  InsertIntervalBug6 insert = new InsertIntervalBug6();
3.  
4.  Interval i1 = new Interval(1, 2);
5.  Interval i2 = new Interval(3, 4);
6.  
7. }

It works fine in line 4, I can successfully get the result by invoking toString() method of insert variable. However, when in line 5, a TimeOutException is reported. However, I have already set the timeout option when starting JVM at 10s, therefore I think such a period is long enough to retrieve the result of toString() method invocation. The trace stack is as follows. Do you have any idea about the problem? Thanks!

org.eclipse.jdi.TimeoutException: Timeout occurred while waiting for packet 586. at org.eclipse.jdi.internal.connect.PacketReceiveManager.getReply(PacketReceiveManager.java:186) at org.eclipse.jdi.internal.connect.PacketReceiveManager.getReply(PacketReceiveManager.java:197) at org.eclipse.jdi.internal.MirrorImpl.requestVM(MirrorImpl.java:191) at org.eclipse.jdi.internal.MirrorImpl.requestVM(MirrorImpl.java:226) at org.eclipse.jdi.internal.ObjectReferenceImpl.invokeMethod(ObjectReferenceImpl.java:428) at microbat.codeanalysis.runtime.variable.VariableValueExtractor.setMessageValue(VariableValueExtractor.java:518)

Yun Lin
  • 11
  • 4

1 Answers1

0

I have solved this problem by myself. I share the solution in this answer as follows:

The TimeoutException is caused by deadlock. When I am visiting the toString() method, it triggers a step request to JVM. However, my program is listening to any step request sent from the debugged program so that it is able to capture the stepping event and suspend the program for checking variable values. Therefore, a programmatical invocation of the toString() method suspend the program itself, the invokeMethod() wait the suspended program until the time output.

The solution is to disable the set step request. Afterward, the deadline lock problem disappears.

Yun Lin
  • 11
  • 4