Skip to content

kernel: add minimal GDB remote serial stub (main thread)

Add a minimal x86-64 GDB Remote Serial Protocol (RSP) stub for the CloudOS kernel, currently targeting the main (BSP) kernel thread. The stub speaks the normal GDB remote protocol over the existing serial port so we can attach GDB during early kernel boot or when an exception occurs.

High-level behavior:

  • Exceptions: the common interrupt handler can route #BP (int3) and #DB (single-step) – and, once a debugger is known to be attached, all CPU exceptions (0–31) – into gdbstub_trap(), which enters the RSP loop.
  • Registers: the stub exposes the standard 156-byte x86-64 KGDB register layout, filled from struct int_stack_frame saved by stubs.S.
  • Core commands: supports ?, g/G, m, Z0/z0 (software breakpoints), and c/s/k. All other packets (e.g. M, most q* queries) currently get an empty reply and are ignored by the stub.
  • Early attach: a new kernel command-line flag gdb=early triggers an early int3 after basic init so that make run-qemu-gdb GDB_EARLY=1 reliably stops in the stub before the kernel races past the boot path.
  • Safety: the stub only blocks in the RSP loop when either gdb=early is enabled or a GDB client has actually sent a first packet (gdbstub_is_active()). Normal boots without GDB behave as before (exceptions log and halt).
  • Integration: GDT and interrupt stubs are adjusted so that returning from the stub via iretq is stable (no more #GP / double-fault when stepping under GDB). The interrupt stack frame layout is guarded with a static_assert to stay in sync with stubs.S.

Fault-safe memory probing (mem_err-style) and more advanced multi-thread / multi-CPU support are intentionally left for follow-up work.

Edited by Prathamesh Hemant Doundkar

Merge request reports

Loading