2020.12.07 更新
CLion 調試代碼的方式有問題,在代碼中打斷點的位置和代碼執行的位置不一致,調試體驗很差。
現在已經不用Clion調試代碼了,改為采用VSCode,可正常debug。
請閱讀文章 使用VSCode調試OpenJDK8
以 Manjaro 20.1 為例
系統環境
? ~ uname -r
5.4.57-1-MANJARO
? ~ make -version
GNU Make 4.3
? ~ gcc -v
...
gcc version 10.2.0 (GCC)
? ~ g++ -v
...
gcc version 10.2.0 (GCC)
安裝必要的編譯、調試軟件
- CLion C and C++ IDE
- compiledb Tool for generating Clang's JSON Compilation Database file for GNU make-based build systems
- Building the JDK 編譯需要的安裝包參考
-
mercurial
sudo pacman -S mercurial
- OracleJDK7 作為編譯OpenJDK8 的 bootSDK
獲取源碼
需要掛梯子
# 根據自己的實際情況配置
export ALL_PROXY=socks5://127.0.0.1:1080
# 這里最好用jdk8u, 不容易出問題
hg clone http://hg.openjdk.java.net/jdk8u/jdk8u/
# 進入目錄
cd jdk8u
# 執行腳本,拉取所有代碼
bash ./get_source.sh
配置源碼
# 移除環境變量配置
unset JAVA_HOME
# 生成debug版本的 openjdk8
bash ./configure --enable-debug --enable-debug-symbols --disable-zip-debug-info --with-boot-jdk=/home/zero/Documents/Java/jdk1.7.0_80
編譯源碼
# 源碼里將所有的warn處理為error。 這里必須配置WARNINGS_ARE_ERRORS=""
# compiledb 是為了生成 compile_commands.json
compiledb make WARNINGS_ARE_ERRORS="" images
CLion 導入項目
File -> Open 選擇 compile_commands.json -> 選擇 open as project
CLion 運行、調試設置
GDB 配置
vim ~/.gdbinit
handle SIGSEGV nostop noprint pass
handle SIGBUS nostop noprint pass
handle SIGFPE nostop noprint pass
handle SIGPIPE nostop noprint pass
handle SIGILL nostop noprint pass