mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-27 04:01:36 +01:00
Split QEMU run, automate GDB debugging
This commit is contained in:
60
README.md
60
README.md
@@ -1,9 +1,10 @@
|
||||
# Linux Kernel Module Cheat
|
||||
|
||||
Run one command, get into QEMU Buildroot BusyBox with several minimal Linux kernel 4.9 module example tutorials. Tested in Ubuntu 14.04.
|
||||
Run one command, get into QEMU Buildroot BusyBox with several minimal Linux kernel 4.9 module example tutorials. Tested in Ubuntu 14.04 host.
|
||||
|
||||
Usage:
|
||||
|
||||
sudo apt-get install qemu
|
||||
./run
|
||||
|
||||
First build will take a while (GCC, Linux kernel).
|
||||
@@ -22,19 +23,72 @@ Each module comes from a C file under `kernel_module/`. For module usage do:
|
||||
|
||||
grep BR2_LINUX_KERNEL_VERSION buildroot/.config
|
||||
|
||||
After the first build, you can also run just:
|
||||
|
||||
./runqemu
|
||||
|
||||
to save a few seconds. `./run` wouldn't rebuild everything, but checking timestamps takes a few moments.
|
||||
|
||||
We use `printk` a lot, and it shows on the QEMU terminal by default. If that annoys you (e.g. you want to see stdout separately), do:
|
||||
|
||||
dmesg -n 1
|
||||
|
||||
See also: <https://superuser.com/questions/351387/how-to-stop-kernel-messages-from-flooding-my-console>
|
||||
|
||||
When your kernel starts crashing, get the full trace with:
|
||||
## Debugging
|
||||
|
||||
GDB the linux kernel:
|
||||
|
||||
./runqemu -d
|
||||
|
||||
If you want to break immediately at a symbol, e.g. `start_kernel` of the boot sequence, open another terminal and run for example:
|
||||
|
||||
./rungdb start_kernel
|
||||
|
||||
Now QEMU will stop there, and you can use the normal GDB commands:
|
||||
|
||||
l
|
||||
n
|
||||
c
|
||||
|
||||
To skip the boot, run just:
|
||||
|
||||
./rungdb
|
||||
|
||||
and when you want to break, do `Ctrl + C` from GDB.
|
||||
|
||||
To have some fun, you can first run inside QEMU:
|
||||
|
||||
/count.sh
|
||||
|
||||
which counts to infinity to stdout, and then:
|
||||
|
||||
Ctrl + C
|
||||
break sys_write
|
||||
|
||||
And now you can control the counting from GDB:
|
||||
|
||||
continue
|
||||
continue
|
||||
continue
|
||||
|
||||
## Text mode
|
||||
|
||||
Show serial output of QEMU directly on the current terminal, without opening a QEMU window:
|
||||
|
||||
./run -n
|
||||
|
||||
To exit, just do a regular:
|
||||
|
||||
poweroff
|
||||
|
||||
This is particularly useful to get full panic traces when you start making the kernel crashing :-)
|
||||
|
||||
In case of a panic, you want your terminal back with `Ctrl + C, A` and type `quit`. See also: <http://stackoverflow.com/questions/14165158/how-to-switch-to-qemu-monitor-console-when-running-with-curses>
|
||||
|
||||
See also: <https://unix.stackexchange.com/questions/208260/how-to-scroll-up-after-a-kernel-panic>
|
||||
|
||||
Then if you want your terminal back, hit `Ctrl + C, A` and type `quit`. See also: <http://stackoverflow.com/questions/14165158/how-to-switch-to-qemu-monitor-console-when-running-with-curses>
|
||||
## Table of contents
|
||||
|
||||
1. [Introduction](introduction.md)
|
||||
1. [Build](build.md)
|
||||
|
||||
Reference in New Issue
Block a user