# VS Code for kernel hacking (Arch) clangd for modules + eBPF, basedpyright + ruff for gdb scripts. Settings live in the repo's `.vscode/`, so open the repo and you're mostly done. ## Packages ```bash sudo pacman -S code clang bear # essential sudo pacman -S libbpf bpf # eBPF headers + bpftool ``` `clang` brings `clangd` and `clang-tidy`. ## Config ```bash mkdir -p ~/.config/clangd && ln -s "$PWD/tooling/editors/clangd/config.yaml" ~/.config/clangd/ code . ``` Click "Install" when VS Code offers the recommended extensions: **clangd** (essential), **basedpyright** and **Ruff** (Python), **EditorConfig**. Got Microsoft's **C/C++** or **Pylance**? Disable them here, they fight clangd and basedpyright. `.vscode/settings.json`: clangd with background index + clang-tidy, kernel style for C (tabs, width 8, ruler at 100), basedpyright + ruff for Python. `~/.config/clangd/config.yaml` throws out the gcc-only kernel flags clang chokes on, plus `-Werror`, turns on sane clang-tidy checks and compiles `*.bpf.c` as `--target=bpf`. ## bear + clangd clangd has no idea where your module's headers are until you hand it a `compile_commands.json`. bear writes one by watching your build. `$KDIR` is the lab kernel tree you build against: ```bash cd my-module/ make -C "$KDIR" M=$PWD clean # bear only records what actually compiles bear -- make -C "$KDIR" M=$PWD modules ``` Then Ctrl+Shift+P → *clangd: Restart language server*. Redo it when you add files or change flags. - **eBPF / userspace**: `bear -- make -B`. `*.bpf.c` works without it too, as long as there's a `vmlinux.h`: `bpftool btf dump file "$KDIR/vmlinux" format c > vmlinux.h` - **the kernel tree itself**: `make compile_commands.json` in `$KDIR`, no bear needed - **checkpatch**: `"$KDIR"/scripts/checkpatch.pl --no-tree -f file.c` - **still broken?** Output panel → "clangd", or `clangd --check=file.c`