iokevins
iokevins

Reputation: 1497

How do I print an array in Java's jdb debugger?

How do I print out the values of the byte array all at once? I seem to recall I could specify a memory range in gdb. Is similar functionality is available in jdb?

I have a Java byte array:

byte [] decompressed = new byte[OUTPUT_FILE_IO_BUFFER_SIZE];

which I populate from a String:

System.arraycopy(decompressedString.getBytes(), 0, decompressed, 0, 
                         decompressedString.length());

In jdb, I want to print the contents of the byte array. I tried

main[1] print decompressed

which returns:

 decompressed = instance of byte[7] (id=342)

Upvotes: 5

Views: 3090

Answers (2)

Yas Ikeda
Yas Ikeda

Reputation: 1096

It is a bit lengthy, but it can display all the elements in a line.

print java.util.Arrays.toString(decompressed)

Even if the array was a boxed-type array (like Byte[]), Arrays.asList could also provide the same. It is slightly shorter.

print java.util.Arrays.asList(decompressed)

Upvotes: 0

iokevins
iokevins

Reputation: 1497

One solution:

dump decompressed

This dumps the byte values! :)

Upvotes: 6

Related Questions