Beispiel #1
0
  public void exceptionEvent(ExceptionEvent event) {
    ObjectReference or = event.exception();
    ReferenceType rt = or.referenceType();
    String exceptionName = rt.name();
    // Field messageField = Throwable.class.getField("detailMessage");
    Field messageField = rt.fieldByName("detailMessage");
    //    System.out.println("field " + messageField);
    Value messageValue = or.getValue(messageField);
    //    System.out.println("mess val " + messageValue);

    // "java.lang.ArrayIndexOutOfBoundsException"
    int last = exceptionName.lastIndexOf('.');
    String message = exceptionName.substring(last + 1);
    if (messageValue != null) {
      String messageStr = messageValue.toString();
      if (messageStr.startsWith("\"")) {
        messageStr = messageStr.substring(1, messageStr.length() - 1);
      }
      message += ": " + messageStr;
    }
    //    System.out.println("mess type " + messageValue.type());
    // StringReference messageReference = (StringReference) messageValue.type();

    // First just report the exception and its placement
    reportException(message, or, event.thread());
    // Then try to pretty it up with a better message
    handleCommonErrors(exceptionName, message, listener);

    if (editor != null) {
      editor.deactivateRun();
    }
  }
 /**
  * Check the type and the vm of the given value. In case of primitive value, the value is
  * converted if needed.
  *
  * @return the (converted) value.
  * @throws InvalidTypeException if the given value is no assignment compatible with the given
  *     type.
  * @see checkPrimitiveValue(PrimitiveValueImpl, PrimitiveTypeImpl, PrimitiveTypeImpl)
  */
 public static ValueImpl checkValue(Value value, Type type, VirtualMachineImpl vm)
     throws InvalidTypeException {
   if (value == null) {
     if (!(type instanceof PrimitiveType)) {
       return null;
     }
   } else {
     vm.checkVM(value);
     TypeImpl valueType = (TypeImpl) value.type();
     if (valueType instanceof PrimitiveType && type instanceof PrimitiveType) {
       return checkPrimitiveValue(
           (PrimitiveValueImpl) value, (PrimitiveTypeImpl) valueType, (PrimitiveTypeImpl) type);
     }
     if (valueType instanceof ReferenceType && type instanceof ReferenceType) {
       checkReferenceType((ReferenceType) valueType, (ReferenceType) type);
       return (ValueImpl) value;
     }
     if (valueType instanceof VoidType && type instanceof VoidType) {
       return (VoidValueImpl) value;
     }
   }
   throw new InvalidTypeException(
       MessageFormat.format(
           JDIMessages.ValueImpl_Type_of_the_value_not_compatible_with_the_expected_type__1,
           new Object[] {
             value != null ? value.type().name() : "null", type.name()
           })); //$NON-NLS-1$
 }
 private void printVar(OutputSink out, LocalVariable var, StackFrame frame) {
   out.print("  " + var.name());
   if (var.isVisible(frame)) {
     Value val = frame.getValue(var);
     out.println(" = " + val.toString());
   } else {
     out.println(" is not in scope");
   }
 }
  private static SourcePosition calcPosition(
      final ValueDescriptor descriptor, final DebugProcessImpl debugProcess)
      throws ClassNotLoadedException {
    final Value value = descriptor.getValue();
    if (value == null) {
      return null;
    }

    Type type = value.type();
    if (type == null) {
      return null;
    }

    try {
      if (type instanceof ArrayType) {
        type = ((ArrayType) type).componentType();
      }
      if (type instanceof ClassType) {
        final ClassType clsType = (ClassType) type;
        final List<Location> locations = clsType.allLineLocations();
        if (locations.size() > 0) {
          final Location location = locations.get(0);
          return ApplicationManager.getApplication()
              .runReadAction(
                  new Computable<SourcePosition>() {
                    @Override
                    public SourcePosition compute() {
                      SourcePosition position =
                          debugProcess.getPositionManager().getSourcePosition(location);
                      // adjust position for non-anonymous classes
                      if (clsType.name().indexOf('$') < 0) {
                        final PsiClass classAt =
                            position != null ? JVMNameUtil.getClassAt(position) : null;
                        if (classAt != null) {
                          final SourcePosition classPosition =
                              SourcePosition.createFromElement(classAt);
                          if (classPosition != null) {
                            position = classPosition;
                          }
                        }
                      }
                      return position;
                    }
                  });
        }
      }
    } catch (ClassNotPreparedException e) {
      LOG.debug(e);
    } catch (AbsentInformationException e) {
      LOG.debug(e);
    }
    return null;
  }
 public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
   final Value result = (Value) myOperand.evaluate(context);
   if (result == null) {
     throw new EvaluateException("java.lang.NullPointerException: cannot unbox null value");
   }
   if (result instanceof ObjectReference) {
     final String valueTypeName = result.type().name();
     final Pair<String, String> pair = TYPES_TO_CONVERSION_METHOD_MAP.get(valueTypeName);
     if (pair != null) {
       return convertToPrimitive(
           context, (ObjectReference) result, pair.getFirst(), pair.getSecond());
     }
   }
   return result;
 }
