前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >简单几步!Windows下Clion结合docker调试openjdk8源码

简单几步!Windows下Clion结合docker调试openjdk8源码

作者头像
DH镔
发布2021-01-20 10:15:29
1.3K0
发布2021-01-20 10:15:29
举报

废话不多说,开干!

原理是通过Docker编译openjdk,然后结合clion通过gdbserver远程调试

环境需求

  • Clion
  • Docker

我测试的版本

Docker for windows : Docker version 20.10.2, build 2291f61

Clion : 2020.3.1

构建镜像

代码语言:javascript
复制
git clone https://e.coding.net/javalistcn/openjdk/build-openjdk-8.git
cd  build-openjdk-8
docker build -t build-openjdk-8 .

运行

代码语言:javascript
复制
docker run -it --name build-openjdk-8 -p 1234:1234 build-openjdk-8

1234端口用于gdbserver 这个非常重要!!!

编译

进入到容器后执行

代码语言:javascript
复制
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

正常输出

代码语言:javascript
复制
====================================================
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'.
代码语言:javascript
复制
make all DISABLE_HOTSPOT_OS_VERSION_CHECK=OK ZIP_DEBUGINFO_FILES=0

一杯咖啡时间过后看到一下内容输出就大功告成了。

代码语言:javascript
复制
----- 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

代码语言:javascript
复制
gdbserver :1234 ./java

正常输出

代码语言:javascript
复制
Process ./java created; pid = 5642
Listening on port 1234

下一步

等待一会儿,程序就停在断点上了。

后面的操作就和idea一样了,但是如果没了解过gdb的可以找找资料学习下。

总结

步骤

代码语言:javascript
复制
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
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 环境需求
  • 构建镜像
    • 运行
      • 编译
        • Clion配置
          • 总结
            • 步骤
        相关产品与服务
        容器镜像服务
        容器镜像服务(Tencent Container Registry,TCR)为您提供安全独享、高性能的容器镜像托管分发服务。您可同时在全球多个地域创建独享实例,以实现容器镜像的就近拉取,降低拉取时间,节约带宽成本。TCR 提供细颗粒度的权限管理及访问控制,保障您的数据安全。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档