Menu

How to use the low level debugger interface

Usage of low level debugger interface

1.choose target method

A sample use of the debugger:

  • use bootclasspath to load elf4j.jar during boot
  • set "gdb.elf.provider" to provider implementation
  • set "provider.tmp.dir" to tmp dir
  • set "methods.to.register" to target methods, use "package.class.method.signature" format to describe target methods. Better to use fuzzy matching, add "." to distinguish between methods with similar prefix or suffix. Don't register too much methods at a time, ulimit does not allow too many open files. If intermediate method in the call chain is not registered, the stack unwinding doesn't work properly.

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.TestSerialization

2.set break points

Break points can be set at absolute address or line number within file.

br *0x00007fffd3af93ec
br DataInputStream.java:176

If the first way is used, users must break at sysStartMainThread first. After program stops at the first break point, 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 shows assembly code with line number.

5.step/next

Step or stepi goes 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 user defined function in .gdbinit, Appendix gives its 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:
          Lorg/jikesrvm/architecture/SizeConstants;
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;
....
methods:
  <init>:()V
  initializeState:()V
  allocateEnvironment:()Lorg/jikesrvm/jni/JNIEnvironment;
  deallocateEnvironment:(Lorg/jikesrvm/jni/JNIEnvironment;)V
  hasNativeStackFrame:()Z
  topJavaFP:()Lorg/vmmagic/unboxed/Address;
  refsArray:()Lorg/vmmagic/unboxed/AddressArray;
  refsTop:()I
  savedRefsFP:()I
....
]

8.print method info
org.jikesrvm.runtime.StackTrace contains int[] compiledMethods and int[] instructionOffsets.
If extracting vmstack trace is necessary, users can print out method info:

Argument format is: (methodId&0x7fffffff | 0x80000000)<<32 | mcOff
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
Examine a field of RVMThread obtained from desObj(addr)

sloppyExecStatusHistogram:[I
value:<0x0000000063856478>

(gdb) call desObj(0x0000000063856478)
Array@[
   type:[I
 length:8
slot(B):4
]
(gdb) call print_primitive(0x0000000063856478,'I',8)
b,1d2d46,1e16,1c8422,12c,393,13c,0,

Appendix

.gdbinit file

        set disassembly-flavor intel
        maint set dwarf2 always-disassemble
        define fbr
        echo fb addr\n
        x/x $rsi+0xa0
        echo l0 addr\n
        p/x $__+0x10+$arg0
        end
        define afi
        x/xg $arg0
        while $__ !=-2
        echo cmid/ret/fp\n
        set var $tmp=$__
        x/xg $tmp-0x8
        x/xg $tmp+0x8
        x/xg $tmp
        end
        end
Posted by Da Feng 2011-10-29 Labels: how to

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.