微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Ubuntu编译调试OpenJDK8

下载源码

非官方 切换到jdk8u分支

https://github.com/unofficial-openjdk/openjdk.git

编译

编译jdk需要一个引导jdk, 引导jdk版本需要比编译版本小一个版本或等于当前版本

命令行运行

sh configure  --with-debug-level=slowdebug --enable-debug-symbols --disable-zip-debug-info --with-boot-jdk=/usr/local/java

若报缺少依赖

configure: error: Could not find freetype! You might be able to fix this by running 'sudo apt-get install libfreetype6-dev'. 

则需要对应安装

注意 sudo apt-get install libX11-dev实际为sudo apt-get install libx11-dev

然后

sudo bear make all

因为openjdk是make编译的,Clion对Cmake构建的项目比较友好,使用Make构建的项目,CLion仍然可以通过Compilation Database来导入项目。因此使用bear工具生成Compilation Database

若报错

*** This OS is not supported: Linux ubuntu ****
gmake[5]: *** [****/openjdk/hotspot/make/linux/Makefile:242:check_os_version] 错误 1

修改/openjdk/hotspot/make/linux/Makefile

line:236插入disABLE_HOTSPOT_OS_VERSION_CHECK=ok

cc1plus: all warnings being treated as errors

修改****/openjdk/hotspot/make/linux/makefiles/gcc.make, 注释掉这行

WARNINGS_ARE_ERRORS = -Werror

出现这个, 编译成功

## Finished jdk (build time 00:02:00)

----- Build times -------
Start 2022-08-05 13:52:55
End   2022-08-05 13:58:12
00:00:17 corba
00:02:21 hotspot
00:00:09 jaxp
00:00:15 jaxws
00:02:00 jdk
00:00:15 langtools
00:05:17 TOTAL
-------------------------
Finished building OpenJDK for target 'default'

验证

./build/linux-x86_64-normal-server-slowdebug/jdk/bin/java -version

openjdk version "1.8.0-internal-debug"
OpenJDK Runtime Environment (build 1.8.0-internal-debug-***)
OpenJDK 64-Bit Server VM (build 25.71-b00-debug, mixed mode)

调试

用clion打开项目目录下的compile_commands.json, Open As Project

Settings->Build->Custom Build Targets->见图

clean

make clean

保存

启动按钮的旁边 , 点击 Add Configurations

添加 Custom Build Application

Target设置为刚才设置的debug

Executable设置为编译openjdk中的bin目录下的java

Program directory设置为-version,以作测试

若debug报错

则在用户目录下创建.gdbinit, 内容如下

handle SIGSEGV pass noprint nostop
handle SIGBUS pass noprint nostop

打开/openjdk/jdk/src/share/bin/main.c

在main方法设置断点, debug启动项目

断点挂住

成功

原文地址:https://cloud.tencent.com/developer/article/2067957

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