如何使用GDB跟踪已编译的JDK9 Hotspot?

时间:2017-06-12 04:24:34

标签: java c++ jvm openjdk java-9

有些人使用NetBeans来跟踪和调试JDK9。但是,我必须使用GDB来跟踪源代码并查看JDK / Hotspot代码的控制流,因为我使用ssh来访问服务器上的源代码,而我无法使用GUI / IDE。

我从JDK官方文档中按照Buildme.md配置JDK9,

bash ./configure --with-debug-level=slowdebug --with-target-bits=64 --disable-warnings-as-errors

然后,

make all

我获得了自定义的debug版本:

/images/jdk/bin/java -version
openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-adhoc.xfwu.9dev)
OpenJDK 64-Bit Server VM (build 9-internal+0-adhoc.xfwu.9dev, mixed mode)

在目录中:9jdk/hotspot

.
├── make
│   ├── copy
│   ├── gensrc
│   ├── ide
│   ├── lib
│   ├── mapfiles
│   │   ├── libjsig
│   │   ├── libjvm_db
│   │   ├── libjvm_dtrace
│   │   └── libsaproc
│   ├── src
│   │   └── classes
│   ├── symbols
│   └── test
├── src
│   ├── cpu
│   │   ├── aarch64
│   │   ├── arm
│   │   ├── ppc
│   │   ├── s390
│   │   ├── sparc
│   │   ├── x86
│   │   └── zero
│   ├── jdk.aot
│   │   ├── share
│   │   └── unix
│   ├── jdk.hotspot.agent
│   │   ├── doc
│   │   ├── linux
│   │   ├── macosx
│   │   ├── scripts
│   │   ├── share
│   │   ├── solaris
│   │   ├── test
│   │   └── windows
│   ├── jdk.internal.vm.ci
│   │   └── share
│   ├── jdk.internal.vm.compiler
│   │   └── share
│   ├── os
│   │   ├── aix
│   │   ├── bsd
│   │   ├── linux
│   │   ├── posix
│   │   ├── solaris
│   │   └── windows
│   ├── os_cpu
│   │   ├── aix_ppc
│   │   ├── bsd_x86
│   │   ├── bsd_zero
│   │   ├── linux_aarch64
│   │   ├── linux_arm
│   │   ├── linux_ppc
│   │   ├── linux_s390
│   │   ├── linux_sparc
│   │   ├── linux_x86
│   │   ├── linux_zero
│   │   ├── solaris_sparc
│   │   ├── solaris_x86
│   │   └── windows_x86
│   └── share
│       ├── tools
│       └── vm
└── test
    ├── compiler
    │   ├── aot
    │   ├── arguments
    │   ├── arraycopy
    │   ├── c1
    │   ├── c2
    │   ├── calls
    │   ├── ciReplay
    │   ├── classUnloading
    │   ├── codecache
    │   ├── codegen
    │   ├── compilercontrol
    │   ├── controldependency
    │   ├── cpuflags
    │   ├── debug
    │   ├── dependencies
    │   ├── eliminateAutobox
    │   ├── escapeAnalysis
    │   ├── exceptions
    │   ├── floatingpoint
    │   ├── gcbarriers
    │   ├── inlining
    │   ├── integerArithmetic
    │   ├── interpreter
    │   ├── intrinsics
    │   ├── jsr292
    │   ├── jvmci
    │   ├── linkage
    │   ├── loopopts
    │   ├── macronodes
    │   ├── membars
    │   ├── memoryinitialization
    │   ├── onSpinWait
    │   ├── oracle
    │   ├── osr
    │   ├── patches
    │   ├── print
    │   ├── profiling
    │   ├── rangechecks
    │   ├── reflection
    │   ├── regalloc
    │   ├── relocations
    │   ├── rtm
    │   ├── runtime
    │   ├── stable
    │   ├── startup
    │   ├── stringopts
    │   ├── testlibrary
    │   ├── tiered
    │   ├── types
    │   ├── uncommontrap
    │   ├── unsafe
    │   ├── vectorization
    │   └── whitebox
    ├── gc
    │   ├── arguments
    │   ├── class_unloading
    │   ├── cms
    │   ├── CondCardMark
    │   ├── ergonomics
    │   ├── g1
    │   ├── logging
    │   ├── metaspace
    │   ├── parallel
    │   ├── serial
    │   ├── startup_warnings
    │   ├── stress
    │   ├── survivorAlignment
    │   ├── testlibrary
    │   └── whitebox
    ├── native
    │   ├── classfile
    │   ├── code
    │   ├── gc
    │   ├── logging
    │   ├── memory
    │   ├── oops
    │   ├── runtime
    │   └── utilities
    ├── native_sanity
    ├── runtime
    │   ├── 6294277
    │   ├── 6626217
    │   ├── 6819213
    │   ├── 6981737
    │   ├── 7100935
    │   ├── 7116786
    │   ├── 7158988
    │   ├── 7160757
    │   ├── 7162488
    │   ├── 7167069
    │   ├── 8007320
    │   ├── 8007475
    │   ├── 8010389
    │   ├── 8024804
    │   ├── 8026365
    │   ├── 8026394
    │   ├── Annotations
    │   ├── BadObjectClass
    │   ├── BoolReturn
    │   ├── BootClassAppendProp
    │   ├── CDSCompressedKPtrs
    │   ├── ClassFile
    │   ├── classFileParserBug
    │   ├── ClassResolutionFail
    │   ├── ClassUnload
    │   ├── CommandLine
    │   ├── CompactStrings
    │   ├── CompressedOops
    │   ├── constantPool
    │   ├── ConstantPool
    │   ├── contended
    │   ├── defineAnonClass
    │   ├── duplAttributes
    │   ├── EnclosingMethodAttr
    │   ├── ErrorHandling
    │   ├── execstack
    │   ├── Final
    │   ├── finalStatic
    │   ├── getSysPackage
    │   ├── handlerInTry
    │   ├── InternalApi
    │   ├── interned
    │   ├── invokedynamic
    │   ├── jni
    │   ├── jsig
    │   ├── lambda-features
    │   ├── libadimalloc.solaris.sparc
    │   ├── LoadClass
    │   ├── LocalLong
    │   ├── LocalVariableTable
    │   ├── logging
    │   ├── memory
    │   ├── Metaspace
    │   ├── MinimalVM
    │   ├── MirrorFrame
    │   ├── modules
    │   ├── NMT
    │   ├── os
    │   ├── PerfMemDestroy
    │   ├── RedefineObject
    │   ├── RedefineTests
    │   ├── reflect
    │   ├── ReservedStack
    │   ├── Safepoint
    │   ├── SameObject
    │   ├── SelectionResolution
    │   ├── SharedArchiveFile
    │   ├── StackGuardPages
    │   ├── stackMapCheck
    │   ├── testlibrary
    │   ├── Thread
    │   ├── ThreadSignalMask
    │   ├── Throwable
    │   ├── TransitiveOverrideCFV50
    │   ├── Unsafe
    │   ├── verifier
    │   ├── whitebox
    │   └── XCheckJniJsig
    ├── sanity
    │   └── MismatchedWhiteBox
    ├── serviceability
    │   ├── 7170638
    │   ├── attach
    │   ├── dcmd
    │   ├── jdwp
    │   ├── jvmti
    │   ├── logging
    │   ├── sa
    │   ├── threads
    │   └── tmtools
    ├── testlibrary
    │   ├── ctw
    │   ├── jittester
    │   └── jvmti
    └── testlibrary_tests
        ├── ctw
        └── whitebox

