@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));
  }
  @Override
  public String getEventMessage(LocatableEvent event) {
    final Location location = event.location();
    String sourceName;
    try {
      sourceName = location.sourceName();
    } catch (AbsentInformationException e) {
      sourceName = getFileName();
    }

    final boolean printFullTrace = Registry.is("debugger.breakpoint.message.full.trace");

    StringBuilder builder = new StringBuilder();
    if (printFullTrace) {
      builder.append(
          DebuggerBundle.message(
              "status.line.breakpoint.reached.full.trace",
              DebuggerUtilsEx.getLocationMethodQName(location)));
      try {
        final List<StackFrame> frames = event.thread().frames();
        renderTrace(frames, builder);
      } catch (IncompatibleThreadStateException e) {
        builder.append("Stacktrace not available: ").append(e.getMessage());
      }
    } else {
      builder.append(
          DebuggerBundle.message(
              "status.line.breakpoint.reached",
              DebuggerUtilsEx.getLocationMethodQName(location),
              sourceName,
              getLineIndex() + 1));
    }
    return builder.toString();
  }
 public void keep(ObjectReference reference) {
   if (!Patches.IBM_JDK_DISABLE_COLLECTION_BUG) {
     final boolean added = myKeptReferences.add(reference);
     if (added) {
       DebuggerUtilsEx.disableCollection(reference);
     }
   }
 }
 public boolean isModified() {
   if (myRenderer == null) {
     return false;
   }
   final CompoundReferenceRenderer cloned = (CompoundReferenceRenderer) myRenderer.clone();
   flushDataTo(cloned);
   return !DebuggerUtilsEx.externalizableEqual(cloned, myOriginalRenderer);
 }
Example #5
0
  public final String renderTypeName(final String typeName) {
    if (SHOW_FQ_TYPE_NAMES) {
      return typeName;
    }
    String baseLambdaClassName = DebuggerUtilsEx.getLambdaBaseClassName(typeName);
    if (baseLambdaClassName != null) {
      return renderTypeName(baseLambdaClassName) + "$lambda";
    }

    final int dotIndex = typeName.lastIndexOf('.');
    if (dotIndex > 0) {
      return typeName.substring(dotIndex + 1);
    }
    return typeName;
  }
 public JavaStackFrame(@NotNull StackFrameDescriptorImpl descriptor, boolean update) {
   myDescriptor = descriptor;
   if (update) {
     myDescriptor.setContext(null);
     myDescriptor.updateRepresentation(null, DescriptorLabelListener.DUMMY_LISTENER);
   }
   myEqualityObject =
       update ? NodeManagerImpl.getContextKeyForFrame(myDescriptor.getFrameProxy()) : null;
   myDebugProcess = ((DebugProcessImpl) descriptor.getDebugProcess());
   myNodeManager = myDebugProcess.getXdebugProcess().getNodeManager();
   myXSourcePosition =
       myDescriptor.getSourcePosition() != null
           ? DebuggerUtilsEx.toXSourcePosition(myDescriptor.getSourcePosition())
           : null;
 }
  @Nullable
  private ExpressionEvaluator getExpressionEvaluator(DebuggerContextImpl debuggerContext)
      throws EvaluateException {
    if (myCurrentExpression instanceof PsiExpression) {
      return EvaluatorBuilderImpl.getInstance()
          .build(myCurrentExpression, debuggerContext.getSourcePosition());
    }

    CodeFragmentFactory factory =
        DebuggerUtilsEx.getEffectiveCodeFragmentFactory(myCurrentExpression);
    TextWithImportsImpl textWithImports =
        new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, myCurrentExpression.getText());
    if (factory == null) return null;
    JavaCodeFragment codeFragment =
        factory.createCodeFragment(textWithImports, myCurrentExpression.getContext(), getProject());
    codeFragment.forceResolveScope(GlobalSearchScope.allScope(getProject()));
    return factory.getEvaluatorBuilder().build(codeFragment, debuggerContext.getSourcePosition());
  }
  protected void resume() {
    assertNotResumed();
    DebuggerManagerThreadImpl.assertIsManagerThread();
    try {
      if (!Patches.IBM_JDK_DISABLE_COLLECTION_BUG) {
        for (ObjectReference objectReference : myKeptReferences) {
          DebuggerUtilsEx.enableCollection(objectReference);
        }
        myKeptReferences.clear();
      }

      for (SuspendContextCommandImpl cmd = pollPostponedCommand();
          cmd != null;
          cmd = pollPostponedCommand()) {
        cmd.notifyCancelled();
      }

      resumeImpl();
    } finally {
      myIsResumed = true;
    }
  }
  // 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) {
        ValueDescriptorImpl returnValueDescriptor =
            myNodeManager.getMethodReturnValueDescriptor(
                myDescriptor, methodValuePair.getFirst(), methodValuePair.getSecond());
        children.add(JavaValue.create(returnValueDescriptor, evaluationContext, myNodeManager));
      }
      // add context exceptions
      for (Pair<Breakpoint, Event> pair :
          DebuggerUtilsEx.getEventDescriptors(debuggerContext.getSuspendContext())) {
        final Event debugEvent = pair.getSecond();
        if (debugEvent instanceof ExceptionEvent) {
          final ObjectReference exception = ((ExceptionEvent) debugEvent).exception();
          if (exception != null) {
            final ValueDescriptorImpl exceptionDescriptor =
                myNodeManager.getThrownExceptionObjectDescriptor(myDescriptor, exception);
            children.add(JavaValue.create(exceptionDescriptor, 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;
      }
    }
  }