use of com.intellij.debugger.engine.evaluation.EvaluationContextImpl in project intellij-community by JetBrains.
the class JavaStackFrame method buildVariablesThreadAction.
// copied from DebuggerTree
private void buildVariablesThreadAction(DebuggerContextImpl debuggerContext, XValueChildrenList children, XCompositeNode node) {
try {
final EvaluationContextImpl evaluationContext = debuggerContext.createEvaluationContext();
if (evaluationContext == null) {
return;
}
if (!debuggerContext.isEvaluationPossible()) {
node.setErrorMessage(MessageDescriptor.EVALUATION_NOT_POSSIBLE.getLabel());
//myChildren.add(myNodeManager.createNode(MessageDescriptor.EVALUATION_NOT_POSSIBLE, evaluationContext));
}
final Location location = myDescriptor.getLocation();
final ObjectReference thisObjectReference = myDescriptor.getThisObject();
if (thisObjectReference != null) {
ValueDescriptorImpl thisDescriptor = myNodeManager.getThisDescriptor(null, thisObjectReference);
children.add(JavaValue.create(thisDescriptor, evaluationContext, myNodeManager));
} else if (location != null) {
StaticDescriptorImpl staticDecriptor = myNodeManager.getStaticDescriptor(myDescriptor, location.declaringType());
if (staticDecriptor.isExpandable()) {
children.addTopGroup(new JavaStaticGroup(staticDecriptor, evaluationContext, myNodeManager));
}
}
DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
if (debugProcess == null) {
return;
}
// add last method return value if any
final Pair<Method, Value> methodValuePair = debugProcess.getLastExecutedMethod();
if (methodValuePair != null && myDescriptor.getUiIndex() == 0) {
ValueDescriptorImpl returnValueDescriptor = myNodeManager.getMethodReturnValueDescriptor(myDescriptor, methodValuePair.getFirst(), methodValuePair.getSecond());
children.add(JavaValue.create(returnValueDescriptor, evaluationContext, myNodeManager));
}
// add context exceptions
Set<ObjectReference> exceptions = new HashSet<>();
for (Pair<Breakpoint, Event> pair : DebuggerUtilsEx.getEventDescriptors(debuggerContext.getSuspendContext())) {
Event debugEvent = pair.getSecond();
if (debugEvent instanceof ExceptionEvent) {
ObjectReference exception = ((ExceptionEvent) debugEvent).exception();
if (exception != null) {
exceptions.add(exception);
}
}
}
exceptions.forEach(e -> children.add(JavaValue.create(myNodeManager.getThrownExceptionObjectDescriptor(myDescriptor, e), evaluationContext, myNodeManager)));
try {
buildVariables(debuggerContext, evaluationContext, debugProcess, children, thisObjectReference, location);
//if (classRenderer.SORT_ASCENDING) {
// Collections.sort(myChildren, NodeManagerImpl.getNodeComparator());
//}
} catch (EvaluateException e) {
node.setErrorMessage(e.getMessage());
//myChildren.add(myNodeManager.createMessageNode(new MessageDescriptor(e.getMessage())));
}
} catch (InvalidStackFrameException e) {
LOG.info(e);
//myChildren.clear();
//notifyCancelled();
} catch (InternalException e) {
if (e.errorCode() == 35) {
node.setErrorMessage(DebuggerBundle.message("error.corrupt.debug.info", e.getMessage()));
//myChildren.add(
// myNodeManager.createMessageNode(new MessageDescriptor(DebuggerBundle.message("error.corrupt.debug.info", e.getMessage()))));
} else {
throw e;
}
}
}
use of com.intellij.debugger.engine.evaluation.EvaluationContextImpl in project intellij-community by JetBrains.
the class DebuggerContextImpl method createEvaluationContext.
@Nullable
public EvaluationContextImpl createEvaluationContext() {
DebuggerManagerThreadImpl.assertIsManagerThread();
StackFrameProxyImpl frameProxy = getFrameProxy();
ObjectReference objectReference;
try {
objectReference = frameProxy != null ? frameProxy.thisObject() : null;
} catch (EvaluateException e) {
LOG.info(e);
objectReference = null;
}
SuspendContextImpl context = getSuspendContext();
return context != null ? new EvaluationContextImpl(context, frameProxy, objectReference) : null;
}
use of com.intellij.debugger.engine.evaluation.EvaluationContextImpl in project intellij-community by JetBrains.
the class ValueDescriptorImpl method setValueLabel.
@Override
public void setValueLabel(@NotNull String label) {
label = myFullValue ? label : DebuggerUtilsEx.truncateString(label);
Value value = myValueReady ? getValue() : null;
NodeRendererImpl lastRenderer = (NodeRendererImpl) getLastRenderer();
EvaluationContextImpl evalContext = myStoredEvaluationContext;
String labelId = myValueReady && evalContext != null && lastRenderer != null && !evalContext.getSuspendContext().isResumed() ? lastRenderer.getIdLabel(value, evalContext.getDebugProcess()) : null;
myValueText = label;
myIdLabel = isShowIdLabel() ? labelId : null;
}
use of com.intellij.debugger.engine.evaluation.EvaluationContextImpl in project intellij-community by JetBrains.
the class EvaluationDescriptor method calcValue.
public final Value calcValue(EvaluationContextImpl evaluationContext) throws EvaluateException {
try {
PsiDocumentManager.getInstance(myProject).commitAndRunReadAction(() -> {
});
EvaluationContextImpl thisEvaluationContext = getEvaluationContext(evaluationContext);
SourcePosition position = ContextUtil.getSourcePosition(evaluationContext);
PsiElement psiContext = ContextUtil.getContextElement(evaluationContext, position);
ExpressionEvaluator evaluator = ReadAction.compute(() -> {
PsiCodeFragment code = getEvaluationCode(thisEvaluationContext);
try {
return DebuggerUtilsEx.findAppropriateCodeFragmentFactory(getEvaluationText(), psiContext).getEvaluatorBuilder().build(code, position);
} catch (UnsupportedExpressionException ex) {
ExpressionEvaluator eval = CompilingEvaluatorImpl.create(myProject, code.getContext(), element -> code);
if (eval != null) {
return eval;
}
throw ex;
}
});
if (!thisEvaluationContext.getDebugProcess().isAttached()) {
throw EvaluateExceptionUtil.PROCESS_EXITED;
}
StackFrameProxyImpl frameProxy = thisEvaluationContext.getFrameProxy();
if (frameProxy == null) {
throw EvaluateExceptionUtil.NULL_STACK_FRAME;
}
Value value = evaluator.evaluate(thisEvaluationContext);
DebuggerUtilsEx.keep(value, thisEvaluationContext);
myModifier = evaluator.getModifier();
setLvalue(myModifier != null);
return value;
} catch (final EvaluateException ex) {
throw new EvaluateException(ex.getLocalizedMessage(), ex);
} catch (ObjectCollectedException ex) {
throw EvaluateExceptionUtil.OBJECT_WAS_COLLECTED;
}
}
use of com.intellij.debugger.engine.evaluation.EvaluationContextImpl in project intellij-community by JetBrains.
the class EvaluationDescriptor method getModifier.
@Override
public XValueModifier getModifier(JavaValue value) {
return new JavaValueModifier(value) {
@Override
protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
final EvaluationDescriptor evaluationDescriptor = EvaluationDescriptor.this;
if (evaluationDescriptor.canSetValue()) {
final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
set(expression, callback, debuggerContext, new SetValueRunnable() {
public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException {
final Modifier modifier = evaluationDescriptor.getModifier();
modifier.setValue(preprocessValue(evaluationContext, newValue, modifier.getExpectedType()));
update(debuggerContext);
}
public ReferenceType loadClass(EvaluationContextImpl evaluationContext, String className) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException, EvaluateException {
return evaluationContext.getDebugProcess().loadClass(evaluationContext, className, evaluationContext.getClassLoader());
}
});
}
}
};
}
Aggregations