Search in sources :

Example 26 with XDebugSession

use of com.intellij.xdebugger.XDebugSession in project intellij-plugins by JetBrains.

the class SendCommandToDebuggerAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null)
        return;
    final XDebugSession xDebugSession = XDebuggerManager.getInstance(project).getCurrentSession();
    new MyDialogWrapper(project, xDebugSession).show();
}
Also used : Project(com.intellij.openapi.project.Project) XDebugSession(com.intellij.xdebugger.XDebugSession)

Example 27 with XDebugSession

use of com.intellij.xdebugger.XDebugSession in project intellij-plugins by JetBrains.

the class KarmaDebugProgramRunner method createDescriptor.

@NotNull
private static RunContentDescriptor createDescriptor(@NotNull ExecutionEnvironment environment, @NotNull ExecutionResult executionResult, @NotNull KarmaConsoleView consoleView, @NotNull KarmaServer karmaServer, @NotNull DebuggableWebBrowser debuggableWebBrowser) throws ExecutionException {
    Url url = Urls.newFromEncoded(karmaServer.formatUrl("/"));
    DebuggableFileFinder fileFinder = getDebuggableFileFinder(karmaServer);
    XDebugSession session = XDebuggerManager.getInstance(environment.getProject()).startSession(environment, new XDebugProcessStarter() {

        @Override
        @NotNull
        public XDebugProcess start(@NotNull XDebugSession session) {
            JavaScriptDebugEngine debugEngine = debuggableWebBrowser.getDebugEngine();
            WebBrowser browser = debuggableWebBrowser.getWebBrowser();
            JavaScriptDebugProcess<? extends VmConnection> debugProcess = debugEngine.createDebugProcess(session, browser, fileFinder, url, executionResult, true);
            debugProcess.addFirstLineBreakpointPattern("\\.browserify$");
            debugProcess.setElementsInspectorEnabled(false);
            debugProcess.setConsoleMessagesSupportEnabled(false);
            debugProcess.setLayouter(consoleView.createDebugLayouter(debugProcess));
            Alarm alarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, consoleView);
            alarm.addRequest(() -> {
                resumeTestRunning(executionResult.getProcessHandler());
                Disposer.dispose(alarm);
            }, 2000);
            return debugProcess;
        }
    });
    return session.getRunContentDescriptor();
}
Also used : JavaScriptDebugProcess(com.intellij.javascript.debugger.JavaScriptDebugProcess) XDebugSession(com.intellij.xdebugger.XDebugSession) VmConnection(org.jetbrains.debugger.connection.VmConnection) XDebugProcess(com.intellij.xdebugger.XDebugProcess) WebBrowser(com.intellij.ide.browsers.WebBrowser) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) Alarm(com.intellij.util.Alarm) NotNull(org.jetbrains.annotations.NotNull) Url(com.intellij.util.Url) DebuggableFileFinder(com.intellij.javascript.debugger.DebuggableFileFinder) JavaScriptDebugEngine(com.intellij.javascript.debugger.JavaScriptDebugEngine) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with XDebugSession

use of com.intellij.xdebugger.XDebugSession in project buck by facebook.

the class TestExecutionState method attachDebugger.

