1 Star 0 Fork 0

STZ / mirror-kernel-grok

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

kernel-grok

grok the linux kernel via a cmake shim

I'm sure there are great ways to spelunk the kernel with an ide... This is my attempt to rig something together using a simple ruby script and a roll of duct tape.

Nutshell:

  • create compile_commands.json for kernel using an intercepted build
  • use ruby script to convert compile_commands.json into an IDE friendly CMakeLists.txt

Possible steps

(Note: not fully tested. Requires some prior knowledge to work around typos etc)

  • Install scan-build (a build interceptor)
## requires python
pip install scan-build --user
## installs intercept-build tool in ~/.local/bin

OR

  • Install Bear (Another build interceptor; wont work on recent MacOs, likely thwarted by selinux)
git clone https://github.com/rizsotto/Bear && cd Bear
mkdir build && cd build
cmake .. && make 
sudo make install
cd ../..
  • Grab the kernel and build
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
cd linux-stable
git reset --hard v4.14-rc2  ## random known good version
make defconfig

## Note that we intercept the build

## _Either_
bear make -j 12  ## create compile_commands.json

## _Or_ 
~/.local/bin/intercept-build make -j 12  ## create compile_commands.json

cd .. 
  • Use our ruby script
git clone https://github.com/habemus-papadum/kernel-grok.git

cd linux-stable
../kernel-grok/generate_cmake  ## creates CMakeLists.txt

## test that generated cmake is valid
mkdir build
cd build
cmake .. && make -j12
  • Now open linux-stable/CMakeLists.txt in an ide (tried testing with clion; though takes about 10 minutes to index the project initially; at first it seemed like an epic fail, but seems quite usable after initial indexing and then restarting)
  • note generate-cmake -d option if not using clion or if cmake build directory is not one level under kernel source root

Theory of operation

  • using compilation database generated by bear/intercept-build, a cmake shim is created that creates a single cmake OBJECT library (this is a somewhat obscure library type that as opposed to SHARED performs no linking).
  • The shim should properly properly compile -- though it just creates object files that are then abandoned (not linked into a final kernel). This means your ide can be used not only for semantic navigation e.g. it knows where to find headers and knows about -Ddefines and so can jump to defintions and find usages etc, but also allows for testing whether edits to existing files compile -- perhaps 90% of the typical dev workflow.
  • Analogy might be Xcode projects generated by CMake. Can be used to make some edits, but larger things like adding files, etc cannot be done in Xcode. So after big changes e.g. new file, new kernel config, you must repeat intercepted KBuild, regenerate shim, and then reload project in ide
  • Use ide compilation to test if your edits compile (only worth it because it is easy to navigate to errors when you ide does the build). Use KBuild to create a proper image to run in qemu etc.
  • NOTE: Everything depends on the kernel actually being built at least once with normal Kbuild. There are generated files that are needed.
  • NOTE: Although a CMakeLists.txt is included in the repo for providing a quick look at what is being done, it should not be used -- GENERATE YOUR OWN
  • NOTE: linux assumes builds are done from the root src directory e.g. "in-tree". Some hacking is done to allow the cmake shim to work out of tree (again, cf. -d option as well as the actual ruby code (which is pretty simple))
  • NOTE: An alternative would be to use {spac}emacs + rtags -- TODO: compare and constrast vs clion
  • A similar approach can be taken to spelunk through other non-cmake projects , though each project will require some tinkering

空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/papermosquito/mirror-kernel-grok.git
git@gitee.com:papermosquito/mirror-kernel-grok.git
papermosquito
mirror-kernel-grok
mirror-kernel-grok
master

搜索帮助