Search in sources :

Example 26 with DebuggerSession

use of com.intellij.debugger.impl.DebuggerSession in project intellij-community by JetBrains.

the class ThreadDumpAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    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(() -> {
                        XDebugSession xSession = session.getXDebugSession();
                        if (xSession != null) {
                            DebuggerUtilsEx.addThreadDump(project, threads, xSession.getUI(), session);
                        }
                    }, ModalityState.NON_MODAL);
                } finally {
                    vm.resume();
                }
            }
        });
    }
}
Also used : Project(com.intellij.openapi.project.Project) XDebugSession(com.intellij.xdebugger.XDebugSession) VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) DebuggerCommandImpl(com.intellij.debugger.engine.events.DebuggerCommandImpl) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) ArrayList(java.util.ArrayList) List(java.util.List) SmartList(com.intellij.util.SmartList) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl)

Example 27 with DebuggerSession

use of com.intellij.debugger.impl.DebuggerSession in project intellij-community by JetBrains.

the class ValueHint method evaluateAndShowHint.

@Override
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) {

            @Override
            public Priority getPriority() {
                return Priority.HIGH;
            }

            @Override
            public void threadAction() {
                try {
                    final EvaluationContextImpl evaluationContext = debuggerContext.createEvaluationContext();
                    final String expressionText = ApplicationManager.getApplication().runReadAction(new Computable<String>() {

                        @Override
                        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() {

                            @Override
                            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 {
                        createAndShowTree(expressionText, descriptor);
                    }
                } catch (EvaluateException e) {
                    LOG.debug(e);
                }
            }
        });
    } catch (EvaluateException e) {
        LOG.debug(e);
    }
}
Also used : SimpleColoredText(com.intellij.ui.SimpleColoredText) DescriptorLabelListener(com.intellij.debugger.ui.tree.render.DescriptorLabelListener) ExpressionEvaluator(com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator) WatchItemDescriptor(com.intellij.debugger.ui.impl.watch.WatchItemDescriptor) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) PrimitiveValue(com.sun.jdi.PrimitiveValue) Value(com.sun.jdi.Value) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) DebuggerContextCommandImpl(com.intellij.debugger.engine.events.DebuggerContextCommandImpl)

Example 28 with DebuggerSession

use of com.intellij.debugger.impl.DebuggerSession in project intellij-community by JetBrains.

the class ThreadsDebuggerTree method build.

protected void build(DebuggerContextImpl context) {
    DebuggerSession session = context.getDebuggerSession();
    final RefreshThreadsTreeCommand command = new RefreshThreadsTreeCommand(session);
    final DebuggerSession.State state = session != null ? session.getState() : DebuggerSession.State.DISPOSED;
    if (ApplicationManager.getApplication().isUnitTestMode() || state == DebuggerSession.State.PAUSED || state == DebuggerSession.State.RUNNING) {
        showMessage(MessageDescriptor.EVALUATING);
        context.getDebugProcess().getManagerThread().schedule(command);
    } else {
        showMessage(session != null ? session.getStateDescription() : DebuggerBundle.message("status.debug.stopped"));
    }
}
Also used : DebuggerSession(com.intellij.debugger.impl.DebuggerSession)

Example 29 with DebuggerSession

use of com.intellij.debugger.impl.DebuggerSession in project intellij-community by JetBrains.

the class JavaAwareTestConsoleProperties method getDebugSession.

@Nullable
public DebuggerSession getDebugSession() {
    final DebuggerManagerEx debuggerManager = DebuggerManagerEx.getInstanceEx(getProject());
    if (debuggerManager == null)
        return null;
    final Collection<DebuggerSession> sessions = debuggerManager.getSessions();
    for (final DebuggerSession debuggerSession : sessions) {
        if (getConsole() == debuggerSession.getProcess().getExecutionResult().getExecutionConsole())
            return debuggerSession;
    }
    return null;
}
Also used : DebuggerManagerEx(com.intellij.debugger.DebuggerManagerEx) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with DebuggerSession

use of com.intellij.debugger.impl.DebuggerSession in project intellij by bazelbuild.

the class BlazeNativeAndroidDebugger method attachToClient.

