1

I want to use btrace to inspect the byte[] value of a method return use the @Return annotation.

The byte array is actually a normal string encoded using utf8.

The class is like below:

Class A {
  byte[] method1() {
    ...
  }
}

I have tried printArray, but it only accepts type of Objetc[], not working for type of byte[]. For print, it just outputs the internal object id like '[B@4fbc7b65'.

Is there any other way can solve the problem?

cainanyang
  • 179
  • 1
  • 1
  • 6

1 Answers1

1

Yes, this is an omission in BTrace (https://github.com/btraceio/btrace/issues/322)

For now, use "trusted" mode where the safety checks will be turned off and you can do eg.

@BTrace(trusted = true)
public class TrustedTrace {
  @OnMethod(clazz = "MyClass", method = "m", location = Location(Kind.RETURN))
  public static void intercept(@Return byte[] data) {
    println(Arrays.toString(data));
  }
}
sel-fish
  • 4,308
  • 2
  • 20
  • 39
JB-
  • 2,615
  • 18
  • 17
  • Does "trusted" mode means we can invoke any static method to the object? – cainanyang Mar 23 '18 at 00:19
  • It means that all the protections are turned off and you can do whatever is possible in JVM. If a field/method is visible you can read/modify/execute it. – JB- Mar 26 '18 at 19:01