public void threadAction() { if (myRefreshOnly && myThreadDescriptorsToUpdate.length != myThreadsCombo.getItemCount()) { // there is no sense in refreshing combobox if thread list has changed since creation of // this command return; } final DebuggerContextImpl context = getDebuggerContext(); final ThreadReferenceProxyImpl threadToSelect = context.getThreadProxy(); if (threadToSelect == null) { return; } final SuspendContextImpl threadContext = SuspendManagerUtil.getSuspendContextForThread( context.getSuspendContext(), threadToSelect); final ThreadDescriptorImpl currentThreadDescriptor = (ThreadDescriptorImpl) myThreadsCombo.getSelectedItem(); final ThreadReferenceProxyImpl currentThread = currentThreadDescriptor != null ? currentThreadDescriptor.getThreadReference() : null; if (myRefreshOnly && threadToSelect.equals(currentThread)) { context .getDebugProcess() .getManagerThread() .schedule(new UpdateFramesListCommand(context, threadContext)); } else { context .getDebugProcess() .getManagerThread() .schedule(new RebuildFramesListCommand(context, threadContext)); } if (myRefreshOnly) { final EvaluationContextImpl evaluationContext = context.createEvaluationContext(); for (ThreadDescriptorImpl descriptor : myThreadDescriptorsToUpdate) { descriptor.setContext(evaluationContext); descriptor.updateRepresentation( evaluationContext, DescriptorLabelListener.DUMMY_LISTENER); } DebuggerInvocationUtil.swingInvokeLater( getProject(), new Runnable() { public void run() { try { myThreadsListener.setEnabled(false); selectThread(threadToSelect); myFramesList.repaint(); } finally { myThreadsListener.setEnabled(true); } } }); } else { // full rebuild refillThreadsCombo(threadToSelect); } }
public void actionPerformed(final AnActionEvent e) { DebuggerTreeNodeImpl[] selectedNode = getSelectedNodes(e.getDataContext()); final DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); if (debugProcess == null) return; //noinspection ConstantConditions for (final DebuggerTreeNodeImpl debuggerTreeNode : selectedNode) { final ThreadDescriptorImpl threadDescriptor = ((ThreadDescriptorImpl) debuggerTreeNode.getDescriptor()); if (threadDescriptor.isSuspended()) { final ThreadReferenceProxyImpl thread = threadDescriptor.getThreadReference(); debugProcess .getManagerThread() .schedule( new DebuggerCommandImpl() { @Override protected void action() throws Exception { Set<SuspendContextImpl> contexts = SuspendManagerUtil.getSuspendingContexts( debugProcess.getSuspendManager(), thread); if (!contexts.isEmpty()) { debugProcess .createResumeThreadCommand(contexts.iterator().next(), thread) .run(); } debuggerTreeNode.calcValue(); } }); } } }
protected void commandCancelled() { if (!DebuggerManagerThreadImpl.isManagerThread()) { return; } // context thread is not suspended final DebuggerContextImpl context = getDebuggerContext(); final SuspendContextImpl suspendContext = context.getSuspendContext(); if (suspendContext == null) { return; } final ThreadReferenceProxyImpl threadToSelect = context.getThreadProxy(); if (threadToSelect == null) { return; } if (!suspendContext.isResumed()) { final SuspendContextImpl threadContext = SuspendManagerUtil.getSuspendContextForThread(suspendContext, threadToSelect); context .getDebugProcess() .getManagerThread() .schedule(new RebuildFramesListCommand(context, threadContext)); refillThreadsCombo(threadToSelect); } }
@Override public void update(final AnActionEvent e) { if (!isFirstStart(e)) { return; } final DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); if (debugProcess == null) { e.getPresentation().setVisible(false); return; } DebuggerTreeNodeImpl selectedNode = getSelectedNode(e.getDataContext()); if (selectedNode == null) { e.getPresentation().setVisible(false); return; } final NodeDescriptorImpl descriptor = selectedNode.getDescriptor(); if (descriptor instanceof ValueDescriptor) { debugProcess .getManagerThread() .schedule( new EnableCommand(debuggerContext, (ValueDescriptor) descriptor, debugProcess, e)); } else { e.getPresentation().setVisible(false); } }
public void actionPerformed(AnActionEvent e) { final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) { return; } DebuggerContextImpl context = (DebuggerManagerEx.getInstanceEx(project)).getContext(); final DebuggerSession session = context.getDebuggerSession(); if (session != null && session.isAttached()) { final DebugProcessImpl process = context.getDebugProcess(); process .getManagerThread() .invoke( new DebuggerCommandImpl() { protected void action() throws Exception { final VirtualMachineProxyImpl vm = process.getVirtualMachineProxy(); vm.suspend(); try { final List<ThreadState> threads = buildThreadStates(vm); ApplicationManager.getApplication() .invokeLater( new Runnable() { public void run() { XDebugSession xSession = session.getProcess().getXDebugSession(); if (xSession != null) { DebuggerSessionTab.addThreadDump( project, threads, xSession.getUI(), session); } } }, ModalityState.NON_MODAL); } finally { vm.resume(); } } }); } }
@Override public void actionPerformed(AnActionEvent e) { DebuggerTreeNodeImpl selectedNode = getSelectedNode(e.getDataContext()); if (selectedNode == null) { return; } final NodeDescriptorImpl descriptor = selectedNode.getDescriptor(); if (!(descriptor instanceof ValueDescriptor)) { return; } DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); if (debugProcess == null) { return; } debugProcess .getManagerThread() .schedule( new NavigateCommand(debuggerContext, (ValueDescriptor) descriptor, debugProcess, e)); }
public void actionPerformed(AnActionEvent e) { final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) { return; } DebuggerContextImpl context = (DebuggerManagerEx.getInstanceEx(project)).getContext(); if (context.getDebuggerSession() != null) { final DebugProcessImpl process = context.getDebugProcess(); process .getManagerThread() .invoke( new DebuggerCommandImpl() { protected void action() throws Exception { final VirtualMachineProxyImpl vm = process.getVirtualMachineProxy(); vm.suspend(); try { final List<ThreadState> threads = buildThreadStates(vm); ApplicationManager.getApplication() .invokeLater( new Runnable() { public void run() { final DebuggerSessionTab sessionTab = DebuggerPanelsManager.getInstance(project).getSessionTab(); if (sessionTab != null) { sessionTab.addThreadDump(threads); } } }, ModalityState.NON_MODAL); } finally { vm.resume(); } } }); } }
protected void evaluateAndShowHint() { final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext(); final DebuggerSession debuggerSession = debuggerContext.getDebuggerSession(); if (debuggerSession == null || !debuggerSession.isPaused()) return; try { final ExpressionEvaluator evaluator = getExpressionEvaluator(debuggerContext); if (evaluator == null) return; debuggerContext .getDebugProcess() .getManagerThread() .schedule( new DebuggerContextCommandImpl(debuggerContext) { public Priority getPriority() { return Priority.HIGH; } public void threadAction() { try { final EvaluationContextImpl evaluationContext = debuggerContext.createEvaluationContext(); final String expressionText = ApplicationManager.getApplication() .runReadAction( new Computable<String>() { public String compute() { return myCurrentExpression.getText(); } }); final TextWithImports text = new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, expressionText); final Value value = myValueToShow != null ? myValueToShow : evaluator.evaluate(evaluationContext); final WatchItemDescriptor descriptor = new WatchItemDescriptor(getProject(), text, value); if (!isActiveTooltipApplicable(value) || getType() == ValueHintType.MOUSE_OVER_HINT) { if (getType() == ValueHintType.MOUSE_OVER_HINT) { // force using default renderer for mouse over hint in order to not to call // accidentally methods while rendering // otherwise, if the hint is invoked explicitly, show it with the right // "auto" renderer descriptor.setRenderer(DebugProcessImpl.getDefaultRenderer(value)); } descriptor.updateRepresentation( evaluationContext, new DescriptorLabelListener() { public void labelChanged() { if (getCurrentRange() != null) { if (getType() != ValueHintType.MOUSE_OVER_HINT || descriptor.isValueValid()) { final SimpleColoredText simpleColoredText = DebuggerTreeRenderer.getDescriptorText( debuggerContext, descriptor, true); if (isActiveTooltipApplicable(value)) { simpleColoredText.append( " (" + DebuggerBundle.message("active.tooltip.suggestion") + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES); } showHint(simpleColoredText, descriptor); } } } }); } else { final InspectDebuggerTree tree = getInspectTree(descriptor); showTreePopup( tree, debuggerContext, expressionText, new ValueHintTreeComponent(ValueHint.this, tree, expressionText)); } } catch (EvaluateException e) { LOG.debug(e); } } }); } catch (EvaluateException e) { LOG.debug(e); } }
public void contextAction() throws Exception { final ThreadReferenceProxyImpl thread = myDebuggerContext.getThreadProxy(); try { if (!getSuspendContext().getDebugProcess().getSuspendManager().isSuspended(thread)) { DebuggerInvocationUtil.swingInvokeLater( getProject(), new Runnable() { public void run() { try { myFramesListener.setEnabled(false); synchronized (myFramesList) { final DefaultListModel model = myFramesList.getModel(); model.clear(); model.addElement( new Object() { public String toString() { return DebuggerBundle.message("frame.panel.frames.not.available"); } }); myFramesList.setSelectedIndex(0); } } finally { myFramesListener.setEnabled(true); } } }); return; } } catch (ObjectCollectedException e) { return; } List<StackFrameProxyImpl> frames; try { frames = thread.frames(); } catch (EvaluateException e) { frames = Collections.emptyList(); } final StackFrameProxyImpl contextFrame = myDebuggerContext.getFrameProxy(); final EvaluationContextImpl evaluationContext = myDebuggerContext.createEvaluationContext(); final DebuggerManagerThreadImpl managerThread = myDebuggerContext.getDebugProcess().getManagerThread(); final MethodsTracker tracker = new MethodsTracker(); final int totalFramesCount = frames.size(); int index = 0; final long timestamp = System.nanoTime(); for (StackFrameProxyImpl stackFrameProxy : frames) { managerThread.schedule( new AppendFrameCommand( getSuspendContext(), stackFrameProxy, evaluationContext, tracker, index++, stackFrameProxy.equals(contextFrame), totalFramesCount, timestamp)); } }
// copied from DebuggerTree private void buildVariablesThreadAction( DebuggerContextImpl debuggerContext, XValueChildrenList children, XCompositeNode node) { try { final EvaluationContextImpl evaluationContext = debuggerContext.createEvaluationContext(); if (evaluationContext == null) { return; } if (!debuggerContext.isEvaluationPossible()) { node.setErrorMessage(MessageDescriptor.EVALUATION_NOT_POSSIBLE.getLabel()); // myChildren.add(myNodeManager.createNode(MessageDescriptor.EVALUATION_NOT_POSSIBLE, // evaluationContext)); } final Location location = myDescriptor.getLocation(); final ObjectReference thisObjectReference = myDescriptor.getThisObject(); if (thisObjectReference != null) { ValueDescriptorImpl thisDescriptor = myNodeManager.getThisDescriptor(null, thisObjectReference); children.add(JavaValue.create(thisDescriptor, evaluationContext, myNodeManager)); } else if (location != null) { StaticDescriptorImpl staticDecriptor = myNodeManager.getStaticDescriptor(myDescriptor, location.declaringType()); if (staticDecriptor.isExpandable()) { children.addTopGroup( new JavaStaticGroup(staticDecriptor, evaluationContext, myNodeManager)); } } DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); if (debugProcess == null) { return; } // add last method return value if any final Pair<Method, Value> methodValuePair = debugProcess.getLastExecutedMethod(); if (methodValuePair != null) { ValueDescriptorImpl returnValueDescriptor = myNodeManager.getMethodReturnValueDescriptor( myDescriptor, methodValuePair.getFirst(), methodValuePair.getSecond()); children.add(JavaValue.create(returnValueDescriptor, evaluationContext, myNodeManager)); } // add context exceptions for (Pair<Breakpoint, Event> pair : DebuggerUtilsEx.getEventDescriptors(debuggerContext.getSuspendContext())) { final Event debugEvent = pair.getSecond(); if (debugEvent instanceof ExceptionEvent) { final ObjectReference exception = ((ExceptionEvent) debugEvent).exception(); if (exception != null) { final ValueDescriptorImpl exceptionDescriptor = myNodeManager.getThrownExceptionObjectDescriptor(myDescriptor, exception); children.add(JavaValue.create(exceptionDescriptor, evaluationContext, myNodeManager)); } } } try { buildVariables( debuggerContext, evaluationContext, debugProcess, children, thisObjectReference, location); // if (classRenderer.SORT_ASCENDING) { // Collections.sort(myChildren, NodeManagerImpl.getNodeComparator()); // } } catch (EvaluateException e) { node.setErrorMessage(e.getMessage()); // myChildren.add(myNodeManager.createMessageNode(new MessageDescriptor(e.getMessage()))); } } catch (InvalidStackFrameException e) { LOG.info(e); // myChildren.clear(); // notifyCancelled(); } catch (InternalException e) { if (e.errorCode() == 35) { node.setErrorMessage(DebuggerBundle.message("error.corrupt.debug.info", e.getMessage())); // myChildren.add( // myNodeManager.createMessageNode(new // MessageDescriptor(DebuggerBundle.message("error.corrupt.debug.info", e.getMessage())))); } else { throw e; } } }