Search in sources :

Example 6 with XExecutionStack

use of com.intellij.xdebugger.frame.XExecutionStack 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 7 with XExecutionStack

use of com.intellij.xdebugger.frame.XExecutionStack in project ballerina by ballerina-lang.

the class BallerinaDebugProcess method stop.

@Override
public void stop() {
    // If we don't call this using the executeOnPooledThread(), the UI will hang until the debug server is stopped.
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        XDebugSession session = getSession();
        if (!isRemoteDebugMode) {
            XSuspendContext suspendContext = session.getSuspendContext();
            if (suspendContext != null) {
                XExecutionStack activeExecutionStack = suspendContext.getActiveExecutionStack();
                if (activeExecutionStack instanceof BallerinaSuspendContext.BallerinaExecutionStack) {
                    String workerID = ((BallerinaSuspendContext.BallerinaExecutionStack) activeExecutionStack).getMyWorkerID();
                    if (workerID != null) {
                        myConnector.sendCommand(Command.STOP, workerID);
                    }
                }
            } else {
                session.stop();
                return;
            }
        } else {
            myConnector.sendCommand(Command.STOP);
            session.stop();
            getSession().getConsoleView().print("Disconnected from the debug server.\n", ConsoleViewContentType.SYSTEM_OUTPUT);
        }
        isDisconnected = true;
        myConnector.close();
    });
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XSuspendContext(com.intellij.xdebugger.frame.XSuspendContext) XExecutionStack(com.intellij.xdebugger.frame.XExecutionStack)

Aggregations

XExecutionStack (com.intellij.xdebugger.frame.XExecutionStack)7 XDebugSession (com.intellij.xdebugger.XDebugSession)3 SuspendContextImpl (com.intellij.debugger.engine.SuspendContextImpl)2 XStackFrame (com.intellij.xdebugger.frame.XStackFrame)2 XSuspendContext (com.intellij.xdebugger.frame.XSuspendContext)2 IOException (java.io.IOException)2 Client (com.android.ddmlib.Client)1 InstantRunClient (com.android.tools.fd.client.InstantRunClient)1 InstantRunPushFailedException (com.android.tools.fd.client.InstantRunPushFailedException)1 DebuggerManagerEx (com.intellij.debugger.DebuggerManagerEx)1 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 JavaExecutionStack (com.intellij.debugger.engine.JavaExecutionStack)1 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)1 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)1 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)1 VirtualMachineProxyImpl (com.intellij.debugger.jdi.VirtualMachineProxyImpl)1 Breakpoint (com.intellij.debugger.ui.breakpoints.Breakpoint)1 BreakpointManager (com.intellij.debugger.ui.breakpoints.BreakpointManager)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Project (com.intellij.openapi.project.Project)1