Search in sources :

Example 51 with DebugProcessImpl

use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.

the class GroovyPositionManager method createPrepareRequest.

@Override
public ClassPrepareRequest createPrepareRequest(@NotNull final ClassPrepareRequestor requestor, @NotNull final SourcePosition position) throws NoDataException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("createPrepareRequest: " + position);
    }
    checkGroovyFile(position);
    String qName = getOuterClassName(position);
    if (qName != null) {
        return myDebugProcess.getRequestsManager().createClassPrepareRequest(requestor, qName);
    }
    qName = findEnclosingName(position);
    if (qName == null)
        throw NoDataException.INSTANCE;
    ClassPrepareRequestor waitRequestor = new ClassPrepareRequestor() {

        @Override
        public void processClassPrepare(DebugProcess debuggerProcess, ReferenceType referenceType) {
            final CompoundPositionManager positionManager = ((DebugProcessImpl) debuggerProcess).getPositionManager();
            if (!positionManager.locationsOfLine(referenceType, position).isEmpty()) {
                requestor.processClassPrepare(debuggerProcess, referenceType);
            }
        }
    };
    return myDebugProcess.getRequestsManager().createClassPrepareRequest(waitRequestor, qName + "$*");
}
Also used : ClassPrepareRequestor(com.intellij.debugger.requests.ClassPrepareRequestor) DebugProcess(com.intellij.debugger.engine.DebugProcess) CompoundPositionManager(com.intellij.debugger.engine.CompoundPositionManager) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) ReferenceType(com.sun.jdi.ReferenceType)

Example 52 with DebugProcessImpl

use of com.intellij.debugger.engine.DebugProcessImpl 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 53 with DebugProcessImpl

use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.

the class SourceCodeChecker method checkAllClasses.

@TestOnly
@SuppressWarnings("UseOfSystemOutOrSystemErr")
private static void checkAllClasses(DebuggerContextImpl debuggerContext) {
    DebugProcessImpl process = debuggerContext.getDebugProcess();
    @SuppressWarnings("ConstantConditions") VirtualMachine machine = process.getVirtualMachineProxy().getVirtualMachine();
    // only default position manager for now
    PositionManagerImpl positionManager = new PositionManagerImpl(process);
    List<ReferenceType> types = machine.allClasses();
    System.out.println("Checking " + types.size() + " classes");
    int i = 0;
    for (ReferenceType type : types) {
        i++;
        try {
            for (Location loc : type.allLineLocations()) {
                SourcePosition position = ReadAction.compute(() -> {
                    try {
                        return positionManager.getSourcePosition(loc);
                    } catch (NoDataException ignore) {
                        return null;
                    }
                });
                if (position == null) {
                    continue;
                }
                if (position.getFile() instanceof PsiCompiledFile) {
                    VirtualFile file = position.getFile().getVirtualFile();
                    if (file == null || file.getUserData(LineNumbersMapping.LINE_NUMBERS_MAPPING_KEY) == null) {
                        // no mapping - skip the whole file
                        break;
                    }
                    if (DebuggerUtilsEx.bytecodeToSourceLine(position.getFile(), loc.lineNumber()) == -1) {
                        continue;
                    }
                }
                if (check(loc, position, process.getProject()) == ThreeState.NO) {
                    System.out.println("failed " + type);
                    break;
                }
            }
        } catch (AbsentInformationException ignored) {
        }
    }
    System.out.println("Done checking");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PositionManagerImpl(com.intellij.debugger.engine.PositionManagerImpl) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) SourcePosition(com.intellij.debugger.SourcePosition) NoDataException(com.intellij.debugger.NoDataException) TestOnly(org.jetbrains.annotations.TestOnly)

Example 54 with DebugProcessImpl

use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.

the class DebuggerTestCase method createLocalProcess.

