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
Note: fbr is a use defined function in .gdbinit,Appendix gives definition
(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
(gdb) call desClz(0x70018318)
Class@[
type:Lorg/jikesrvm/jni/JNIEnvironment;
size(B):8
interfaces:
superclass:
Ljava/lang/Object;
fields:
JNIREFS_ARRAY_LENGTH:I
JNIREFS_FUDGE_LENGTH:I
JNIFunctions:Lorg/jikesrvm/jni/FunctionTable;
LinkageTriplets:Lorg/jikesrvm/jni/LinkageTripletTable;
externalJNIFunctions:Lorg/vmmagic/unboxed/Address;
savedTRreg:Lorg/jikesrvm/scheduler/RVMThread;
savedJTOC:Lorg/vmmagic/unboxed/Address;
...
methods:
<init>:()V
initializeState:()V
allocateEnvironment:()Lorg/jikesrvm/jni/JNIEnvironment;
deallocateEnvironment:(Lorg/jikesrvm/jni/JNIEnvironment;)V
hasNativeStackFrame:()Z
topJavaFP:()Lorg/vmmagic/unboxed/Address;
...
]
8.print method info
When extracting vmstack trace is necessary, users can print out method info:
Argument format is: (methodId&0x7fffffff | 0x80000000)<<32 | linenumber
SetDoubleField_14245.so,
Contents of the .debug_aranges section:
Length: 44
Version: 3
Offset into .debug_info: 0x0
Pointer Size: 8
Segment Size: 0
Address Length
00000000650ce418 00000000000001c1
0000000000000000 0000000000000000
(gdb) call desTyp(0x800037a80000012d)
CompiledMethod:
Compiler:BASELINE
Lorg/jikesrvm/jni/JNIFunctions;
SetDoubleField
(Lorg/jikesrvm/jni/JNIEnvironment;IID)V
Line Number:1996
9.print unicode string
Java unicode string can't be displayed by gdb directly, so users can use exported function print_uStr(addr,len)
(gdb) call desObj(0x704290a8)
Array@[
type:[C
length:83
slot(B):2
]
(gdb) call print_uStr(0x704290a8,83)
-Djava.home=/home/vondart/project/javaProject/mrp/dist/FullAdaptiveMSD_x86_64-linux
10.print primary array
Appendix
.gdbinit file
1 set disassembly-flavor intel
2 maint set dwarf2 always-disassemble
3 define fbr
4 echo fb addr\n
5 x/x $rsi+0xa0
6 echo l0 addr\n
7 p/x $__+0x10+$arg0
8 end