How do I print a Java array in gdb?
Asked Answered
S

1

6

I compiled a very simple java program with gcj-4.4 and -o option. I loaded it in gdb-7.2 and tried to do some debugging. I noticed at I could print the variables in int type but I could not print an array of int. I received this error message:

(gdb) p orderFinish[0]
cannot find java.lang.Object
(gdb) p (int)orderFinish
$8 = -136261440
(gdb) p orderFinish[3]
cannot find java.lang.Object
(gdb) p in
$9 = 1
(gdb) whatis orderFinish 
type = int[]

So my question is how can I print a Java array in gdb? My OS is openSUSE-11.1 x64-86bit. Thanks!

Scipio answered 31/1, 2011 at 18:27 Comment(0)
S
1

p *array-variable@length should work.

Source: http://www.yolinux.com/TUTORIALS/GDB-Commands.html

Sconce answered 14/3, 2011 at 4:3 Comment(2)
Works fine for me, this is straight out of the doco "p *array-variable@length Print first # values of array specified by length. Good for pointers to dynamicaly allocated memory." You may need to set print array on before this works.Sconce
It looks as if in my case missing debuginfos were the culprit. After installing them, it seems to work.Diller

© 2022 - 2024 — McMap. All rights reserved.