Search in sources :

Example 11 with DebugProcess

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

the class CompilingEvaluator method evaluate.

@Override
public Value evaluate(final EvaluationContext evaluationContext) throws EvaluateException {
    DebugProcess process = evaluationContext.getDebugProcess();
    EvaluationContextImpl autoLoadContext = ((EvaluationContextImpl) evaluationContext).createEvaluationContext(evaluationContext.getThisObject());
    autoLoadContext.setAutoLoadClasses(true);
    ClassLoaderReference classLoader = ClassLoadingUtils.getClassLoader(autoLoadContext, process);
    autoLoadContext.setClassLoader(classLoader);
    String version = ((VirtualMachineProxyImpl) process.getVirtualMachineProxy()).version();
    Collection<ClassObject> classes = compile(JdkVersionUtil.getVersion(version));
    defineClasses(classes, autoLoadContext, process, classLoader);
    try {
        // invoke base evaluator on call code
        SourcePosition position = ContextUtil.getSourcePosition(evaluationContext);
        ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(myProject, new EvaluatingComputable<ExpressionEvaluator>() {

            @Override
            public ExpressionEvaluator compute() throws EvaluateException {
                TextWithImports callCode = getCallCode();
                PsiElement copyContext = myData.getAnchor();
                CodeFragmentFactory factory = DebuggerUtilsEx.findAppropriateCodeFragmentFactory(callCode, copyContext);
                return factory.getEvaluatorBuilder().build(factory.createCodeFragment(callCode, copyContext, myProject), position);
            }
        });
        return evaluator.evaluate(autoLoadContext);
    } catch (Exception e) {
        throw new EvaluateException("Error during generated code invocation " + e, e);
    }
}
Also used : VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) ClassObject(com.intellij.openapi.compiler.ClassObject) ClassLoaderReference(com.sun.jdi.ClassLoaderReference) ExpressionEvaluator(com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator) DebugProcess(com.intellij.debugger.engine.DebugProcess) SourcePosition(com.intellij.debugger.SourcePosition) PsiElement(com.intellij.psi.PsiElement)

Example 12 with DebugProcess

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

the class JavaTestFrameworkDebuggerRunner method createContentDescriptor.

