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(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(); } }); } } }
private boolean shouldApplyContext(DebuggerContextImpl context) { SuspendContextImpl suspendContext = context.getSuspendContext(); SuspendContextImpl currentContext = (SuspendContextImpl) getSession().getSuspendContext(); if (suspendContext != null && !suspendContext.equals(currentContext)) return true; JavaExecutionStack currentExecutionStack = currentContext != null ? currentContext.getActiveExecutionStack() : null; return currentExecutionStack == null || !Comparing.equal(context.getThreadProxy(), currentExecutionStack.getThreadProxy()); }
private ReferenceType loadClass(final String className) { final EvaluationContextImpl eContext = myDebuggerContext.createEvaluationContext(); try { return myDebugProcess.loadClass(eContext, className, eContext.getClassLoader()); } catch (Throwable ignored) { } return null; }
@Nullable private ExpressionEvaluator getExpressionEvaluator(DebuggerContextImpl debuggerContext) throws EvaluateException { if (myCurrentExpression instanceof PsiExpression) { return EvaluatorBuilderImpl.getInstance() .build(myCurrentExpression, debuggerContext.getSourcePosition()); } CodeFragmentFactory factory = DebuggerUtilsEx.getEffectiveCodeFragmentFactory(myCurrentExpression); TextWithImportsImpl textWithImports = new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, myCurrentExpression.getText()); if (factory == null) return null; JavaCodeFragment codeFragment = factory.createCodeFragment(textWithImports, myCurrentExpression.getContext(), getProject()); codeFragment.forceResolveScope(GlobalSearchScope.allScope(getProject())); return factory.getEvaluatorBuilder().build(codeFragment, debuggerContext.getSourcePosition()); }
public SourcePositionCommand( final DebuggerContextImpl debuggerContext, final ValueDescriptor descriptor, final DebugProcessImpl debugProcess, final AnActionEvent actionEvent) { super(debuggerContext.getSuspendContext()); myDebuggerContext = debuggerContext; myDescriptor = descriptor; myDebugProcess = debugProcess; myActionEvent = actionEvent; }
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(); } } }); } }
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); } }
@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 DebuggerContextImpl createDebuggerContext( final SuspendContextImpl suspendContext, StackFrameProxyImpl stackFrame) { final DebuggerSession[] session = new DebuggerSession[1]; UIUtil.invokeAndWaitIfNeeded( new Runnable() { @Override public void run() { session[0] = DebuggerManagerEx.getInstanceEx(myProject) .getSession(suspendContext.getDebugProcess()); } }); DebuggerContextImpl debuggerContext = DebuggerContextImpl.createDebuggerContext( session[0], suspendContext, stackFrame != null ? stackFrame.threadProxy() : null, stackFrame); debuggerContext.initCaches(); return debuggerContext; }
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(); } } }); } }
public void contextAction() throws Exception { updateFrameList(myDebuggerContext.getThreadProxy()); DebuggerInvocationUtil.swingInvokeLater( getProject(), new Runnable() { public void run() { try { myFramesListener.setEnabled(false); final StackFrameProxyImpl contextFrame = getDebuggerContext().getFrameProxy(); if (contextFrame != null) { selectFrame(contextFrame); } } finally { myFramesListener.setEnabled(true); } } }); }
DebuggerContextImpl getFrameDebuggerContext() { DebuggerManagerThreadImpl.assertIsManagerThread(); DebuggerContextImpl context = myDebugProcess.getDebuggerContext(); if (context.getFrameProxy() != getStackFrameProxy()) { SuspendContextImpl threadSuspendContext = SuspendManagerUtil.getSuspendContextForThread( context.getSuspendContext(), getStackFrameProxy().threadProxy()); context = DebuggerContextImpl.createDebuggerContext( myDebugProcess.mySession, threadSuspendContext, getStackFrameProxy().threadProxy(), getStackFrameProxy()); context.setPositionCache(myDescriptor.getSourcePosition()); context.initCaches(); } return context; }
// 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; } } }
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); } }
// copied from FrameVariablesTree private void buildVariables( DebuggerContextImpl debuggerContext, final EvaluationContextImpl evaluationContext, @NotNull DebugProcessImpl debugProcess, XValueChildrenList children, ObjectReference thisObjectReference, Location location) throws EvaluateException { final Set<String> visibleLocals = new HashSet<String>(); if (NodeRendererSettings.getInstance().getClassRenderer().SHOW_VAL_FIELDS_AS_LOCAL_VARIABLES) { if (thisObjectReference != null && debugProcess.getVirtualMachineProxy().canGetSyntheticAttribute()) { final ReferenceType thisRefType = thisObjectReference.referenceType(); if (thisRefType instanceof ClassType && location != null && thisRefType.equals(location.declaringType()) && thisRefType.name().contains("$")) { // makes sense for nested classes only for (Field field : thisRefType.fields()) { if (DebuggerUtils.isSynthetic(field) && StringUtil.startsWith( field.name(), FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) { final FieldDescriptorImpl fieldDescriptor = myNodeManager.getFieldDescriptor(myDescriptor, thisObjectReference, field); children.add(JavaValue.create(fieldDescriptor, evaluationContext, myNodeManager)); visibleLocals.add(fieldDescriptor.calcValueName()); } } } } } boolean myAutoWatchMode = DebuggerSettings.getInstance().AUTO_VARIABLES_MODE; if (evaluationContext == null) { return; } final SourcePosition sourcePosition = debuggerContext.getSourcePosition(); if (sourcePosition == null) { return; } try { if (!XDebuggerSettingsManager.getInstance().getDataViewSettings().isAutoExpressions() && !myAutoWatchMode) { // optimization superBuildVariables(evaluationContext, children); } else { final Map<String, LocalVariableProxyImpl> visibleVariables = getVisibleVariables(getStackFrameProxy()); final Pair<Set<String>, Set<TextWithImports>> usedVars = ApplicationManager.getApplication() .runReadAction( new Computable<Pair<Set<String>, Set<TextWithImports>>>() { @Override public Pair<Set<String>, Set<TextWithImports>> compute() { return findReferencedVars( ContainerUtil.union(visibleVariables.keySet(), visibleLocals), sourcePosition); } }); // add locals if (myAutoWatchMode) { for (String var : usedVars.first) { LocalVariableProxyImpl local = visibleVariables.get(var); if (local != null) { children.add( JavaValue.create( myNodeManager.getLocalVariableDescriptor(null, local), evaluationContext, myNodeManager)); } } } else { superBuildVariables(evaluationContext, children); } final EvaluationContextImpl evalContextCopy = evaluationContext.createEvaluationContext(evaluationContext.getThisObject()); evalContextCopy.setAutoLoadClasses(false); final Set<TextWithImports> extraVars = computeExtraVars(usedVars, sourcePosition, evaluationContext); // add extra vars addToChildrenFrom(extraVars, children, evaluationContext); // add expressions addToChildrenFrom(usedVars.second, children, evalContextCopy); } } catch (EvaluateException e) { if (e.getCause() instanceof AbsentInformationException) { children.add( new DummyMessageValueNode( MessageDescriptor.LOCAL_VARIABLES_INFO_UNAVAILABLE.getLabel(), XDebuggerUIConstants.INFORMATION_MESSAGE_ICON)); // trying to collect values from variable slots try { for (Map.Entry<DecompiledLocalVariable, Value> entry : LocalVariablesUtil.fetchValues(getStackFrameProxy(), debugProcess).entrySet()) { children.add( JavaValue.create( myNodeManager.getArgumentValueDescriptor( null, entry.getKey(), entry.getValue()), evaluationContext, myNodeManager)); } } catch (Exception ex) { LOG.info(ex); } } else { throw e; } } }
private void unsetPausedIfNeeded(DebuggerContextImpl context) { SuspendContextImpl suspendContext = context.getSuspendContext(); if (suspendContext != null && context.getThreadProxy() != suspendContext.getThread()) { ((XDebugSessionImpl) getSession()).unsetPaused(); } }
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)); } }