c++ - 如何使用GDB跟踪编译后的JDK9 Hotspot?

标签 c++ jvm java java-9

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

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

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

然后,

全部制作

我获得了自定义的调试版本:

/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 Hotspot代码。

例如如何跟踪一个简单的 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方式的Hotspot代码流程。

虽然我可以阅读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

最佳答案

您可以使用 gdbserver 远程调试在 gdb 中运行调试 session 。
供引用:

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

关于c++ - 如何使用GDB跟踪编译后的JDK9 Hotspot?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44491385/

相关文章:

java - 为什么会跳过 for 循环?

Java 子字符串

java - 使用 Jsoup/Selenium 从网站获取 "::before"标签后的数字数据

c++ - 图像c++,opencv中均匀性/同质性的测量

c++ - 将参数传递给 constexpr 函数

c++ - 为游戏数据流量添加 SSL 加密是否值得?

java - 与 JComboBox 相关的问题

C++ 通过类传递参数?

java - JVM 在何处保存有关引用和对象类型的信息

java - 无法在消费者线程中使用 JNI 的生产者消费者程序中捕获 SIGINT 信号