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.
compile_commands.json
for kernel using an intercepted buildcompile_commands.json
into an IDE friendly CMakeLists.txt
(Note: not fully tested. Requires some prior knowledge to work around typos etc)
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
bear make -j 12 ## create compile_commands.json
~/.local/bin/intercept-build make -j 12 ## create compile_commands.json
cd ..
* Use our ruby script
``` bash
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
generate-cmake -d
option if not using clion or if cmake build directory is not one level under
kernel source root 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).-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.-d
option as well as the actual ruby code (which is pretty simple))