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?


Comment actions Permalink

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

Comment actions Permalink

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
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(
 at java.lang.reflect.Method.invoke(
 at myActions.GetAdviceAction.fetchValues(
 at myActions.GetAdviceAction.actionPerformed(
Not in  Manager thread


Comment actions Permalink

Got it, see attached source file and screenshot below:



Please sign in to leave a comment.