本文主要是支持Clion进行代码的跳转教程,至于OpenJDK17的编译(先独立编译成功,再看后文!!),网上很多教程有现成的。
主要参考链接:
https://blog.jetbrains.com/clion/2020/03/openjdk-with-clion/
环境:Debian10, Clion 2021.1
1.拉取源码
我使用的Github,还有mercurial repo
git clone git@github.com:openjdk/jdk.git
假设路径拉取后的路径为:
/home/jie/jdk
2.bash configure
bash configure --with-debug-level=slowdebug --disable-warnings-as-errors --disable-javac-server
====================================================
A new configuration has been successfully created in
/home/jie/jdk/build/linux-x86_64-normal-server-slowdebug
using configure arguments '--with-debug-level=slowdebug --disable-warnings-as-errors'.
Configuration summary:
* Debug level: slowdebug
* HS debug level: debug
* JVM variants: server
* JVM features: server: 'aot cds cmsgc compiler1 compiler2 epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services vm-structs'
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64
* Version string: 11-internal+0-adhoc.jie.jdk (11-internal)
Tools summary:
* Boot JDK: openjdk version "11.0.11" 2021-04-20 OpenJDK Runtime Environment (build 11.0.11+9-post-Debian-1deb10u1) OpenJDK 64-Bit Server VM (build 11.0.11+9-post-Debian-1deb10u1, mixed mode, sharing) (at /usr/lib/jvm/java-11-openjdk-amd64)
* Toolchain: gcc (GNU Compiler Collection)
* C Compiler: Version 8.3.0 (at /usr/bin/gcc)
* C++ Compiler: Version 8.3.0 (at /usr/bin/g++)
Build performance summary:
* Cores to use: 4
* Memory limit: 11987 MB
看到类似表示配置成功。
–disable-warnings-as-errors 这个是高版本gcc默认将警告当成错误处理造成编译失败的时候,配置的。
多数一句–with-debug-level这个参数是可以有其他值,关键看你编译JDK的目的是什么。
另外wsl需要加上 --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu
3.生成compile_commands.json
安装bear
sudo apt install -y bear
bear工具利用编译时,代码的调用关系生成 compile_commands.json
Clion的2020.2才开始支持 compilation-database。
至于 compilation-database,compile_commands.json的关系,请参考:https://www.jetbrains.com/help/clion/compilation-database.html
https://blog.jetbrains.com/clion/2020/02/dealing-with-makefiles/
bear -- make
看到类似的结果
Compiling 4 files for BUILD_JIGSAW_TOOLS
Stopping sjavac server
Finished building target 'default (exploded-image)' in configuration 'linux-x86_64-normal-server-slowdebug'
这个过程和我们自己调用make并无太大的差别,只是帮我生成了compile_commands.json ,
注意这个地方的linux-x86_64-normal-server-slowdebug,可能和你的不一致,后文选择可执行文件时,路径的就是 /home/jie/jdk/build/linux-x86_64-normal-server-slowdebug/jdk/bin/java
4.使用Clion打开compile_commands.json
打开文件时,请选择
看到类似信息时,项目就导入成功了。
现在就支持代码跳转了。
5.运行
启动配置
- 创建BuildTargets
依次点击OK就行了
这里再重点说一下,可执行文件的位置需要看你生成的JDK的路径,
进行调试
修改源码,进行调试
调试时,如果发生SIGSEGV调试,请参考
忽略“Signal: SIGSEGV (Segmentation fault)”