{"id":13484850,"url":"https://github.com/FlorentRevest/linux-kernel-vscode","last_synced_at":"2025-03-27T16:31:29.166Z","repository":{"id":205999144,"uuid":"715597638","full_name":"FlorentRevest/linux-kernel-vscode","owner":"FlorentRevest","description":"Reference setup for Linux kernel development in VSCode","archived":false,"fork":false,"pushed_at":"2025-03-14T11:36:21.000Z","size":43,"stargazers_count":231,"open_issues_count":1,"forks_count":21,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-14T12:29:53.694Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FlorentRevest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-07T13:17:24.000Z","updated_at":"2025-03-14T11:36:24.000Z","dependencies_parsed_at":"2024-10-30T18:32:11.113Z","dependency_job_id":"f5c538fe-81e9-4533-b2ca-404a4b697c44","html_url":"https://github.com/FlorentRevest/linux-kernel-vscode","commit_stats":null,"previous_names":["florentrevest/linux-kernel-vscode"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlorentRevest%2Flinux-kernel-vscode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlorentRevest%2Flinux-kernel-vscode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlorentRevest%2Flinux-kernel-vscode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlorentRevest%2Flinux-kernel-vscode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FlorentRevest","download_url":"https://codeload.github.com/FlorentRevest/linux-kernel-vscode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245882417,"owners_count":20687884,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:01:36.319Z","updated_at":"2025-03-27T16:31:29.155Z","avatar_url":"https://github.com/FlorentRevest.png","language":"Shell","funding_links":[],"categories":["Shell"],"sub_categories":[],"readme":"# VSCode for Linux kernel development\n\n## Features\n\n**Editor:**\n\n*   Symbol lookup (go-to-definition etc) based on your `.config`\n*   Clangd and Checkpatch live squiggles and linting\n*   Syntax highlighting for KConfig, assembly language, and Device Trees\n\n**Compilation:**\n\n*   Minimal defconfig generation that boots in a VM\n*   Easy cross-compilation to arm64\n*   `Ctrl+Click` on error messages point back to code\n\n**Testing on a local VM:**\n\n*   Minimal Debian VMs generation\n*   Autostart of C and shell payloads\n*   Integrated serial output\n*   Easy SSH into the VM\n\n**Patch management:**\n\n*   `git format-patch` and `send-email` assistant\n*   Mailing list exploration using Patchwork\n*   `kernel.org`'s cgit links generation\n\n**Debugging:**\n\n*   Integrated VM debugger using GDB (function and conditional breakpoints,\n    watchpoints, backtraces, variable inspection, step-by-step, disassembly\n    views etc...)\n*   Integrated IPython notebook for ftrace analysis\n*   BPF selftests cross-compilation and run tasks\n*   Ctrl-Click addresses like `__sys_sendmsg+0x284/0x370` in your backtraces and\n    they will automatically get resolved by `addr2line`\n*   Easy systemtap probing (right click -\u003e \"Trace this function\") and logging\n    with deep argument inspection (logs buffer opens immediately on logs)\n\n**Syzkaller:**\n\n*   Straightforward setup to test syzkaller fuzzer descriptions\n*   Integrated IPython notebook to reproduce [syzbot](https://syzkaller.appspot.com/upstream) bugs\n\n**Other:**\n\n*   Transparent remote development from a laptop\n*   Setup that is easy to modify (bash scripts) and contribute to\n*   Easy to update\n\n## LPC Talk\n\nThis setup was presented at the Linux Plumbers 2023 conference. The slides can be found [here](https://lpc.events/event/17/contributions/1614/attachments/1210/2474/VSCode%20for%20kernel%20development.pdf) and the video below:\n\n[![VSCode for kernel development](https://img.youtube.com/vi/nmYaSqe0fGg/0.jpg)](https://www.youtube.com/watch?v=nmYaSqe0fGg)\n\n## System-wide installation *(done once)*\n\nInstall the dependencies required to run all the supported commands/tasks:\n\n```\ncurl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor \u003e microsoft.gpg\nsudo install -o root -g root -m 644 microsoft.gpg /usr/share/keyrings/microsoft-archive-keyring.gpg\nsudo 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\" \u003e /etc/apt/sources.list.d/vscode.list'\nsudo apt update\nsudo 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 debian-archive-keyring\n```\n\nFor VS Code to keep track of all the files in your kernel source tree:\n\n```shell\nsudo bash -c 'echo \"fs.inotify.max_user_watches=524288\" \u003e\u003e /etc/sysctl.conf'\nsudo sysctl -p\n```\n\n## Linux tree setup *(done once per kernel tree)*\n\nInside a fresh linux kernel tree, e.g.:\n\n```shell\ngit clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git\ncd linux\n```\n\nCreate a `.vscode` directory with our config files inside:\n\n```shell\ngit clone https://github.com/FlorentRevest/linux-kernel-vscode .vscode/\n.vscode/tasks.sh update  # Needs to be run once to generate settings.json\n```\n\n## Extensions *(done once)*\n\nIf you open the kernel tree in VSCode. A pop-up will appear recommending\nworkspace extensions, install them all. Here is what they do:\n\n*   [C/C++ via Clangd](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd)\n    this integrates with a `compile_commands.json` file autogenerated on kernel\n    builds.\n*   [Git integration](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens)\n    this provides a git blame at the end of the selected line and adds many\n    options to the source control tab (commit log, file history, branches\n    switching etc...).\n*   [x86 and x86_64 Assembly](https://marketplace.visualstudio.com/items?itemName=13xforever.language-x86-64-assembly)\n    provides syntax highlighting for asm files.\n*   [ARM64 Assembly](https://marketplace.visualstudio.com/items?itemName=MKornelsen.vscode-arm64)\n    same, but for arm.\n*   [Device Tree](https://marketplace.visualstudio.com/items?itemName=plorefice.devicetree)\n    provides syntax highlighting for dts files.\n*   [KConfig](https://marketplace.visualstudio.com/items?itemName=luveti.kconfig)\n    provides syntax highlighting for Kconfig files.\n*   [Checkpatch](https://marketplace.visualstudio.com/items?itemName=idanp.checkpatch)\n    provides squiggle highlighting of checkpatch errors on file saves.\n*   [Patchwork](https://marketplace.visualstudio.com/items?itemName=florent-revest.patchwork)\n    view, apply and search patches from the\n    [linux patchwork instance](https://patchwork.kernel.org/).\n*   [Addr2line](https://marketplace.visualstudio.com/items?itemName=florent-revest.addr2line)\n    lets users ctrl+click on addresses in backtraces and they get resolved into\n    lines of code.\n*   [Git send-email](https://marketplace.visualstudio.com/items?itemName=florent-revest.git-send-email)\n    facilitates sending patches or series to the list.\n*   [Syzlang](https://marketplace.visualstudio.com/items?itemName=florent-revest.vscode-syzlang)\n    highlights syzkaller syscall descriptions.\n*   [Syzkaller coverage](https://marketplace.visualstudio.com/items?itemName=florent-revest.syzkaller-coverage)\n    can highlight lines covered by a running instance of syz-manager fuzzing.\n*   [SystemTap Assistant](https://marketplace.visualstudio.com/items?itemName=florent-revest.systemtap-assistant)\n    facilitates kernel functions or lines tracing by dynamically generating\n    systemtap scripts and rendering logs received from these probes in a buffer.\n*   [SystemTap](https://marketplace.visualstudio.com/items?itemName=nzh21.systemtap-syntax)\n    highlights systemtap scripts.\n*   [Microsoft C/C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)\n    only the GDB integration of this plugin is used, every features interacting\n    with the code is disabled in favor of Clangd which works much better.\n*   [Trailing spaces](https://marketplace.visualstudio.com/items?itemName=shardulm94.trailing-spaces)\n    highlights forgotten trailing spaces.\n\nIf the pop-up didn't appear or you dismissed it:\n\n1.  Click on the Extensions tab on the left hand side of VSCode\n2.  Enter \"@recommended\" in the search bar\n3.  Manually click the \"Install\" button on every extension in the \"Workspace\n    Recommendations\" section\n\nNOTE: You probably want either one of these extensions too (run the command in\nthe `Ctrl+P` dialog box):\n\n*   [Vim emulation](https://marketplace.visualstudio.com/items?itemName=vscodevim.vim):\n\n    ```shell\n    ext install vscodevim.vim\n    ```\n\n*   [Emacs emulation](https://marketplace.visualstudio.com/items?itemName=vscodeemacs.emacs):\n\n    ```shell\n    ext install vscodeemacs.emacs\n    ```\n\n## Basic usage\n\n*   **Compile** the kernel using `Ctrl+Shift+B` (if you don't have a `.config`\n    yet, it will generate a functional one automatically for you).\n*   **Run** it with `F5`.\n*   **Debug** with breakpoints by clicking on the left of a line number.\n*   **Open** a file by name with `Ctrl+P`.\n*   **Navigate** between symbol definition/declaration with `F12`.\n*   Get **clang squiggles** by building the kernel once and waiting for clangd\n    to index the code for a bit. Clang also supports code refactoring (symbol\n    renames with `F2` for example) and auto-formatting according to kernel rules\n    with `Ctrl+Shift+I`.\n*   Get **`checkpatch` squiggles** by saving the current file.\n*   Interact with **git** following\n    [this demo](https://www.youtube.com/watch?v=UQPb73Zz9qk).\n*   Change the content of `TARGET_ARCH` in `.vscode/local.sh` to `arm64` to\n    transparently get an *aarch64** workspace (future compilations/virtual\n    machines will be `arm64`).\n*   Customize per-workspace VS-Code settings the normal way (edit local\n    `.vscode/settings.json`, or use `Ctrl+Shift+P` -\u003e \"Preferences: Open\n    Settings (UI)\"). Note that fields that exist in `settings.jsonnet` will get\n    overwritten when you run the `update` task. If needed, extra settings can be\n    added in `.vscode/settings-extra.json` file. Also, comments in your\n    `.vscode/settings.json` will get deleted.\n*   **Autostart** commands or codes at VM start time by modifying the content of\n    `.vscode/autostart/` (eg: always run tests that exercise the kernel\n    subsystem you work on).\n*   Find **more helper tasks** using `Ctrl+Shift+P`, search for `Run task` and\n    then pick from the list (for example you can run menuconfig, create SSH\n    sessions, update to the latest version of this setup etc).\n*   **Interact with your VM** from an external terminal using\n    commands such as `lkv start`, `lkv ssh`, `lkv stop` etc...\n\nMake sure to check the *Tips and Tricks* and *Interactive Playground* options\nunder *Help* in the menu bar to learn more about basic VS Code usage.\n\n## Commands outside of VSCode\n\nAll tasks are implemented in the `tasks.sh` file. This script can be run from\nanywhere. For example:\n\n```shell\nalias lkv=~/linux/.vscode/tasks.sh\nlkv build # Equivalent to Ctrl+Shift+B\nlkv start # Equivalent to F5\nlkv ssh\nlkv stop\nlkv push ./file\nlkv pull /root/file\nlkv run ls /\nlkv chroot\n```\n\n## Technical documentation\n\nIf you want or need to dive into the nitty-gritty of this setup:\n\nAll the VSCode config files are maintained under this git repository.\nImprovement PRs can be sent to\nhttps://github.com/FlorentRevest/linux-kernel-vscode and will be easily\nfetchable by users thanks to the auto-update task (which updates `.vscode` from\nthere).\n\n*   `.vscode/tasks.json` [describes per-workspace tasks to\n    VSCode](https://code.visualstudio.com/docs/editor/tasks#_custom-tasks).\n    These tasks are entries under the `Ctrl+Shift+P` `Run task` dialog box. All\n    task basically just call `tasks.sh` with a different command flag.\n*   `.vscode/tasks.sh` is a bash script with a big switch statement that\n    implements all tasks exposed by `tasks.json`. They all share a common\n    preamble customizable\n    locally by local.sh.\n*   `.vscode/settings.jsonnet` [provides per-workspace configuration values to\n    VSCode](https://code.visualstudio.com/docs/getstarted/settings) and its\n    extensions. This is constructed by `tasks.sh` by evaluating\n    [`settings.jsonnet`](http://depot/company/teams/security/kernel/tools/vscode/settings.jsonnet)\n    with the existing settings as an input. The JSonnet file contains sane\n    defaults valid for all kernel developers. For example, it specifies which\n    files VSCode should ignore, how to handle spaces and tabs or how to generate\n    `kernel.org` cgit links from a file path and line. Individual developers can\n    then customize per-workspace settings for their kernel trees while still\n    benefiting from the defaults in the JSonnet file.\n*   `.vscode/syzbot.ipynb` is a reference Jupyter notebook to automate the\n    repetitive aspects of reproducing a syzkaller bug. Every step along the way\n    is guided.\n*   `.vscode/launch.json`\n    [describes how to run a VM with a debugger attached to VSCode](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations).\n*   `.vscode/extensions.json` [describes a list of recommended extensions to\n    VSCode](https://code.visualstudio.com/docs/editor/extension-marketplace#_recommended-extensions).\n    These are meant to be sane defaults valid for all kernel developers.\n    Extensions are pulled in from\n    [the VSCode Marketplace](https://marketplace.visualstudio.com/).\n*   `.vscode/local.sh` is a local config file not updated by the auto-update\n    task. It can be used to implement special features or override defaults for\n    specific needs.\n*   `.vscode/autostart/` contains the template for a dummy task that gets run\n    at the end of the VM's boot. Before running a VM, `tasks.sh` is responsible\n    for detecting changes to these files and updating the files in the VM's\n    rootfs.\n\nNote: The [Patchwork](https://github.com/FlorentRevest/vscode-patchwork) and\n[Git Send Email](https://github.com/FlorentRevest/vscode-git-send-email)\nextensions are homegrown and maintained in other git repositories.\nPull-requests or bug reports are also welcome there.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFlorentRevest%2Flinux-kernel-vscode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFlorentRevest%2Flinux-kernel-vscode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFlorentRevest%2Flinux-kernel-vscode/lists"}