How can a plugin access a local variable's value in the debugger's current stackframe?
I would like to write a plugin that uses the value of a local variable, whilst execution is suspended in the IntelliJ debugger, to do some work e.g. call a web service with the value (and display the response in a popup or tab or add in comments in the source file/psi). Can anyone articulate the steps required, given AnActionEvent?
TIA
Please sign in to leave a comment.
No luck, but it's early yet; so far I've explored this approach a bit:
Project project = event.getData(CommonDataKeys.PROJECT);
DebuggerManager dbg = DebuggerManager.getInstance(project);
DebugProcess p = dbg.getDebugProcess(getHandler(event.getDataContext()));
DebuggerSession s = ((DebuggerManagerImpl) dbg).getSession(p);
// TODO: Research re: com.intellij.debugger.jdi.LocalVariablesUtil.fetchValues()
Object localVariableValue = p.getUserData(new Key("nameOfLocalVariable")); // resolves to NULL
I've managed to get to the frame where I can spy on the slots in the debugger (and see the variable names I'm expecting i.e. headers & args)

but I get this JDWPException when I try to get the values (stole some of the attached code from LocalVariablesUtil.fetchValues()) from the debugger (or is it debugee?):
[ 23824] ERROR - gine.DebuggerManagerThreadImpl - Last Action: Actions.ActionsPlugin.GetAdvice
com.sun.tools.jdi.JDWPException
at com.sun.tools.jdi.PacketStream.waitForReply(PacketStream.java:54)
at com.sun.tools.jdi.JDWP$StackFrame$GetValues.waitForReply(JDWP.java:6967)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at myActions.GetAdviceAction.fetchValues(GetAdviceAction.java:89)
at myActions.GetAdviceAction.actionPerformed(GetAdviceAction.java:139)
Not in Manager thread
Attachment(s):
GetAdviceAction.java.zip
Got it, see attached source file and screenshot below:

Attachment(s):
GetAdviceAction.java.zip
It seems, DebuggerManager, DebuggerManagerEx, etc has been removed latest SDK (2020.3).
Is there any other way to get local variable values at runtime?