共计 3060 个字符,预计需要花费 8 分钟才能阅读完成。
废话不多说,开干!
原理是通过 Docker 编译 openjdk,而后联合 clion 通过 gdbserver 近程调试
环境需要
- Clion
- Docker
我测试的版本
Docker for windows : Docker version 20.10.2, build 2291f61
Clion : 2020.3.1
构建镜像
git clone https://e.coding.net/javalistcn/openjdk/build-openjdk-8.git
cd build-openjdk-8
docker build -t build-openjdk-8 .
运行
docker run -it --name build-openjdk-8 -p 1234:1234 build-openjdk-8
1234 端口用于 gdbserver 这个十分重要!!!
编译
进入到容器后执行
cd jdk-jdk8-b120/
# 删除 adjust-mflags.sh 的 67 行,不然编译会报错
sed -i '67d' hotspot/make/linux/makefiles/adjust-mflags.sh
bash ./configure --with-target-bits=64 --with-debug-level=slowdebug --enable-debug-symbols --with-boot-jdk=/openjdk/java-se-7u75-ri --with-freetype-include=/usr/include/freetype2/ --with-freetype-lib=/usr/lib/x86_64-linux-gnu ZIP_DEBUGINFO_FILES=0
失常输入
====================================================
A new configuration has been successfully created in
/openjdk/jdk-jdk8-b120/build/linux-x86_64-normal-server-slowdebug
using configure arguments '--with-target-bits=64 --with-debug-level=slowdebug --enable-debug-symbols --with-boot-jdk=/openjdk/java-se-7u75-ri --with-freetype-include=/usr/include/freetype2/ --with-freetype-lib=/usr/lib/x86_64-linux-gnu ZIP_DEBUGINFO_FILES=0'.
Configuration summary:
* Debug level: slowdebug
* JDK variant: normal
* JVM variants: server
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64
Tools summary:
* Boot JDK: openjdk version "1.7.0_75" OpenJDK Runtime Environment (build 1.7.0_75-b13) OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode) (at /openjdk/java-se-7u75-ri)
* C Compiler: gcc-5 (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 version 20160609 (at /usr/bin/gcc-5)
* C++ Compiler: g++-5 (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 version 20160609 (at /usr/bin/g++-5)
Build performance summary:
* Cores to use: 4
* Memory limit: 12698 MB
* ccache status: not installed (consider installing)
Build performance tip: ccache gives a tremendous speedup for C++ recompilations.
You do not have ccache installed. Try installing it.
You might be able to fix this by running 'sudo apt-get install ccache'.
make all DISABLE_HOTSPOT_OS_VERSION_CHECK=OK ZIP_DEBUGINFO_FILES=0
一杯咖啡工夫过后看到一下内容输入就功败垂成了。
----- Build times -------
Start 2021-01-15 00:57:13
End 2021-01-15 01:05:57
00:00:27 corba
00:00:14 demos
00:01:40 docs
00:02:15 hotspot
00:00:18 images
00:00:17 jaxp
00:00:20 jaxws
00:02:31 jdk
00:00:30 langtools
00:00:12 nashorn
00:08:44 TOTAL
-------------------------
Finished building OpenJDK for target 'all'
Clion 配置
把 jdk-jdk8-b120.tar.gz
解压,用 clion 关上我的项目(open -> 抉择 jdk-jdk8-b120 目录)
增加 GDB Remote Debug 配置如下图
进入容器,cd 到/openjdk/jdk-jdk8-b120/build/linux-x86_64-normal-server-slowdebug/jdk/bin
,执行gdbserver
gdbserver :1234 ./java
失常输入
Process ./java created; pid = 5642
Listening on port 1234
下一步
期待一会儿,程序就停在断点上了。
前面的操作就和 idea 一样了,然而如果没理解过 gdb 的能够找找材料学习下。
总结
步骤
1. git clone https://e.coding.net/javalistcn/openjdk/build-openjdk-8.git
2. cd build-openjdk-8
3. docker build -t build-openjdk-8 .
4. cd jdk-jdk8-b120/
5. sed -i '67d' hotspot/make/linux/makefiles/adjust-mflags.sh
6. bash ./configure --with-target-bits=64 --with-debug-level=slowdebug --enable-debug-symbols --with-boot-jdk=/openjdk/java-se-7u75-ri --with-freetype-include=/usr/include/freetype2/ --with-freetype-lib=/usr/lib/x86_64-linux-gnu ZIP_DEBUGINFO_FILES=0
7. make all DISABLE_HOTSPOT_OS_VERSION_CHECK=OK ZIP_DEBUGINFO_FILES=0
8. 配置 clion
9. 运行 gdbserver
正文完