Adding JDI MethodEntry events
Answered
I'm trying to write a plugin which traces all method calls on a thread after a breakpoint has been hit. i.e. add a kind of “Resume with tracing” button to the debugger.
In plain Java, I can do this to add MethodEntry events using the java debug interface (JDI):
VirtualMachine vm = // attach to JVM
EventRequestManager mgr = vm.eventRequestManager();
MethodEntryRequest request = mgr.createMethodEntryRequest();
request.enable();
In my Intellij Plugin I've got this (simplified) code to get the thread:
public class DebugProcessListener implements XDebuggerManagerListener {
@Override
public void processStarted(@NotNull final XDebugProcess debugProcess) {
XDebugSession debugSession = debugProcess.getSession();
debugSession.addSessionListener(new DebugSessionListener(debugProcess));
}
}
public class DebugSessionListener implements XDebugSessionListener {
@Override
public void sessionPaused() {
SuspendContext sc = (SuspendContext) debugSession.getSuspendContext();
ThreadReferenceProxy scThread = sc.getThread();
}
}
From here, how can I get access to the JDI VirtualMachine in order to add the MethodEntry request?
Please sign in to leave a comment.
Hi, you can try something like this:
((VirtualMachineProxyImpl)thread.getVirtualMachine()).eventRequestManager().createMethodEntryRequest()