Linux kernel symbols debug

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

How to create a setup for linux kernel debugging using buildroot

Rhydon1337/linux-kernel-debugging

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

How to create a setup for linux kernel debugging using buildroot, qemu and gdb.

Part 1: Compile linux kernel and rootfs

Читайте также:  Which cmd in linux

We are going to compile linux kernel and rootfs using buildroot. Buildroot supplies all the toolchain which needed for automate the process of compiling linux kernel and rootfs. Buildroot was created for creating linux embedded/minimal systems. However, if your purpose is developing or debugging the linux kernel its really good solution.

First, Clone buildroot repository (latest version):

Now we need to configure buildroot in order to build every packages with debug symbols. In order to be able to ssh to the vm we’ll add the openssh package.

The path to the options may change between buildroot versions, if an option is missing validate the symbols are set appropriately using cat .config | grep from buildroot’s folder

If you want to tell buildroot to download and compile antoher version of linux kernel:

  • In Toolchain, change “linux version” to
  • In Toolchain, change “Custom kernel version headers series” to
  • In Kernel, change “Kernel version» to

Now we are going to configure linux kernel in order to compile it with debug symbols. Before opening the menuconfig it will trigger buildroot to download linux kernel source code.

Compile linux kernel and rootfs

Now lets compile everything:

  • output/build/linux- contains the downloaded kernel source code
  • output/images/bzImage is the compressed kernel image
  • output/images/rootfs.ext4 is the rootfs
  • output/build/linux-/vmlinux is the raw kernel image

Part 2: Debugging linux kernel using qemu and gdb

After we compiled the linux kernel and rootfs we can debug it. Our emulator will be qemu because qemu is a really lightweight emulator that can be easily configured to run almost anything and qemu works fine with kvm which improves the performance.

sudo -i cd /path/to/buildroot/output/images mkdir /mnt/dbg_kernel_fs mount rootfs.ext2 /mnt/dbg_kernel_fs echo "PermitRootLogin yes" >> /mnt/dbg_kernel_fs/etc/ssh/sshd_config umount /mnt/dbg_kernel_fs rmdir /mnt/dbg_kernel_fs exit 

Now we’ll convert our raw rootfs to qemu format which will enable us to create snapshots later on.

cd ./output/images qemu-img convert -f raw -O qcow2 rootfs.ext2 rootfs.qcow2 

Note: rootfs.ext4 is just a symlink to rootfs.ext2

Copy/Replace start-qemu.sh from this repo into buildroot/output/images. This shell script runs qemu with customized flags explained below:

  • -monitor unix:qemu-monitor-socket,server,nowait -> creates a socket file named qemu-monitor-socket to which we’ll connect with socat for the qemu monitoring
  • -enable-kvm -> kvm is a virtualization solution for linux which use hardware virtualization extensions, we will use it in order to improve the vm performance
  • -cpu host -> use host cpu, we will use it in order to improve the vm performence
  • -s -> qemu will open a gdbserver on TCP port 1234
  • -m 2048 -> amount of memory of the vm (2mb in our example)
  • -hda -> path to the root filesystem image in our case the rootfs
  • -append -> send command line arguments to the linux kernel
  • -net nic,model=virtio -> connect a network interface
  • -net user,hostfwd=tcp::5555-:22 -> forwards tcp traffic from host port 5555 to guest port 22 which allows us to use ssh.
Читайте также:  Обновить кали линукс через терминал

In order to take snapshots we’ll connect to the qemu monitor 11. socat stdio,echo=0,icanon=0 unix-connect:qemu-monitor-socket

saving and loading snapshots can be done in the following manner respectively:

Start the debugging session

Now we are going to attach to our vm and the debug the kernel, we will also use our symbols to the kernel.

And now you got a kernel debugging session.

About

How to create a setup for linux kernel debugging using buildroot

Источник

Оцените статью
Adblock
detector