@Nullable
@Override
protected RunContentDescriptor createContentDescriptor(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment environment) throws ExecutionException {
    final RunContentDescriptor res = super.createContentDescriptor(state, environment);
    final ServerSocket socket = ((JavaTestFrameworkRunnableState) state).getForkSocket();
    if (socket != null) {
        Thread thread = new Thread(getThreadName() + " debugger runner") {

            @Override
            public void run() {
                try {
                    final Socket accept = socket.accept();
                    try {
                        DataInputStream stream = new DataInputStream(accept.getInputStream());
                        try {
                            int read = stream.readInt();
                            while (read != -1) {
                                final DebugProcess process = DebuggerManager.getInstance(environment.getProject()).getDebugProcess(res.getProcessHandler());
                                if (process == null)
                                    break;
                                final RemoteConnection connection = new RemoteConnection(true, "127.0.0.1", String.valueOf(read), true);
                                final DebugEnvironment env = new DefaultDebugEnvironment(environment, state, connection, true);
                                SwingUtilities.invokeLater(() -> {
                                    try {
                                        ((DebugProcessImpl) process).reattach(env);
                                        accept.getOutputStream().write(0);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                });
                                read = stream.readInt();
                            }
                        } finally {
                            stream.close();
                        }
                    } finally {
                        accept.close();
                    }
                } catch (EOFException ignored) {
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        };
        thread.setDaemon(true);
        thread.start();
    }
    return res;
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JavaTestFrameworkRunnableState(com.intellij.execution.JavaTestFrameworkRunnableState) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) ExecutionException(com.intellij.execution.ExecutionException) IOException(java.io.IOException) EOFException(java.io.EOFException) DebugProcess(com.intellij.debugger.engine.DebugProcess) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) EOFException(java.io.EOFException) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DebugEnvironment(com.intellij.debugger.DebugEnvironment) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with DebugProcess

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

the class CompoundTypeRenderer method getContext.

protected final PsiElement getContext(Project project, DebuggerContext context) {
    DebugProcess process = context.getDebugProcess();
    GlobalSearchScope scope = process != null ? process.getSearchScope() : GlobalSearchScope.allScope(project);
    return DebuggerUtils.findClass(getClassName(), project, scope);
}
Also used : DebugProcess(com.intellij.debugger.engine.DebugProcess) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 14 with DebugProcess

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

the class LabelRenderer method calcLabel.

public String calcLabel(ValueDescriptor descriptor, EvaluationContext evaluationContext, DescriptorLabelListener labelListener) throws EvaluateException {
    final Value value = descriptor.getValue();
    String result;
    final DebugProcess debugProcess = evaluationContext.getDebugProcess();
    if (value != null) {
        try {
            final ExpressionEvaluator evaluator = myLabelExpression.getEvaluator(debugProcess.getProject());
            if (!debugProcess.isAttached()) {
                throw EvaluateExceptionUtil.PROCESS_EXITED;
            }
            EvaluationContext thisEvaluationContext = evaluationContext.createEvaluationContext(value);
            Value labelValue = evaluator.evaluate(thisEvaluationContext);
            result = DebuggerUtils.getValueAsString(thisEvaluationContext, labelValue);
        } catch (final EvaluateException ex) {
            throw new EvaluateException(DebuggerBundle.message("error.unable.to.evaluate.expression") + " " + ex.getMessage(), ex);
        }
    } else {
        //noinspection HardCodedStringLiteral
        result = "null";
    }
    return result;
}
Also used : DebugProcess(com.intellij.debugger.engine.DebugProcess) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) Value(com.sun.jdi.Value) EvaluationContext(com.intellij.debugger.engine.evaluation.EvaluationContext) ExpressionEvaluator(com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)

Example 15 with DebugProcess

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

the class JavaDebuggerLauncherImpl method startDebugSession.

@Override
public void startDebugSession(@NotNull JavaDebugConnectionData info, @NotNull ExecutionEnvironment executionEnvironment, @NotNull RemoteServer<?> server) throws ExecutionException {
    final Project project = executionEnvironment.getProject();
    final DebuggerPanelsManager manager = DebuggerPanelsManager.getInstance(project);
    final JavaDebugServerModeHandler serverModeHandler = info.getServerModeHandler();
    boolean serverMode = serverModeHandler != null;
    final RemoteConnection remoteConnection = new RemoteConnection(true, info.getHost(), String.valueOf(info.getPort()), serverMode);
    DebugEnvironment debugEnvironment = new RemoteServerDebugEnvironment(project, remoteConnection, executionEnvironment.getRunProfile());
    DebugUIEnvironment debugUIEnvironment = new RemoteServerDebugUIEnvironment(debugEnvironment, executionEnvironment);
    RunContentDescriptor debugContentDescriptor = manager.attachVirtualMachine(debugUIEnvironment);
    LOG.assertTrue(debugContentDescriptor != null);
    ProcessHandler processHandler = debugContentDescriptor.getProcessHandler();
    LOG.assertTrue(processHandler != null);
    if (serverMode) {
        serverModeHandler.attachRemote();
        DebuggerManager.getInstance(executionEnvironment.getProject()).addDebugProcessListener(processHandler, new DebugProcessListener() {

            public void processDetached(DebugProcess process, boolean closedByUser) {
                try {
                    serverModeHandler.detachRemote();
                } catch (ExecutionException e) {
                    LOG.info(e);
                }
            }
        });
    }
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JavaDebugServerModeHandler(com.intellij.remoteServer.runtime.deployment.debug.JavaDebugServerModeHandler) Project(com.intellij.openapi.project.Project) DebugProcess(com.intellij.debugger.engine.DebugProcess) DebugProcessListener(com.intellij.debugger.engine.DebugProcessListener) DebuggerPanelsManager(com.intellij.debugger.ui.DebuggerPanelsManager) RemoteDebugProcessHandler(com.intellij.debugger.engine.RemoteDebugProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) ExecutionException(com.intellij.execution.ExecutionException) DebugEnvironment(com.intellij.debugger.DebugEnvironment) DebugUIEnvironment(com.intellij.debugger.DebugUIEnvironment)

Aggregations

DebugProcess (com.intellij.debugger.engine.DebugProcess)18 VirtualMachineProxyImpl (com.intellij.debugger.jdi.VirtualMachineProxyImpl)4 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)3 DebugProcessListener (com.intellij.debugger.engine.DebugProcessListener)3 DebugEnvironment (com.intellij.debugger.DebugEnvironment)2 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)2 EvaluationContext (com.intellij.debugger.engine.evaluation.EvaluationContext)2 ExpressionEvaluator (com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)2 ClassPrepareRequestor (com.intellij.debugger.requests.ClassPrepareRequestor)2 ExecutionException (com.intellij.execution.ExecutionException)2 RemoteConnection (com.intellij.execution.configurations.RemoteConnection)2 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)2 ReferenceType (com.sun.jdi.ReferenceType)2 Nullable (org.jetbrains.annotations.Nullable)2 DebugUIEnvironment (com.intellij.debugger.DebugUIEnvironment)1 DefaultDebugEnvironment (com.intellij.debugger.DefaultDebugEnvironment)1 SourcePosition (com.intellij.debugger.SourcePosition)1 CompoundPositionManager (com.intellij.debugger.engine.CompoundPositionManager)1 RemoteDebugProcessHandler (com.intellij.debugger.engine.RemoteDebugProcessHandler)1 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)1