Search in sources :

Example 46 with DebugProcessImpl

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

the class MethodEvaluator method evaluate.

@Override
public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
    if (!context.getDebugProcess().isAttached())
        return null;
    DebugProcessImpl debugProcess = context.getDebugProcess();
    final boolean requiresSuperObject = myObjectEvaluator instanceof SuperEvaluator || (myObjectEvaluator instanceof DisableGC && ((DisableGC) myObjectEvaluator).getDelegate() instanceof SuperEvaluator);
    final Object object = myObjectEvaluator.evaluate(context);
    if (LOG.isDebugEnabled()) {
        LOG.debug("MethodEvaluator: object = " + object);
    }
    if (object == null) {
        throw EvaluateExceptionUtil.createEvaluateException(new NullPointerException());
    }
    if (!(object instanceof ObjectReference || isInvokableType(object))) {
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.evaluating.method", myMethodName));
    }
    List args = new ArrayList(myArgumentEvaluators.length);
    for (Evaluator evaluator : myArgumentEvaluators) {
        args.add(evaluator.evaluate(context));
    }
    try {
        ReferenceType referenceType = null;
        if (object instanceof ObjectReference) {
            // it seems that if we have an object of the class, the class must be ready, so no need to use findClass here
            referenceType = ((ObjectReference) object).referenceType();
        } else if (isInvokableType(object)) {
            referenceType = (ReferenceType) object;
        } else {
            final String className = myClassName != null ? myClassName.getName(debugProcess) : null;
            if (className != null) {
                referenceType = debugProcess.findClass(context, className, context.getClassLoader());
            }
        }
        if (referenceType == null) {
            throw new EvaluateRuntimeException(EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.cannot.evaluate.qualifier", myMethodName)));
        }
        final String signature = myMethodSignature != null ? myMethodSignature.getName(debugProcess) : null;
        final String methodName = DebuggerUtilsEx.methodName(referenceType.name(), myMethodName, signature);
        if (isInvokableType(object)) {
            if (isInvokableType(referenceType)) {
                Method jdiMethod = DebuggerUtils.findMethod(referenceType, myMethodName, signature);
                if (jdiMethod != null && jdiMethod.isStatic()) {
                    if (referenceType instanceof ClassType) {
                        return debugProcess.invokeMethod(context, (ClassType) referenceType, jdiMethod, args);
                    } else {
                        return debugProcess.invokeMethod(context, (InterfaceType) referenceType, jdiMethod, args);
                    }
                }
            }
            throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.no.static.method", methodName));
        }
        // object should be an ObjectReference
        final ObjectReference objRef = (ObjectReference) object;
        ReferenceType _refType = referenceType;
        if (requiresSuperObject && (referenceType instanceof ClassType)) {
            _refType = ((ClassType) referenceType).superclass();
        }
        Method jdiMethod = DebuggerUtils.findMethod(_refType, myMethodName, signature);
        if (signature == null) {
            // IMPORTANT! using argumentTypeNames() instead of argumentTypes() to avoid type resolution inside JDI, which may be time-consuming
            if (jdiMethod == null || jdiMethod.argumentTypeNames().size() != args.size()) {
                for (Method method : _refType.methodsByName(myMethodName)) {
                    if (method.argumentTypeNames().size() == args.size()) {
                        jdiMethod = method;
                        break;
                    }
                }
            }
        } else if (myMustBeVararg && jdiMethod != null && !jdiMethod.isVarArgs() && jdiMethod.isBridge()) {
            // see IDEA-129869, avoid bridge methods for varargs
            int retTypePos = signature.lastIndexOf(")");
            if (retTypePos >= 0) {
                String signatureNoRetType = signature.substring(0, retTypePos + 1);
                for (Method method : _refType.visibleMethods()) {
                    if (method.name().equals(myMethodName) && method.signature().startsWith(signatureNoRetType) && !method.isBridge() && !method.isAbstract()) {
                        jdiMethod = method;
                        break;
                    }
                }
            }
        }
        if (jdiMethod == null) {
            throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.no.instance.method", methodName));
        }
        if (requiresSuperObject) {
            return debugProcess.invokeInstanceMethod(context, objRef, jdiMethod, args, ObjectReference.INVOKE_NONVIRTUAL);
        }
        // fix for default methods in interfaces, see IDEA-124066
        if (Patches.JDK_BUG_ID_8042123 && myCheckDefaultInterfaceMethod && jdiMethod.declaringType() instanceof InterfaceType) {
            try {
                return invokeDefaultMethod(debugProcess, context, objRef, myMethodName);
            } catch (EvaluateException e) {
                LOG.info(e);
            }
        }
        return debugProcess.invokeMethod(context, objRef, jdiMethod, args);
    } catch (Exception e) {
        LOG.debug(e);
        throw EvaluateExceptionUtil.createEvaluateException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) ArrayList(java.util.ArrayList) List(java.util.List)

Example 47 with DebugProcessImpl

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

the class ResumeThreadAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    DebuggerTreeNodeImpl[] selectedNode = getSelectedNodes(e.getDataContext());
    final DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext());
    final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
    if (debugProcess == null)
        return;
    //noinspection ConstantConditions
    for (final DebuggerTreeNodeImpl debuggerTreeNode : selectedNode) {
        final ThreadDescriptorImpl threadDescriptor = ((ThreadDescriptorImpl) debuggerTreeNode.getDescriptor());
        if (threadDescriptor.isSuspended()) {
            final ThreadReferenceProxyImpl thread = threadDescriptor.getThreadReference();
            debugProcess.getManagerThread().schedule(new DebuggerCommandImpl() {

                @Override
                protected void action() throws Exception {
                    SuspendContextImpl suspendingContext = SuspendManagerUtil.getSuspendingContext(debugProcess.getSuspendManager(), thread);
                    if (suspendingContext != null) {
                        debugProcess.createResumeThreadCommand(suspendingContext, thread).run();
                    }
                    debuggerTreeNode.calcValue();
                }
            });
        }
    }
}
Also used : DebuggerTreeNodeImpl(com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl) DebuggerCommandImpl(com.intellij.debugger.engine.events.DebuggerCommandImpl) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) ThreadDescriptorImpl(com.intellij.debugger.ui.impl.watch.ThreadDescriptorImpl) SuspendContextImpl(com.intellij.debugger.engine.SuspendContextImpl) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) ThreadReferenceProxyImpl(com.intellij.debugger.jdi.ThreadReferenceProxyImpl)

Example 48 with DebugProcessImpl

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

the class ShowRelatedStackAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    List<StackFrameItem> stack = getRelatedStack(e);
    if (project != null && stack != null) {
        DebugProcessImpl debugProcess = DebuggerAction.getDebuggerContext(e.getDataContext()).getDebugProcess();
        if (debugProcess == null) {
            return;
        }
        StackFramePopup.show(stack, debugProcess);
    }
}
Also used : Project(com.intellij.openapi.project.Project) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) StackFrameItem(com.intellij.debugger.memory.utils.StackFrameItem)

Example 49 with DebugProcessImpl

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

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

the class BreakpointWithHighlighter method processClassPrepare.

@Override
public void processClassPrepare(DebugProcess debugProcess, ReferenceType classType) {
    DebugProcessImpl process = (DebugProcessImpl) debugProcess;
    if (shouldCreateRequest(process, true)) {
        createRequestForPreparedClass(process, classType);
        updateUI();
    }
}
Also used : DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl)

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