我不知道如何使用GDB跟踪JDK9热点代码。

例如,如何跟踪一个简单的HelloWorld.java代码并浏览所有Hotspot代码。

public class HelloWorld {
   public static void main(String[] args) {
      // Prints "Hello, World" in the terminal window.
      System.out.println("Hello, World");
   }
}

我想学习基于STEP BY STEP方式的热点代码流程。

虽然我可以阅读static源代码并生成控制流图供我理解,但这对我来说还不够发展。

/9dev/jdk/test/sun/management/jmxremote/bootstrap/launcher.c

enter image description here

我知道基本的GDB命令

start
    start gcc 

list
    enter to show 10 more lines

step
    step into and go through

print [var]
    variable name
    p = print

next
    step over

x [var]
    addr: raw var
    examine abbr.

watch  [var]
rwatch
info watch
info break

cont
    continue until break point

break #line 

bt
    backtrace
frame #
    change context and subrounte and rounte

set var sum=23
    set a varible inside and change the variable instantly

quit
exit gdb

2 个答案:

答案 0 :(得分:1)

您可以使用gdbserver远程调试在gdb中运行调试会话 供参考:

注意:您需要运行两个单独的远程ssh会话实例,其中一个会话中您将运行gdbserver,而另一个会话中您将运行gdb客户端以调试JVM代码。

答案 1 :(得分:0)

配置并制作

配置参数

bash ./configure --with-target-bits=64 --with-debug-level=slowdebug --disable-warnings-as-errors --with-native-debug-symbols=internal

make clean

make all

版本

xfwu:~/sandboxJDK/9jdk/build/linux-x86_64-normal-server-slowdebug/jdk/bin$./java -version openjdk version "9-internal" OpenJDK Runtime Environment (slowdebug build 9-internal+0-adhoc.xfwu.9jdk) OpenJDK 64-Bit Server VM (slowdebug build 9-internal+0-adhoc.xfwu.9jdk, mixed mode)

GDB

xfwu:~/sandboxJDK/9jdk/build/linux-x86_64-normal-server-slowdebug/jdk/bin$gdb --args java ~/sanboxJDK/9jdk/javaPrj/HelloWorld

相关问题