@Override
public void attachToClient(Project project, Client client) {
    final String clientDescr = client.getClientData().getClientDescription();
    Module module = null;
    final List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
    for (AndroidFacet facet : facets) {
        try {
            final String packageName = ApkProviderUtil.computePackageName(facet);
            if (clientDescr.startsWith(packageName)) {
                module = facet.getModule();
                break;
            }
        } catch (ApkProvisionException ignored) {
        // ignored
        }
    }
    if (module == null) {
        throw new RuntimeException("Cannot find module by package name");
    }
    if (hasExistingSession(project, client)) {
        return;
    }
    // Detach any existing JDWP debug session - reusing an existing session is troublesome
    // because we need to setup a custom XDebugProcess.
    DebuggerSession debuggerSession = findJdwpDebuggerSession(project, getClientDebugPort(client));
    if (debuggerSession != null) {
        debuggerSession.getProcess().stop(false);
    }
    // Create run configuration
    // TODO: Important modification here. Make sure to keep this in refactor.
    // We need a custom BlazeAndroidNativeAttachConfiguration to skip a bunch of launch checks so
    // validate passes.
    ConfigurationFactory factory = BlazeAndroidNativeAttachConfigurationFactory.getInstance();
    String runConfigurationName = String.format("Android Native Debugger (%d)", client.getClientData().getPid());
    RunnerAndConfigurationSettings runSettings = RunManager.getInstance(project).createRunConfiguration(runConfigurationName, factory);
    AndroidNativeAttachConfiguration configuration = (AndroidNativeAttachConfiguration) runSettings.getConfiguration();
    configuration.setClient(client);
    configuration.getAndroidDebuggerContext().setDebuggerType(getId());
    configuration.getConfigurationModule().setModule(module);
    // TODO: Important modification here. Make sure to keep this in refactor.
    // We need to set the correct working dir to find sources while debugging.
    // See BlazeAndroidRunConfigurationDebuggerManager#getAndroidDebuggerState
    AndroidDebuggerState state = configuration.getAndroidDebuggerContext().getAndroidDebuggerState();
    if (state instanceof NativeAndroidDebuggerState) {
        NativeAndroidDebuggerState nativeState = (NativeAndroidDebuggerState) state;
        nativeState.setWorkingDir(WorkspaceRoot.fromProject(project).directory().getPath());
    }
    ProgramRunnerUtil.executeConfiguration(project, runSettings, DefaultDebugExecutor.getDebugExecutorInstance());
}
Also used : DebuggerSession(com.intellij.debugger.impl.DebuggerSession) ApkProvisionException(com.android.tools.idea.run.ApkProvisionException) AndroidDebuggerState(com.android.tools.idea.run.editor.AndroidDebuggerState) NativeAndroidDebuggerState(com.android.tools.ndk.run.editor.NativeAndroidDebuggerState) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) BlazeAndroidNativeAttachConfigurationFactory(com.google.idea.blaze.android.run.attach.BlazeAndroidNativeAttachConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) AndroidNativeAttachConfiguration(com.android.tools.ndk.run.attach.AndroidNativeAttachConfiguration) Module(com.intellij.openapi.module.Module) NativeAndroidDebuggerState(com.android.tools.ndk.run.editor.NativeAndroidDebuggerState) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Aggregations

DebuggerSession (com.intellij.debugger.impl.DebuggerSession)32 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)11 Project (com.intellij.openapi.project.Project)10 XDebugSession (com.intellij.xdebugger.XDebugSession)10 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)9 Nullable (org.jetbrains.annotations.Nullable)8 DebugEnvironment (com.intellij.debugger.DebugEnvironment)6 DebuggerManagerEx (com.intellij.debugger.DebuggerManagerEx)6 XDebugProcessStarter (com.intellij.xdebugger.XDebugProcessStarter)5 NotNull (org.jetbrains.annotations.NotNull)5 DefaultDebugEnvironment (com.intellij.debugger.DefaultDebugEnvironment)4 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)4 ExecutionResult (com.intellij.execution.ExecutionResult)4 XDebugSessionImpl (com.intellij.xdebugger.impl.XDebugSessionImpl)4 SourcePosition (com.intellij.debugger.SourcePosition)3 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)3 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)3 XDebugProcess (com.intellij.xdebugger.XDebugProcess)3 DefaultDebugUIEnvironment (com.intellij.debugger.DefaultDebugUIEnvironment)2 JavaDebugProcess (com.intellij.debugger.engine.JavaDebugProcess)2