コード例 #1
0
 @Override
 public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
   Object result =
       context.getSuspendContext().getDebugProcess().getVirtualMachineProxy().mirrorOfVoid();
   try {
     result = myBodyEvaluator.evaluate(context);
   } catch (EvaluateException e) {
     boolean catched = false;
     ObjectReference vmException = e.getExceptionFromTargetVM();
     if (vmException != null) {
       for (CatchEvaluator evaluator : myCatchBlockEvaluators) {
         if (evaluator != null
             && DebuggerUtils.instanceOf(vmException.type(), evaluator.getExceptionType())) {
           result = evaluator.evaluate(vmException, context);
           catched = true;
           break;
         }
       }
     }
     if (!catched) {
       throw e;
     }
   } finally {
     if (myFinallyEvaluator != null) {
       result = myFinallyEvaluator.evaluate(context);
     }
   }
   return result;
 }
コード例 #2
0
  protected boolean shouldDisplay(
      EvaluationContext context, @NotNull ObjectReference objInstance, @NotNull Field field) {
    final boolean isSynthetic = DebuggerUtils.isSynthetic(field);
    if (!SHOW_SYNTHETICS && isSynthetic) {
      return false;
    }
    if (SHOW_VAL_FIELDS_AS_LOCAL_VARIABLES && isSynthetic) {
      try {
        final StackFrameProxy frameProxy = context.getFrameProxy();
        if (frameProxy != null) {
          final Location location = frameProxy.location();
          if (location != null
              && objInstance.equals(context.getThisObject())
              && Comparing.equal(objInstance.referenceType(), location.declaringType())
              && StringUtil.startsWith(
                  field.name(), FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
            return false;
          }
        }
      } catch (EvaluateException ignored) {
      }
    }
    if (!SHOW_STATIC && field.isStatic()) {
      return false;
    }

    if (!SHOW_STATIC_FINAL && field.isStatic() && field.isFinal()) {
      return false;
    }

    return true;
  }
コード例 #3
0
  @Nullable
  private static Value createScaledBitmap(
      @NotNull EvaluationContextImpl context,
      @NotNull ObjectReference bitmap,
      @NotNull Dimension currentDimensions)
      throws EvaluateException {
    DebugProcessImpl debugProcess = context.getDebugProcess();
    Method createScaledBitmapMethod =
        DebuggerUtils.findMethod(
            bitmap.referenceType(),
            "createScaledBitmap",
            "(Landroid/graphics/Bitmap;IIZ)Landroid/graphics/Bitmap;");
    if (createScaledBitmapMethod == null) {
      return null;
    }

    double s =
        Math.max(currentDimensions.getHeight(), currentDimensions.getWidth()) / MAX_DIMENSION;

    VirtualMachineProxyImpl vm = context.getDebugProcess().getVirtualMachineProxy();
    Value dstWidth =
        DebuggerUtilsEx.createValue(vm, "int", (int) (currentDimensions.getWidth() / s));
    Value dstHeight =
        DebuggerUtilsEx.createValue(vm, "int", (int) (currentDimensions.getHeight() / s));
    Value filter = DebuggerUtilsEx.createValue(vm, "boolean", Boolean.FALSE);
    return debugProcess.invokeMethod(
        context,
        bitmap,
        createScaledBitmapMethod,
        Arrays.asList(bitmap, dstWidth, dstHeight, filter));
  }
コード例 #4
0
 public boolean isOuterLocalVariableValue() {
   try {
     return DebuggerUtils.isSynthetic(myField)
         && myField.name().startsWith(OUTER_LOCAL_VAR_FIELD_PREFIX);
   } catch (UnsupportedOperationException ignored) {
     return false;
   }
 }
コード例 #5
0
 public boolean isApplicable(Type type) {
   if (type == null
       || !(type instanceof ReferenceType)
       || !DebuggerUtils.instanceOf(type, getClassName())) {
     return false;
   }
   return super.isApplicable(type);
 }
コード例 #6
0
 @Override
 public boolean isPrimitive() {
   if (myIsPrimitive == null) {
     final Value value = getValue();
     if (value != null) {
       myIsPrimitive = super.isPrimitive();
     } else {
       myIsPrimitive = DebuggerUtils.isPrimitiveType(myField.typeName());
     }
   }
   return myIsPrimitive.booleanValue();
 }
コード例 #7
0
 @Nullable
 private static Value getBitmapConfig(EvaluationContextImpl context, ObjectReference bitmap)
     throws EvaluateException {
   DebugProcessImpl debugProcess = context.getDebugProcess();
   Method getConfig =
       DebuggerUtils.findMethod(
           bitmap.referenceType(), "getConfig", "()Landroid/graphics/Bitmap$Config;");
   if (getConfig == null) {
     return null;
   }
   return debugProcess.invokeMethod(context, bitmap, getConfig, Collections.emptyList());
 }
  @Override
  public Value calcValue(EvaluationContextImpl evaluationContext) throws EvaluateException {
    boolean isVisible = myFrameProxy.isLocalVariableVisible(getLocalVariable());
    if (isVisible) {
      final String typeName = getLocalVariable().typeName();
      myTypeName = typeName;
      myIsPrimitive = DebuggerUtils.isPrimitiveType(typeName);
      return myFrameProxy.getValue(getLocalVariable());
    }

    return null;
  }
コード例 #9
0
  @Nullable
  private static List<Value> copyToBuffer(
      EvaluationContextImpl evaluationContext, ObjectReference bitmap, Dimension size)
      throws EvaluateException {
    DebugProcessImpl debugProcess = evaluationContext.getDebugProcess();
    VirtualMachineProxyImpl virtualMachineProxy = debugProcess.getVirtualMachineProxy();

    List<ReferenceType> classes = virtualMachineProxy.classesByName("byte[]");
    if (classes.size() != 1 || !(classes.get(0) instanceof ArrayType)) {
      return null;
    }
    ArrayType byteArrayType = (ArrayType) classes.get(0);

    classes = virtualMachineProxy.classesByName("java.nio.ByteBuffer");
    if (classes.size() != 1 || !(classes.get(0) instanceof ClassType)) {
      return null;
    }
    ClassType byteBufferType = (ClassType) classes.get(0);
    Method wrapMethod =
        DebuggerUtils.findMethod(byteBufferType, "wrap", "([B)Ljava/nio/ByteBuffer;");
    if (wrapMethod == null) {
      return null;
    }

    ArrayReference byteArray = byteArrayType.newInstance(size.width * size.height * 4);
    Value byteBufferRef =
        debugProcess.invokeMethod(
            evaluationContext, byteBufferType, wrapMethod, ImmutableList.of(byteArray));

    Method copyToBufferMethod =
        DebuggerUtils.findMethod(
            bitmap.referenceType(), "copyPixelsToBuffer", "(Ljava/nio/Buffer;)V");
    if (copyToBufferMethod == null) {
      return null;
    }

    debugProcess.invokeMethod(
        evaluationContext, bitmap, copyToBufferMethod, ImmutableList.of(byteBufferRef));
    return byteArray.getValues();
  }
コード例 #10
0
  private void runAction(final EvaluationContextImpl context, LocatableEvent event) {
    if (LOG_ENABLED || LOG_EXPRESSION_ENABLED) {
      final StringBuilder buf = StringBuilderSpinAllocator.alloc();
      try {
        if (LOG_ENABLED) {
          buf.append(getEventMessage(event));
          buf.append("\n");
        }
        final DebugProcessImpl debugProcess = context.getDebugProcess();
        final TextWithImports expressionToEvaluate = getLogMessage();
        if (LOG_EXPRESSION_ENABLED
            && expressionToEvaluate != null
            && !"".equals(expressionToEvaluate.getText())) {
          if (!debugProcess.isAttached()) {
            return;
          }

          try {
            ExpressionEvaluator evaluator =
                DebuggerInvocationUtil.commitAndRunReadAction(
                    getProject(),
                    new EvaluatingComputable<ExpressionEvaluator>() {
                      public ExpressionEvaluator compute() throws EvaluateException {
                        return EvaluatorBuilderImpl.build(
                            expressionToEvaluate,
                            ContextUtil.getContextElement(context),
                            ContextUtil.getSourcePosition(context));
                      }
                    });
            final Value eval = evaluator.evaluate(context);
            final String result =
                eval instanceof VoidValue ? "void" : DebuggerUtils.getValueAsString(context, eval);
            buf.append(result);
          } catch (EvaluateException e) {
            buf.append(DebuggerBundle.message("error.unable.to.evaluate.expression"));
            buf.append(" \"");
            buf.append(expressionToEvaluate);
            buf.append("\"");
            buf.append(" : ");
            buf.append(e.getMessage());
          }
          buf.append("\n");
        }
        if (buf.length() > 0) {
          debugProcess.printToConsole(buf.toString());
        }
      } finally {
        StringBuilderSpinAllocator.dispose(buf);
      }
    }
  }
コード例 #11
0
  @Nullable
  private static Integer getImageDimension(
      EvaluationContextImpl context,
      ObjectReference bitmap,
      DebugProcessImpl debugProcess,
      String methodName)
      throws EvaluateException {
    Method method = DebuggerUtils.findMethod((bitmap).referenceType(), methodName, "()I");
    if (method != null) {
      Value widthValue =
          debugProcess.invokeMethod(context, bitmap, method, Collections.emptyList());
      if (widthValue instanceof IntegerValue) {
        return ((IntegerValue) widthValue).value();
      }
    }

    return null;
  }
コード例 #12
0
  @Override
  public PsiElement getChildValueExpression(DebuggerTreeNode node, DebuggerContext context)
      throws EvaluateException {
    FieldDescriptor fieldDescriptor = (FieldDescriptor) node.getDescriptor();

    PsiElementFactory elementFactory =
        JavaPsiFacade.getInstance(node.getProject()).getElementFactory();
    try {
      return elementFactory.createExpressionFromText(
          "this." + fieldDescriptor.getField().name(),
          DebuggerUtils.findClass(
              fieldDescriptor.getObject().referenceType().name(),
              context.getProject(),
              context.getDebugProcess().getSearchScope()));
    } catch (IncorrectOperationException e) {
      throw new EvaluateException(
          DebuggerBundle.message("error.invalid.field.name", fieldDescriptor.getField().name()),
          null);
    }
  }
コード例 #13
0
  @SuppressWarnings({"HardCodedStringLiteral"})
  public static RemoteConnection createDebugParameters(
      final JavaParameters parameters,
      final boolean debuggerInServerMode,
      int transport,
      final String debugPort,
      boolean checkValidity)
      throws ExecutionException {
    if (checkValidity) {
      checkTargetJPDAInstalled(parameters);
    }

    final boolean useSockets = transport == DebuggerSettings.SOCKET_TRANSPORT;

    String address = "";
    if (StringUtil.isEmptyOrSpaces(debugPort)) {
      try {
        address = DebuggerUtils.getInstance().findAvailableDebugAddress(useSockets);
      } catch (ExecutionException e) {
        if (checkValidity) {
          throw e;
        }
      }
    } else {
      address = debugPort;
    }

    final TransportServiceWrapper transportService =
        TransportServiceWrapper.getTransportService(useSockets);
    final String debugAddress =
        debuggerInServerMode && useSockets ? "127.0.0.1:" + address : address;
    String debuggeeRunProperties =
        "transport=" + transportService.transportId() + ",address=" + debugAddress;
    if (debuggerInServerMode) {
      debuggeeRunProperties += ",suspend=y,server=n";
    } else {
      debuggeeRunProperties += ",suspend=n,server=y";
    }

    if (hasWhitespace(debuggeeRunProperties)) {
      debuggeeRunProperties = "\"" + debuggeeRunProperties + "\"";
    }
    final String _debuggeeRunProperties = debuggeeRunProperties;

    ApplicationManager.getApplication()
        .runReadAction(
            new Runnable() {
              @Override
              @SuppressWarnings({"HardCodedStringLiteral"})
              public void run() {
                JavaSdkUtil.addRtJar(parameters.getClassPath());

                final Sdk jdk = parameters.getJdk();
                final boolean forceClassicVM = shouldForceClassicVM(jdk);
                final boolean forceNoJIT = shouldForceNoJIT(jdk);
                final String debugKey = System.getProperty(DEBUG_KEY_NAME, "-Xdebug");
                final boolean needDebugKey =
                    shouldAddXdebugKey(jdk)
                        || !"-Xdebug".equals(debugKey) /*the key is non-standard*/;

                if (forceClassicVM || forceNoJIT || needDebugKey || !isJVMTIAvailable(jdk)) {
                  parameters
                      .getVMParametersList()
                      .replaceOrPrepend("-Xrunjdwp:", "-Xrunjdwp:" + _debuggeeRunProperties);
                } else {
                  // use newer JVMTI if available
                  parameters.getVMParametersList().replaceOrPrepend("-Xrunjdwp:", "");
                  parameters
                      .getVMParametersList()
                      .replaceOrPrepend(
                          "-agentlib:jdwp=", "-agentlib:jdwp=" + _debuggeeRunProperties);
                }

                if (forceNoJIT) {
                  parameters
                      .getVMParametersList()
                      .replaceOrPrepend("-Djava.compiler=", "-Djava.compiler=NONE");
                  parameters.getVMParametersList().replaceOrPrepend("-Xnoagent", "-Xnoagent");
                }

                if (needDebugKey) {
                  parameters.getVMParametersList().replaceOrPrepend(debugKey, debugKey);
                } else {
                  // deliberately skip outdated parameter because it can disable full-speed
                  // debugging for some jdk builds
                  // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6272174
                  parameters.getVMParametersList().replaceOrPrepend("-Xdebug", "");
                }

                parameters
                    .getVMParametersList()
                    .replaceOrPrepend("-classic", forceClassicVM ? "-classic" : "");
              }
            });

    return new RemoteConnection(useSockets, "127.0.0.1", address, debuggerInServerMode);
  }
コード例 #14
0
  @Override
  public final boolean canPutAt(
      @NotNull final VirtualFile file, final int line, @NotNull Project project) {
    final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    // JSPX supports jvm debugging, but not in XHTML files
    if (psiFile == null || psiFile.getVirtualFile().getFileType() == StdFileTypes.XHTML) {
      return false;
    }

    if (!StdFileTypes.CLASS.equals(psiFile.getFileType())
        && !DebuggerUtils.isBreakpointAware(psiFile)) {
      return false;
    }

    final Document document = FileDocumentManager.getInstance().getDocument(file);
    final Ref<Class<? extends JavaLineBreakpointTypeBase>> result = Ref.create();
    XDebuggerUtil.getInstance()
        .iterateLine(
            project,
            document,
            line,
            new Processor<PsiElement>() {
              @Override
              public boolean process(PsiElement element) {
                // avoid comments
                if ((element instanceof PsiWhiteSpace)
                    || (PsiTreeUtil.getParentOfType(element, PsiComment.class, false) != null)) {
                  return true;
                }
                PsiElement parent = element;
                while (element != null) {
                  // skip modifiers
                  if (element instanceof PsiModifierList) {
                    element = element.getParent();
                    continue;
                  }

                  final int offset = element.getTextOffset();
                  if (offset >= 0) {
                    if (document.getLineNumber(offset) != line) {
                      break;
                    }
                  }
                  parent = element;
                  element = element.getParent();
                }

                if (parent instanceof PsiMethod) {
                  if (parent.getTextRange().getEndOffset() >= document.getLineEndOffset(line)) {
                    PsiCodeBlock body = ((PsiMethod) parent).getBody();
                    if (body != null) {
                      PsiStatement[] statements = body.getStatements();
                      if (statements.length > 0
                          && document.getLineNumber(statements[0].getTextOffset()) == line) {
                        result.set(JavaLineBreakpointType.class);
                      }
                    }
                  }
                  if (result.isNull()) {
                    result.set(JavaMethodBreakpointType.class);
                  }
                } else if (parent instanceof PsiField) {
                  if (result.isNull()) {
                    result.set(JavaFieldBreakpointType.class);
                  }
                } else {
                  result.set(JavaLineBreakpointType.class);
                }
                return true;
              }
            });
    return result.get() == getClass();
  }