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);
}
}
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();
}
});
}
}
}
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);
}
}
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();
}
}
});
}
}
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();
}
}
Aggregations