# Linux Kernel Module Cheat

### 3.1. GDB step debug kernel boot

`--gdb-wait` makes QEMU and gem5 wait for a GDB connection, otherwise we could accidentally go past the point we want to break at:

    ./run --gdb-wait

Say you want to break at `start_kernel`. So on another shell:

    ./run-gdb start_kernel

or at a given line:

    ./run-gdb init/main.c:1088

Now QEMU will stop there, and you can use the normal GDB commands:

    list
    next
    continue

See also:

- https://stackoverflow.com/questions/11408041/how-to-debug-the-linux-kernel-with-gdb-and-qemu/33203642#33203642

- https://stackoverflow.com/questions/4943857/linux-kernel-live-debugging-how-its-done-and-what-tools-are-used/42316607#42316607

- GDB step debug kernel boot other archs

- Disable kernel compiler optimizations