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启动项目

断点挂住

成功

相关文章

目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、...
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html ...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失...
参见:https://blog.csdn.net/weixin_38883338/article/deta...
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netpla...
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问...