protected DebuggerSession createLocalProcess(int transport, final JavaParameters javaParameters) throws ExecutionException, InterruptedException, InvocationTargetException {
    createBreakpoints(javaParameters.getMainClass());
    final DebuggerSession[] debuggerSession = new DebuggerSession[] { null };
    DebuggerSettings.getInstance().DEBUGGER_TRANSPORT = transport;
    GenericDebuggerRunnerSettings debuggerRunnerSettings = new GenericDebuggerRunnerSettings();
    debuggerRunnerSettings.LOCAL = true;
    debuggerRunnerSettings.setDebugPort(String.valueOf(DEFAULT_ADDRESS));
    ExecutionEnvironment environment = new ExecutionEnvironmentBuilder(myProject, DefaultDebugExecutor.getDebugExecutorInstance()).runnerSettings(debuggerRunnerSettings).runProfile(new MockConfiguration()).build();
    final JavaCommandLineState javaCommandLineState = new JavaCommandLineState(environment) {

        @Override
        protected JavaParameters createJavaParameters() {
            return javaParameters;
        }

        @Override
        protected GeneralCommandLine createCommandLine() throws ExecutionException {
            return getJavaParameters().toCommandLine();
        }
    };
    final RemoteConnection debugParameters = DebuggerManagerImpl.createDebugParameters(javaCommandLineState.getJavaParameters(), debuggerRunnerSettings, true);
    UIUtil.invokeAndWaitIfNeeded(new Runnable() {

        @Override
        public void run() {
            try {
                debuggerSession[0] = attachVirtualMachine(javaCommandLineState, javaCommandLineState.getEnvironment(), debugParameters, false);
            } catch (ExecutionException e) {
                fail(e.getMessage());
            }
        }
    });
    final ProcessHandler processHandler = debuggerSession[0].getProcess().getProcessHandler();
    debuggerSession[0].getProcess().addProcessListener(new ProcessAdapter() {

        @Override
        public void onTextAvailable(ProcessEvent event, Key outputType) {
            print(event.getText(), outputType);
        }
    });
    DebugProcessImpl process = (DebugProcessImpl) DebuggerManagerEx.getInstanceEx(myProject).getDebugProcess(processHandler);
    assertNotNull(process);
    return debuggerSession[0];
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) ThrowableRunnable(com.intellij.util.ThrowableRunnable) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Example 55 with DebugProcessImpl

use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.

the class MethodBreakpoint method createRequestForSubClasses.