private void attachDebugger(String title, String port) {
    final RemoteConnection remoteConnection = new RemoteConnection(/* useSockets */
    true, "localhost", port, /* serverMode */
    false);
    final RemoteStateState state = new RemoteStateState(mProject, remoteConnection);
    final String name = title + " debugger (" + port + ")";
    final ConfigurationFactory cfgFactory = ConfigurationTypeUtil.findConfigurationType("Remote").getConfigurationFactories()[0];
    RunnerAndConfigurationSettings runSettings = RunManager.getInstance(mProject).createRunConfiguration(name, cfgFactory);
    final Executor debugExecutor = DefaultDebugExecutor.getDebugExecutorInstance();
    final ExecutionEnvironment env = new ExecutionEnvironmentBuilder(mProject, debugExecutor).runProfile(runSettings.getConfiguration()).build();
    final int pollTimeout = 3000;
    final DebugEnvironment environment = new DefaultDebugEnvironment(env, state, remoteConnection, pollTimeout);
    ApplicationManager.getApplication().invokeLater(() -> {
        try {
            final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(mProject).attachVirtualMachine(environment);
            if (debuggerSession == null) {
                return;
            }
            XDebuggerManager.getInstance(mProject).startSessionAndShowTab(name, null, new XDebugProcessStarter() {

                @Override
                @NotNull
                public XDebugProcess start(@NotNull XDebugSession session) {
                    return JavaDebugProcess.create(session, debuggerSession);
                }
            });
        } catch (ExecutionException e) {
            LOG.error("failed to attach to debugger on port " + port + " with polling timeout " + pollTimeout);
        }
    });
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) XDebugProcess(com.intellij.xdebugger.XDebugProcess) NotNull(org.jetbrains.annotations.NotNull) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) Executor(com.intellij.execution.Executor) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) RemoteStateState(com.intellij.debugger.engine.RemoteStateState) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ExecutionException(com.intellij.execution.ExecutionException) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DebugEnvironment(com.intellij.debugger.DebugEnvironment)

Example 29 with XDebugSession

use of com.intellij.xdebugger.XDebugSession in project intellij-community by JetBrains.

the class ReloadClassesWorker method reloadClasses.

