use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.
the class DebuggerTree method buildNode.
private void buildNode(final DebuggerTreeNodeImpl node) {
if (node == null || node.getDescriptor() == null) {
return;
}
final DebugProcessImpl debugProcess = getDebuggerContext().getDebugProcess();
if (debugProcess != null) {
DebuggerCommandImpl command = getBuildNodeCommand(node);
if (command != null) {
node.add(myNodeManager.createMessageNode(MessageDescriptor.EVALUATING));
debugProcess.getManagerThread().schedule(command);
}
}
}
use of com.intellij.debugger.engine.DebugProcessImpl 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;
}
use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.
the class IconObjectRenderer method calcValueIcon.
@Override
public Icon calcValueIcon(final ValueDescriptor descriptor, final EvaluationContext evaluationContext, final DescriptorLabelListener listener) throws EvaluateException {
EvaluationContextImpl evalContext = ((EvaluationContextImpl) evaluationContext);
DebugProcessImpl debugProcess = evalContext.getDebugProcess();
if (!Registry.is("debugger.auto.fetch.icons") || DebuggerUtilsImpl.isRemote(debugProcess))
return null;
debugProcess.getManagerThread().schedule(new SuspendContextCommandImpl(evalContext.getSuspendContext()) {
@Override
public void contextAction() throws Exception {
String getterName = AllIcons.Debugger.Value.getIconHeight() <= 16 ? "iconToBytesPreviewNormal" : "iconToBytesPreviewRetina";
descriptor.setValueIcon(ImageObjectRenderer.getIcon(evaluationContext, descriptor.getValue(), getterName));
listener.labelChanged();
}
});
return null;
}
use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.
the class LocalVariableEvaluator method evaluate.
@Override
public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
StackFrameProxyImpl frameProxy = context.getFrameProxy();
if (frameProxy == null) {
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.no.stackframe"));
}
try {
ThreadReferenceProxyImpl threadProxy = null;
int lastFrameIndex = -1;
PsiVariable variable = null;
DebugProcessImpl process = context.getDebugProcess();
boolean topFrame = true;
while (true) {
try {
LocalVariableProxyImpl local = frameProxy.visibleVariableByName(myLocalVariableName);
if (local != null) {
if (topFrame || variable.equals(resolveVariable(frameProxy, myLocalVariableName, context.getProject(), process))) {
myEvaluatedVariable = local;
myContext = context;
return frameProxy.getValue(local);
}
}
} catch (EvaluateException e) {
if (!(e.getCause() instanceof AbsentInformationException)) {
throw e;
}
// try to look in slots
try {
Map<DecompiledLocalVariable, Value> vars = LocalVariablesUtil.fetchValues(frameProxy, process, true);
for (Map.Entry<DecompiledLocalVariable, Value> entry : vars.entrySet()) {
DecompiledLocalVariable var = entry.getKey();
if (var.getMatchedNames().contains(myLocalVariableName) || var.getDefaultName().equals(myLocalVariableName)) {
myEvaluatedDecompiledVariable = var;
myContext = context;
return entry.getValue();
}
}
} catch (Exception e1) {
LOG.info(e1);
}
}
if (myCanScanFrames) {
if (topFrame) {
variable = resolveVariable(frameProxy, myLocalVariableName, context.getProject(), process);
if (variable == null)
break;
}
if (threadProxy == null) /* initialize it lazily */
{
threadProxy = frameProxy.threadProxy();
lastFrameIndex = threadProxy.frameCount() - 1;
}
int currentFrameIndex = frameProxy.getFrameIndex();
if (currentFrameIndex < lastFrameIndex) {
frameProxy = threadProxy.frame(currentFrameIndex + 1);
if (frameProxy != null) {
topFrame = false;
continue;
}
}
}
break;
}
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.local.variable.missing", myLocalVariableName));
} catch (EvaluateException e) {
myEvaluatedVariable = null;
myContext = null;
throw e;
}
}
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);
}
}
Aggregations