Beispiel #6
0
 @Override
 public String getTypeName() {
   if (value == null) {
     return "null";
   }
   return value.type().name();
 }
 private void commandPrint(StringTokenizer t, boolean dumpObject) throws NoSessionException {
   if (!t.hasMoreTokens()) {
     // ### Probably confused if expresion contains whitespace.
     env.error("No expression specified.");
     return;
   }
   ThreadReference current = context.getCurrentThread();
   if (current == null) {
     env.failure("No default thread specified: " + "use the \"thread\" command first.");
     return;
   }
   StackFrame frame;
   try {
     frame = context.getCurrentFrame(current);
     if (frame == null) {
       env.failure("Thread has not yet created any stack frames.");
       return;
     }
   } catch (VMNotInterruptedException e) {
     env.failure("Target VM must be in interrupted state.");
     return;
   }
   while (t.hasMoreTokens()) {
     String expr = t.nextToken("");
     Value val = null;
     try {
       val = runtime.evaluate(frame, expr);
     } catch (Exception e) {
       env.error("Exception: " + e);
       // ### Fix this!
     }
     if (val == null) {
       return; // Error message already printed
     }
     OutputSink out = env.getOutputSink();
     if (dumpObject && (val instanceof ObjectReference) && !(val instanceof StringReference)) {
       ObjectReference obj = (ObjectReference) val;
       ReferenceType refType = obj.referenceType();
       out.println(expr + " = " + val.toString() + " {");
       dump(out, obj, refType, refType);
       out.println("}");
     } else {
       out.println(expr + " = " + val.toString());
     }
     out.show();
   }
 }
Beispiel #8
0
 public static boolean valuesEqual(Value val1, Value val2) {
   if (val1 == null) {
     return val2 == null;
   }
   if (val2 == null) {
     return false;
   }
   if (val1 instanceof StringReference && val2 instanceof StringReference) {
     return ((StringReference) val1).value().equals(((StringReference) val2).value());
   }
   return val1.equals(val2);
 }
Beispiel #9
0
  @SuppressWarnings({"HardCodedStringLiteral"})
  public static boolean isCharOrIntegerArray(Value value) {
    if (value == null) return false;
    if (myCharOrIntegers == null) {
      myCharOrIntegers = new HashSet<String>();
      myCharOrIntegers.add("C");
      myCharOrIntegers.add("B");
      myCharOrIntegers.add("S");
      myCharOrIntegers.add("I");
      myCharOrIntegers.add("J");
    }

    String signature = value.type().signature();
    int i;
    for (i = 0; signature.charAt(i) == '['; i++) ;
    if (i == 0) return false;
    signature = signature.substring(i, signature.length());
    return myCharOrIntegers.contains(signature);
  }
Beispiel #10
0
 @Override
 public String evaluate(String expression) throws DebuggerException {
   com.sun.jdi.Value result = evaluate(ExpressionParser.newInstance(expression));
   return result == null ? "null" : result.toString();
 }
  @Nullable
  public static BufferedImage getBitmap(EvaluationContextImpl evaluationContext, Value bitmap)
      throws EvaluateException {
    // retrieve the bitmap from bitmap drawables
    String fqcn = bitmap.type().name();
    if (BitmapDrawableRenderer.BITMAP_DRAWABLE_FQCN.equals(fqcn)) {
      bitmap = getBitmapFromDrawable(evaluationContext, (ObjectReference) bitmap);
      if (bitmap == null) {
        throw new RuntimeException("Unable to obtain bitmap from drawable");
      }
    }

    String config = getBitmapConfigName((ObjectReference) bitmap, evaluationContext);
    if (!"\"ARGB_8888\"".equals(config)) {
      throw new RuntimeException("Unsupported bitmap configuration: " + config);
    }

    Dimension size = getDimension(evaluationContext, bitmap);
    if (size == null) {
      throw new RuntimeException("Unable to determine image dimensions.");
    }

    // if the image is rather large, then scale it down
    if (size.width > MAX_DIMENSION || size.height > MAX_DIMENSION) {
      LOG.debug("Scaling down bitmap");
      bitmap = createScaledBitmap(evaluationContext, (ObjectReference) bitmap, size);
      if (bitmap == null) {
        throw new RuntimeException("Unable to create scaled bitmap");
      }

      size = getDimension(evaluationContext, bitmap);
      if (size == null) {
        throw new RuntimeException("Unable to obtained scaled bitmap's dimensions");
      }
    }

    List<Value> pixelValues;

    Field bufferField = ((ObjectReference) bitmap).referenceType().fieldByName("mBuffer");
    if (bufferField != null) {
      // if the buffer field is available, we can directly copy over the values
      Value bufferValue = ((ObjectReference) bitmap).getValue(bufferField);
      if (!(bufferValue instanceof ArrayReference)) {
        throw new RuntimeException("Image Buffer is not an array");
      }
      pixelValues = ((ArrayReference) bufferValue).getValues();
    } else {
      // if there is no buffer field (on older platforms that store data on native heap), then
      // resort to creating a new buffer,
      // and invoking copyPixelsToBuffer to copy the pixel data into the newly created buffer
      pixelValues = copyToBuffer(evaluationContext, (ObjectReference) bitmap, size);
      if (pixelValues == null) {
        throw new RuntimeException("Unable to extract image data: Bitmap has no buffer field.");
      }
    }

    byte[] argb = new byte[pixelValues.size()];
    for (int i = 0; i < pixelValues.size(); i++) {
      Value pixelValue = pixelValues.get(i);
      if (pixelValue instanceof ByteValue) {
        argb[i] = ((ByteValue) pixelValue).byteValue();
      }
    }

    return createBufferedImage(size.width, size.height, argb);
  }