public void reloadClasses(final Map<String, HotSwapFile> modifiedClasses) {
    DebuggerManagerThreadImpl.assertIsManagerThread();
    if (modifiedClasses == null || modifiedClasses.size() == 0) {
        myProgress.addMessage(myDebuggerSession, MessageCategory.INFORMATION, DebuggerBundle.message("status.hotswap.loaded.classes.up.to.date"));
        return;
    }
    final DebugProcessImpl debugProcess = getDebugProcess();
    final VirtualMachineProxyImpl virtualMachineProxy = debugProcess.getVirtualMachineProxy();
    final Project project = debugProcess.getProject();
    final BreakpointManager breakpointManager = (DebuggerManagerEx.getInstanceEx(project)).getBreakpointManager();
    breakpointManager.disableBreakpoints(debugProcess);
    try {
        RedefineProcessor redefineProcessor = new RedefineProcessor(virtualMachineProxy);
        int processedEntriesCount = 0;
        for (final Map.Entry<String, HotSwapFile> entry : modifiedClasses.entrySet()) {
            // stop if process is finished already
            if (debugProcess.isDetached() || debugProcess.isDetaching()) {
                break;
            }
            if (redefineProcessor.getProcessedClassesCount() == 0 && myProgress.isCancelled()) {
                // once at least one class has been actually reloaded, do not interrupt the whole process
                break;
            }
            processedEntriesCount++;
            final String qualifiedName = entry.getKey();
            if (qualifiedName != null) {
                myProgress.setText(qualifiedName);
                myProgress.setFraction(processedEntriesCount / (double) modifiedClasses.size());
            }
            try {
                redefineProcessor.processClass(qualifiedName, entry.getValue().file);
            } catch (IOException e) {
                reportProblem(qualifiedName, e);
            }
        }
        if (redefineProcessor.getProcessedClassesCount() == 0 && myProgress.isCancelled()) {
            // once at least one class has been actually reloaded, do not interrupt the whole process
            return;
        }
        redefineProcessor.processPending();
        myProgress.setFraction(1);
        final int partiallyRedefinedClassesCount = redefineProcessor.getPartiallyRedefinedClassesCount();
        if (partiallyRedefinedClassesCount == 0) {
            myProgress.addMessage(myDebuggerSession, MessageCategory.INFORMATION, DebuggerBundle.message("status.classes.reloaded", redefineProcessor.getProcessedClassesCount()));
        } else {
            final String message = DebuggerBundle.message("status.classes.not.all.versions.reloaded", partiallyRedefinedClassesCount, redefineProcessor.getProcessedClassesCount());
            myProgress.addMessage(myDebuggerSession, MessageCategory.WARNING, message);
        }
        LOG.debug("classes reloaded");
    } catch (Throwable e) {
        processException(e);
    }
    debugProcess.onHotSwapFinished();
    DebuggerContextImpl context = myDebuggerSession.getContextManager().getContext();
    SuspendContextImpl suspendContext = context.getSuspendContext();
    if (suspendContext != null) {
        XExecutionStack stack = suspendContext.getActiveExecutionStack();
        if (stack != null) {
            ((JavaExecutionStack) stack).initTopFrame();
        }
    }
    final Semaphore waitSemaphore = new Semaphore();
    waitSemaphore.down();
    //noinspection SSBasedInspection
    SwingUtilities.invokeLater(() -> {
        try {
            if (!project.isDisposed()) {
                breakpointManager.reloadBreakpoints();
                debugProcess.getRequestsManager().clearWarnings();
                if (LOG.isDebugEnabled()) {
                    LOG.debug("requests updated");
                    LOG.debug("time stamp set");
                }
                myDebuggerSession.refresh(false);
                XDebugSession session = myDebuggerSession.getXDebugSession();
                if (session != null) {
                    session.rebuildViews();
                }
            }
        } catch (Throwable e) {
            LOG.error(e);
        } finally {
            waitSemaphore.up();
        }
    });
    waitSemaphore.waitFor();
    if (!project.isDisposed()) {
        try {
            breakpointManager.enableBreakpoints(debugProcess);
        } catch (Exception e) {
            processException(e);
        }
    }
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) IOException(java.io.IOException) Semaphore(com.intellij.util.concurrency.Semaphore) BreakpointManager(com.intellij.debugger.ui.breakpoints.BreakpointManager) XExecutionStack(com.intellij.xdebugger.frame.XExecutionStack) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IOException(java.io.IOException) Project(com.intellij.openapi.project.Project) JavaExecutionStack(com.intellij.debugger.engine.JavaExecutionStack) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) SuspendContextImpl(com.intellij.debugger.engine.SuspendContextImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 30 with XDebugSession

use of com.intellij.xdebugger.XDebugSession in project intellij-community by JetBrains.

the class CustomizeContextViewAction method update.

@Override
public void update(AnActionEvent e) {
    e.getPresentation().setText(ActionsBundle.actionText(DebuggerActions.CUSTOMIZE_VIEWS));
    Project project = getEventProject(e);
    if (project != null) {
        final XDebugSession currentSession = XDebuggerManager.getInstance(project).getCurrentSession();
        if (currentSession != null) {
            e.getPresentation().setEnabledAndVisible(currentSession.getDebugProcess() instanceof JavaDebugProcess);
            return;
        }
    }
    e.getPresentation().setEnabledAndVisible(false);
}
Also used : Project(com.intellij.openapi.project.Project) XDebugSession(com.intellij.xdebugger.XDebugSession) JavaDebugProcess(com.intellij.debugger.engine.JavaDebugProcess)

Aggregations

XDebugSession (com.intellij.xdebugger.XDebugSession)50 Project (com.intellij.openapi.project.Project)15 NotNull (org.jetbrains.annotations.NotNull)13 XDebugProcessStarter (com.intellij.xdebugger.XDebugProcessStarter)9 XDebugSessionImpl (com.intellij.xdebugger.impl.XDebugSessionImpl)9 XDebugProcess (com.intellij.xdebugger.XDebugProcess)8 Nullable (org.jetbrains.annotations.Nullable)7 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)6 IOException (java.io.IOException)5 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)4 ExecutionException (com.intellij.execution.ExecutionException)4 XValueNodeImpl (com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl)4 DebugEnvironment (com.intellij.debugger.DebugEnvironment)3 VirtualMachineProxyImpl (com.intellij.debugger.jdi.VirtualMachineProxyImpl)3 ExecutionResult (com.intellij.execution.ExecutionResult)3 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)3 XSourcePosition (com.intellij.xdebugger.XSourcePosition)3 ServerSocket (java.net.ServerSocket)3 List (java.util.List)3 DefaultDebugEnvironment (com.intellij.debugger.DefaultDebugEnvironment)2