Reputation: 2009
I'm currently implementing a IDebugContextListener class (part of the eclipse developer tools API/library) to listen to event changes in the debugger. The method that makes this happen is:
private void contextActivated(ISelection context) {
if (context instanceof StructuredSelection) {
Object data = ((StructuredSelection) context).getFirstElement();
if (data instanceof IStackFrame) {
reciever.setStackFrame((IStackFrame) data);
} else {
reciever.setStackFrame(null);
}
}
}
Basically the debugger is giving my program IStackFrame's, which have IVariables inside, which gives a model of what is going on in the program that is being debugged. These as far as I can tell are data representations of true variables that is running on the program that is being debugged. The IVariables are limited in their functionality, as they can do basic things such as get the name of the variable they represent and get the type etc.
This might not be possible but is there any way I can get a copy of the actual object that it represents rather than the IVariable data representations using the IDebugContextListener class?
My purpose is I want to use the internal functions of the objects. With IVariables I can only get access to properties of the variables inside the objects.
Upvotes: 1
Views: 136
Reputation: 2009
The IDebugContextListener actually returns an IStackFrame that has a collection of IVariables that are specifically implementing the IJavaVariable interface. Knowing this, we can get an IJavaValue from the IJavaVariable, which can in turn be casted into an IJavaObject.
The IJavaObject provides a method called sendMessage(), where you can communicate with the debugger JVM to have methods on the stack be executed and return back an IValue of the return value of the method.
This is how I managed to solve this problem.
Upvotes: 1
Reputation: 13858
The IVariable/IValue interface provides a generic, language-independent way of getting debug information. This means, it is not really possible to get the current values directly from the debugger using these values.
However, the language environment, such as JDT provide a second, language-specific layer that helps getting that information, in case of JDT see org.eclipse.jdt.debug project.
For a more detailed sample to get values of the Java debugger, please see the source code of the Inspect action. Basically, this code shows how to communicate with the debugged JVM.
Warning: the solution presented here may rely on internal code from JDT (possibly still usable outside the jdt plug-ins); and communicating with the other JVM can be quite slow. Be careful.
Upvotes: 2