use of com.intellij.debugger.engine.evaluation.EvaluateException in project intellij-community by JetBrains.
the class StackTraceElementObjectRenderer method getFullValueEvaluator.
@Nullable
@Override
public XFullValueEvaluator getFullValueEvaluator(final EvaluationContextImpl evaluationContext, final ValueDescriptorImpl valueDescriptor) {
return new JavaValue.JavaFullValueEvaluator(DebuggerBundle.message("message.node.navigate"), evaluationContext) {
@Override
public void evaluate(@NotNull XFullValueEvaluationCallback callback) {
Value value = valueDescriptor.getValue();
ClassType type = ((ClassType) value.type());
Method toString = type.concreteMethodByName("toString", "()Ljava/lang/String;");
if (toString != null) {
try {
Value res = evaluationContext.getDebugProcess().invokeMethod(evaluationContext, (ObjectReference) value, toString, Collections.emptyList());
if (res instanceof StringReference) {
callback.evaluated("");
final String line = ((StringReference) res).value();
ApplicationManager.getApplication().runReadAction(() -> {
ExceptionFilter filter = new ExceptionFilter(evaluationContext.getDebugProcess().getSession().getSearchScope());
Filter.Result result = filter.applyFilter(line, line.length());
if (result != null) {
final HyperlinkInfo info = result.getFirstHyperlinkInfo();
if (info != null) {
DebuggerUIUtil.invokeLater(() -> info.navigate(valueDescriptor.getProject()));
}
}
});
}
} catch (EvaluateException e) {
LOG.info("Exception while getting stack info", e);
}
}
}
@Override
public boolean isShowValuePopup() {
return false;
}
};
}
use of com.intellij.debugger.engine.evaluation.EvaluateException in project intellij-community by JetBrains.
the class ToStringRenderer method calcLabel.
@Override
public String calcLabel(final ValueDescriptor valueDescriptor, EvaluationContext evaluationContext, final DescriptorLabelListener labelListener) throws EvaluateException {
final Value value = valueDescriptor.getValue();
BatchEvaluator.getBatchEvaluator(evaluationContext.getDebugProcess()).invoke(new ToStringCommand(evaluationContext, value) {
@Override
public void evaluationResult(String message) {
valueDescriptor.setValueLabel(StringUtil.notNullize(message));
labelListener.labelChanged();
}
@Override
public void evaluationError(String message) {
final String msg = value != null ? message + " " + DebuggerBundle.message("evaluation.error.cannot.evaluate.tostring", value.type().name()) : message;
valueDescriptor.setValueLabelFailed(new EvaluateException(msg, null));
labelListener.labelChanged();
}
});
return XDebuggerUIConstants.COLLECTING_DATA_MESSAGE;
}
use of com.intellij.debugger.engine.evaluation.EvaluateException in project smali by JesusFreke.
the class LazyValue method getNullableValue.
@Nullable
protected T getNullableValue(boolean allowNull) {
if (value == null) {
try {
if (evaluationContext == null) {
final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(project).getContext();
evaluationContext = debuggerContext.createEvaluationContext();
if (evaluationContext == null) {
if (!allowNull) {
throw new IllegalStateException("Can't create evaluation context");
}
return null;
}
}
value = SmaliCodeFragmentFactory.evaluateRegister(evaluationContext, method, registerNumber, type);
evaluationContext = null;
} catch (EvaluateException ex) {
if (!allowNull) {
throw new IllegalStateException(ex);
}
return null;
}
}
return (T) value;
}
use of com.intellij.debugger.engine.evaluation.EvaluateException in project android by JetBrains.
the class BitmapEvaluatorProvider method getBitmapFromDrawable.
@Nullable
private Value getBitmapFromDrawable(@NotNull ObjectReference bitmapDrawable) {
try {
DebugProcessImpl debugProcess = myEvaluationContext.getDebugProcess();
Method getBitmapMethod = DebuggerUtils.findMethod(bitmapDrawable.referenceType(), "getBitmap", "()Landroid/graphics/Bitmap;");
if (getBitmapMethod == null) {
return null;
}
return debugProcess.invokeMethod(myEvaluationContext, bitmapDrawable, getBitmapMethod, Collections.emptyList());
} catch (EvaluateException ignored) {
return null;
}
}
use of com.intellij.debugger.engine.evaluation.EvaluateException in project android by JetBrains.
the class DynamicResourceIdResolver method getAndroidResourceName.
@Nullable
@Override
public String getAndroidResourceName(int resId) {
String id = myDelegate.getAndroidResourceName(resId);
if (id != null) {
return id;
}
DebugProcess debugProcess = myContext.getDebugProcess();
VirtualMachineProxyImpl vmProxy = (VirtualMachineProxyImpl) debugProcess.getVirtualMachineProxy();
List<ReferenceType> classes = vmProxy.classesByName(CLASS_RESOURCES);
if (classes.isEmpty()) {
LOG.warn(CLASS_RESOURCES + " class not loaded?");
return null;
}
if (classes.size() != 1) {
LOG.warn("Expected a single Resource class loaded, but found " + classes.size());
}
ReferenceType resourcesClassType = classes.get(0);
Method getResourceNameMethod = DebuggerUtils.findMethod(resourcesClassType, "getResourceName", "(I)Ljava/lang/String;");
if (getResourceNameMethod == null) {
LOG.warn("Unable to locate getResourceName(int id) in class " + resourcesClassType.name());
return null;
}
List<ObjectReference> instances = resourcesClassType.instances(10);
if (instances.isEmpty()) {
LOG.warn("No instances of Resource class found");
return null;
}
List args = Collections.singletonList(DebuggerUtilsEx.createValue(vmProxy, "int", resId));
for (ObjectReference ref : instances) {
try {
Value value = debugProcess.invokeMethod(myContext, ref, getResourceNameMethod, args);
if (value instanceof StringReference) {
StringReference nameRef = (StringReference) value;
return nameRef.value();
}
} catch (EvaluateException e) {
ObjectReference exception = e.getExceptionFromTargetVM();
// do not log Resources$NotFoundException
if (exception == null || !DebuggerUtils.instanceOf(exception.type(), "android.content.res.Resources$NotFoundException")) {
LOG.warn("Unexpected error while invoking Resources.getResourceName()", e);
// continue and try this on other object references
}
}
}
return null;
}
Aggregations