前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Ubuntu编译调试OpenJDK8

Ubuntu编译调试OpenJDK8

原创
作者头像
code-x
修改2022-08-17 15:01:16
8600
修改2022-08-17 15:01:16
举报
文章被收录于专栏:code-xcode-xcode-x

下载源码

非官方 切换到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
clean
make 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启动项目

断点挂住

成功

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

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

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 下载源码
  • 编译
  • 调试
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档