mirror of
https://github.com/ebrandi/FDD-book.git
synced 2026-12-06 00:23:30 +00:00
Organize companion code and materials by book part: part-01/ Foundations part-02/ Kernel & driver fundamentals part-03/ Character & block devices part-04/ Networking & storage part-05/ Buses & advanced topics part-06/ Debugging & performance part-07/ Real-world drivers appendices/ Supplementary material README.md Overview and build instructions
2.5 KiB
2.5 KiB
Annotated Notes on the GDB Stub Workflow
The Moving Parts
- KDB: the in-kernel debugger framework. It selects a backend and invokes it.
- DDB: the local, in-kernel debugger backend. Uses the system console directly.
- GDB (stub): a remote backend. Speaks the GDB remote serial protocol over a serial line.
- kgdb: the host-side debugger. On a dump, it reads
/var/crash/vmcore.last. On a live remote session, it connects to the stub.
Key Sysctls
debug.kdb.supported_backends- read-only list of backends compiled in.debug.kdb.current_backend- writable; selects which backend handles the next debugger entry.debug.kdb.enter- write1to force entry.debug.kdb.panic_str- triggers a test panic (when the kernel hasINVARIANTS).
Serial Transport
The GDB stub requires a serial line the host can open. Options:
- bhyve:
-l com1,stdioor-l com1,/dev/nmdmXAwith/dev/nmdmXBon the host. - QEMU:
-serial stdio,-serial pty, or-serial unix:/tmp/serial.sock,server,nowait. - Real hardware: a dedicated serial port.
Attach Sequence
- VM enters KDB via
debug.kdb.enter=1or panic. - KDB switches to the GDB backend (if selected).
- Stub waits for the
$GDB packet. - Host
kgdbopens the serial device, sends the handshake. - Stub responds with register values;
kgdbtakes control.
Detach Sequence
- In
kgdb:detach, thenquit. - Stub sees the detach, returns control to the kernel.
- Kernel resumes at the instruction after the entry point.
A hard close (killing kgdb without detach) leaves the stub
expecting more packets. The kernel stays blocked. Usually only
a reboot recovers.
When to Use the Stub vs. DDB
| Situation | Prefer |
|---|---|
| Quick look on a local console | DDB |
| Deep debugging with source-level view | GDB stub |
| No serial port, dev box only | DDB |
| Intermittent bug, need live inspection | GDB stub |
| Post-mortem only | kgdb on vmcore |
| Watchpoints on specific addresses | GDB stub |
When the Stub Is the Wrong Tool
- Production servers: halts all work.
- Time-sensitive code under test: the halt itself is an observation effect.
- Hypervisor-managed migrations: a long halt can look like a dead node and be fenced.
- SMP hangs: only the CPU that entered the debugger is stopped; other CPUs may still be running, which can confuse the picture.