private static void createRequestForSubClasses(@NotNull MethodBreakpointBase breakpoint, @NotNull DebugProcessImpl debugProcess, @NotNull ReferenceType baseType) {
    DebuggerManagerThreadImpl.assertIsManagerThread();
    RequestManagerImpl requestsManager = debugProcess.getRequestsManager();
    ClassPrepareRequest request = requestsManager.createClassPrepareRequest((debuggerProcess, referenceType) -> {
        if (instanceOf(referenceType, baseType)) {
            createRequestForPreparedClassEmulated(breakpoint, debugProcess, referenceType, false);
        }
    }, null);
    if (request != null) {
        requestsManager.registerRequest(breakpoint, request);
        request.enable();
        // to force reload classes available so far
        debugProcess.getVirtualMachineProxy().clearCaches();
    }
    AtomicReference<ProgressIndicator> indicatorRef = new AtomicReference<>();
    ApplicationManager.getApplication().invokeAndWait(() -> indicatorRef.set(new ProgressWindowWithNotification(true, false, debugProcess.getProject(), "Cancel emulation")));
    ProgressIndicator indicator = indicatorRef.get();
    ProgressManager.getInstance().executeProcessUnderProgress(() -> processPreparedSubTypes(baseType, subType -> createRequestForPreparedClassEmulated(breakpoint, debugProcess, subType, false), indicator), indicator);
    if (indicator.isCanceled()) {
        breakpoint.disableEmulation();
    }
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) MethodEntryEvent(com.sun.jdi.event.MethodEntryEvent) JVMNameUtil(com.intellij.debugger.engine.JVMNameUtil) AllIcons(com.intellij.icons.AllIcons) Document(com.intellij.openapi.editor.Document) Opcodes(org.jetbrains.org.objectweb.asm.Opcodes) DebuggerUtilsEx(com.intellij.debugger.impl.DebuggerUtilsEx) EventRequest(com.sun.jdi.request.EventRequest) EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl) StringBuilderSpinAllocator(com.intellij.util.StringBuilderSpinAllocator) ProgressWindowWithNotification(com.intellij.openapi.progress.util.ProgressWindowWithNotification) Logger(com.intellij.openapi.diagnostic.Logger) MultiMap(com.intellij.util.containers.MultiMap) MethodEntryRequest(com.sun.jdi.request.MethodEntryRequest) DebuggerManagerThreadImpl(com.intellij.debugger.engine.DebuggerManagerThreadImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ProgressManager(com.intellij.openapi.progress.ProgressManager) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) MethodExitRequest(com.sun.jdi.request.MethodExitRequest) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) PositionUtil(com.intellij.debugger.impl.PositionUtil) MethodExitEvent(com.sun.jdi.event.MethodExitEvent) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) Stream(java.util.stream.Stream) StreamEx(one.util.streamex.StreamEx) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Requestor(com.intellij.debugger.requests.Requestor) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) SourcePosition(com.intellij.debugger.SourcePosition) LocatableEvent(com.sun.jdi.event.LocatableEvent) Label(org.jetbrains.org.objectweb.asm.Label) NonNls(org.jetbrains.annotations.NonNls) MethodBytecodeUtil(com.intellij.debugger.jdi.MethodBytecodeUtil) ContainerUtil(com.intellij.util.containers.ContainerUtil) AtomicReference(java.util.concurrent.atomic.AtomicReference) RequestManagerImpl(com.intellij.debugger.engine.requests.RequestManagerImpl) Project(com.intellij.openapi.project.Project) DebuggerBundle(com.intellij.debugger.DebuggerBundle) JavaMethodBreakpointProperties(org.jetbrains.java.debugger.breakpoints.properties.JavaMethodBreakpointProperties) MethodVisitor(org.jetbrains.org.objectweb.asm.MethodVisitor) JVMName(com.intellij.debugger.engine.JVMName) Consumer(java.util.function.Consumer) ClassPrepareRequest(com.sun.jdi.request.ClassPrepareRequest) DebuggerManagerEx(com.intellij.debugger.DebuggerManagerEx) com.sun.jdi(com.sun.jdi) Element(org.jdom.Element) javax.swing(javax.swing) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProgressWindowWithNotification(com.intellij.openapi.progress.util.ProgressWindowWithNotification) AtomicReference(java.util.concurrent.atomic.AtomicReference) RequestManagerImpl(com.intellij.debugger.engine.requests.RequestManagerImpl) ClassPrepareRequest(com.sun.jdi.request.ClassPrepareRequest)

Aggregations

DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)56 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)20 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)15 Project (com.intellij.openapi.project.Project)15 Nullable (org.jetbrains.annotations.Nullable)12 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)9 DebuggerTreeNodeImpl (com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl)9 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)7 List (java.util.List)7 SourcePosition (com.intellij.debugger.SourcePosition)5 JavaValue (com.intellij.debugger.engine.JavaValue)5 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)5 StackFrameProxyImpl (com.intellij.debugger.jdi.StackFrameProxyImpl)5 ThreadReferenceProxyImpl (com.intellij.debugger.jdi.ThreadReferenceProxyImpl)5 VirtualMachineProxyImpl (com.intellij.debugger.jdi.VirtualMachineProxyImpl)5 XDebugSession (com.intellij.xdebugger.XDebugSession)5 NotNull (org.jetbrains.annotations.NotNull)5 NodeDescriptorImpl (com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl)4 ThreadDescriptorImpl (com.intellij.debugger.ui.impl.watch.ThreadDescriptorImpl)4 ArrayList (java.util.ArrayList)4