FlorentRevest / linux-kernel-vscode

Reference setup for Linux kernel development in VSCode
GNU General Public License v2.0
185 stars 15 forks source link

VSCode for Linux kernel development

Features

Editor:

Compilation:

Testing on a local VM:

Patch management:

Debugging:

Syzkaller:

Other:

System-wide installation (done once)

Install the dependencies required to run all the supported commands/tasks:

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo install -o root -g root -m 644 microsoft.gpg /usr/share/keyrings/microsoft-archive-keyring.gpg
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
sudo apt update
sudo apt install code gdb-multiarch ccache clang clangd llvm lld libguestfs-tools libssl-dev trace-cmd python3-pip jsonnet libelf-dev bison bindfs mmdebstrap proot systemtap flex yacc bc

For VS Code to keep track of all the files in your kernel source tree:

sudo bash -c 'echo "fs.inotify.max_user_watches=524288" >> /etc/sysctl.conf'
sudo sysctl -p

Linux tree setup (done once per kernel tree)

Inside a fresh linux kernel tree, e.g.:

git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux

Create a .vscode directory with our config files inside:

git clone https://github.com/FlorentRevest/linux-kernel-vscode .vscode/
.vscode/tasks.sh update  # Needs to be run once to generate settings.json

Extensions (done once)

If you open the kernel tree in VSCode. A pop-up will appear recommending workspace extensions, install them all. Here is what they do:

If the pop-up didn't appear or you dismissed it:

  1. Click on the Extensions tab on the left hand side of VSCode
  2. Enter "@recommended" in the search bar
  3. Manually click the "Install" button on every extension in the "Workspace Recommendations" section

NOTE: You probably want either one of these extensions too (run the command in the Ctrl+P dialog box):

Basic usage

Make sure to check the Tips and Tricks and Interactive Playground options under Help in the menu bar to learn more about basic VS Code usage.

Commands outside of VSCode

All tasks are implemented in the tasks.sh file. This script can be run from anywhere. For example:

alias lkv=~/linux/.vscode/tasks.sh
lkv build # Equivalent to Ctrl+Shift+B
lkv start # Equivalent to F5
lkv ssh
lkv stop
lkv push ./file
lkv pull /root/file
lkv run ls /
lkv chroot

Technical documentation

If you want or need to dive into the nitty-gritty of this setup:

All the VSCode config files are maintained under this git repository. Improvement PRs can be sent to https://github.com/FlorentRevest/linux-kernel-vscode and will be easily fetchable by users thanks to the auto-update task (which updates .vscode from there).

Note: The Patchwork and Git Send Email extensions are homegrown and maintained in other git repositories. Pull-requests or bug reports are also welcome there.