Coder Social home page Coder Social logo

alikasundara / linux-devel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from plailect/linux-devel

0.0 0.0 0.0 679 KB

A modern Linux kernel kernel development environment featuring integrated debugging based on vscode and libvirtd

License: The Unlicense

linux-devel's Introduction

linux-devel

What

A modern Linux kernel kernel development environment featuring integrated debugging based on vscode and libvirtd.

scrsht_header

Why

Kernel development can be an extremely difficult environment to create an efficient workflow for. If you do not already have a preferred Linux kernel development workflow (based on your favorite editor such as vim or emacs), these instructions are for you. If you already have a preferred workflow based on another tool, you may still find value in the libvirtd-related content presented here.

Configuring vscode to use libvirtd (using UEFI direct kernel boot) allows for building the kernel as one would build any other vscode project, and simple debugging by pressing F5 as one would debug any other C/C++ vscode project. Stack frames, threads, variable introspection, and breakpoints are all presented to the user with an easy-to-use GUI. Hardware breakpoints are used by default as the debugging infrastructure uses GDB under the hood.

TODO

  • Add initramfs instructions
  • Debug edge-cases where breakpoints fail

How

  1. Create a root filesystem VM image and place it somewhere owned by your user (any location / distribution will do, and more efficient solutions than this one likely exist)
cd ~/.local/share/gnome-boxes/images/
virt-builder ubuntu-18.04 --root-password password:toor -o ub1804.qcow2 --format qcow2 --update
  1. Clone the linux source tree and place it somewhere
cd ~/documents/projects/
git clone --depth=1 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
  1. Configure the kernel source using your favorite method. An example .config is provided which will work with the above virt-builder image, but the most important things which need to be enabled are the virtio block device / network driver, and EFISTUB output
cd ~/documents/projects/linux/
wget https://raw.githubusercontent.com/Plailect/linux-devel/master/resources/.config
  1. (Optional) Setup ccache

  2. Create a libvirtd session VM (session VMs are owned by your user, system VMs are owned by root; see this post for details) which uses UEFI direct kernel boot pointed at the built kernel bzImage. An example configuration is presented here:

cd /tmp/
wget https://raw.githubusercontent.com/Plailect/linux-devel/master/resources/example.xml

# edit as necessary
# may need to install UEFI libvirt OVMF support
vim example.xml

env LIBVIRT_DEFAULT_URI=qemu:///session virsh define /tmp/example.xml
  1. (Optional) Ensure that libvirtd has a system network you can bridge to, then set the session VM to use the virbr0 bridged adapter for networking (virt-manager has an excellent GUI that can do this)
sudo virsh net-define /usr/share/libvirt/networks/default.xml
sudo virsh net-autostart default
sudo virsh net-start default
  1. Ensure you have the vscode C/C++ extension, then create the vscode configuration in your kernel source tree
cd ~/documents/projects/linux/
mkdir .vscode
wget https://raw.githubusercontent.com/Plailect/linux-devel/master/resources/.vscode/c_cpp_properties.json

# from amezin/vscode-linux-kernel
wget https://raw.githubusercontent.com/Plailect/linux-devel/master/resources/.vscode/generate_compdb.py
python .vscode/generate_compdb.py

wget https://raw.githubusercontent.com/Plailect/linux-devel/master/resources/.vscode/launch.json
wget https://raw.githubusercontent.com/Plailect/linux-devel/master/resources/.vscode/tasks.json
  1. Open vscode to your kernel development directory to test that everything works properly
  • ctrl+shift+b should trigger a make of the kernel
  • F5 should boot the VM, wait a moment for QEMU's gdbserver to connect, then begin displaying the console in a pane
  • At any point, pressing F6 should pause and allow introspection of state in the debugger tab

linux-devel's People

Contributors

plailect avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.