Skip to main content

Read Linux Kernel With CLion

你是如何阅读内核代码的, 是使用 xtags + vim (+ lsp ), 还是 Source Insight, 还是直接 bootlin 之类的网站在线看?

我的阅读方式是: CLion + compile_commands.json

生成 compile_commands.json

make bzImage -j$(nproc)
./scripts/clang-tools/gen_compile_commands.py

只有 buildin 的模块会在 compile_commands.json 记录编译命令, module 的不会

如果需要看 module 的代码,可以编译模块,重新生成 compile_commands.json

make modules_prepare
make M=drivers/input/mouse -j$(nproc) # 指定模块文件夹
./scripts/clang-tools/gen_compile_commands.py

导入项目

使用 CLion 打开 compile_commands.json 作为 Compilation DB 项目, 导入以后就可以像 CMake 项目一样使用啦