1.choose target method
A sample use of the debugger:
Example:
rvm -gdb -Xms180m -Xmx360m -Xbootclasspath/a:elf4j.jar -Dgdb.elf.provider=net.sourceforge.elf4j.providers.MRPProvider -Dprovider.tmp.dir=/tmp/rvm/ -Dmethods.to.register="org.jikesrvm.classloader.TableBasedDynamicLinker.,org.jikesrvm.runtime.DynamicLinker.,.JNIFunctions.,.ObjectInputStream.,.TestSerialization.,.ObjectAccessor." -cp . test.org.jikesrvm.basic.core.serialization.TestSerializatio
2.set break points
Break points can be set at absolute address or line number within file.
If the first way is used, users must break at sysStartMainThread first, then set the absolute break point, since before that, the image isn't loaded yet.
If the second way is used, method containing the line must be specified as one of the targets.
3.display stack, frame info
info frame, bt works fine.
Example
use bt:
(gdb) bt
#0 SetDoubleField(reference, primitive, primitive, primitive)void (Lorg/jikesrvm/jni/JNIEnvironment;=@0x8, I=@0x9dd3, I=@0x9dd3,
D=@0x4018000000000000) at JNIFunctions.java:1992
#1 0x00007fffd3af93ec in Java_org_apache_harmony_misc_accessors_ObjectAccessor_setDouble (env=0x70018310, accessorObj=0x8, obj=0x10,
fieldID=40403, value=6) at ../shared/org_apache_harmony_misc_accessors_ObjectAccessorImpl.c:63
#2 0x0000000070c2dc7c in setDouble(reference, primitive, primitive)void (Ljava/lang/Object;=@0x71443968, J=@0x9dd3, D=@0x61f39418)
#3 0x0000000064dee4ee in readFieldValues(reference, reference)void (Ljava/lang/Object;=@0x714439b8, Ljava/io/ObjectStreamClass;=@0x76b9b218)
at DataInputStream.java:176
#4 0x0000000064df3aa4 in defaultReadObject()void () at ObjectInputStream.java:524
#5 0x0000000064c784b3 in readObjectForClass(reference, reference)void (Ljava/lang/Object;=@0x64ded486,
Ljava/io/ObjectStreamClass;=@0x76b9b218) at ObjectInputStream.java:1497
#6 0x0000000064ded340 in readHierarchy(reference, reference)void (Ljava/lang/Object;=@0x71443bc8, Ljava/io/ObjectStreamClass;=@0x76b9b218)
at ObjectInputStream.java:1431
#7 0x0000000064c77d9e in readNewObject(primitive)reference (Z=@0x64df0cfb) at Allocator.java:73
#8 0x0000000064df110b in readNonPrimitiveContent(primitive)reference (Z=@0x71443cc8) at Allocator.java:73
#9 0x0000000064ceabc0 in readObject(primitive)reference (Z=@0x76a8bf28) at ObjectInputStream.java:2247
#10 0x0000000064de6349 in readObject()reference () at ObjectInputStream.java:2207
#11 0x0000000070c42520 in main(array)void ([Ljava/lang/String;=@0x75fe8f78) at TestSerialization.java:39
use i f:
(gdb) info frame
Stack level 0, frame at 0x71443810:
rip = 0x650ce4a4 in SetDoubleField(reference, primitive, primitive, primitive)void (JNIFunctions.java:1992); saved rip 0x7fffd3af93ec
called by frame at 0x71443850
source language java.
Arglist at 0x71443800, args: Lorg/jikesrvm/jni/JNIEnvironment;=@0x8, I=@0x9dd3, I=@0x9dd3, D=@0x4018000000000000
Locals at 0x71443800, Previous frame's sp is 0x71443810
Saved registers:
rbp at 0x714437e0, rip at 0x71443808
use info addr __local0:
GDB currently doesn't support complex dwarf expression well. ELF4j uses this sequence to define cfa: \"DW_OP_lit16; DW_OP_breg4: 160; DW_OP_deref; DW_OP_plus\", so GDB prints out below:
(gdb) info addr __local0
Symbol "__local0" is a complex DWARF expression:
1: DW_OP_fbreg 18446744073709551536
.
(gdb) p/d 18446744073709551536
$2 = -80
4.disassemble
disassemlbe/m $rip,+128 can show assembly code with line number.
5.step/next
Step or stepi can go through instructions one after another.
Using next requires register method as one of the targets to enable line number. Also add 'org.jikesrvm.classloader.TableBasedDynamicLinker.' and 'org.jikesrvm.runtime.DynamicLinker.' to target methods, to enable next command during dynamic resolution of call sites.
6.print object info
Example:
Obtain first local info
(gdb) fbr(-80)
fb addr
0x7000aab8: 0x71443800
l0 addr
$1 = 0x714437c0
(gdb) x/x 0x714437c0
0x714437c0: 0x704290a8
(gdb) call desObj(0x704290a8)
Array@[
type:[C
length:83
slot(B):2
]
7.print class info
8.print method info
9.print unicode string
10.print primary array
11..gdbinit file