Skip to content

A small collection of notes and bash scripts to serve as future reference regarding setting up environments for debugging kernel modules using GDB

Notifications You must be signed in to change notification settings

AlexSutila/kernelDbgScripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

sudo apt-get install qemu-system

Scripts

Script Purpose
mkrootfs.sh The purpose of this script is to throw together a compressed rootfs, rootfs.cpio.gz, which will be supplied to qemu as the initial ram disk. For the time being, this script uses busybox to do this.
startqemu.sh Starts QEMU in a suspended state, where it will wait for you to attach GDB to it remotely. If rootfs.cpio.gz has yet to be generated, see 'mkrootfs.sh'
startgdb.sh Run after starting QEMU (or running startqemu.sh). In the kernel source, there are helper scripts to simplify kernel debugging in GDB which are also loaded up as well.

Creating rootfs

Busybox Compilation

Running mkrootfs.sh should provide a sufficient rootfs.cpio.gz to at least get something that boots. As mentioned earlier, mkrootfs.sh uses and builds busybox from source and then makes the necessary directory structure needed to boot. A menuconfig menu will apear during this process, be sure to compile it as a static binary (see below). image image If extra stuff is needed, it can be copied into the rootfs folder before it is compressed. Life will be a lot easier if binaries copied into the rootfs can be compiled from source as static binaries.

Additional Notes

During kernel compilation

Compile the kernel with the following flags set as follows (or make sure they are set as follows by inspecting the config file on an already compiled kernel):

Flag Value
CONFIG_DEBUG_INFO y
CONFIG_GDB_SCRIPTS y
CONFIG_KGDB y

After kernel compilation

Run make scripts_gdb in the kernel source root.

During debugging

Once in GDB, the lx-symbols is particularly useful for refreshing debug symbols as you load (or unload) modules while in QEMU.

Loading a dummy hello world module

image

Reloading debug symbols

image

About

A small collection of notes and bash scripts to serve as future reference regarding setting up environments for debugging kernel modules using GDB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages