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_framesaved bystubs.S. - Core commands: supports
?,g/G,m,Z0/z0(software breakpoints), andc/s/k. All other packets (e.g.M, mostq*queries) currently get an empty reply and are ignored by the stub. - Early attach: a new kernel command-line flag
gdb=earlytriggers an earlyint3after basic init so thatmake run-qemu-gdb GDB_EARLY=1reliably stops in the stub before the kernel races past the boot path. - Safety: the stub only blocks in the RSP loop when either
gdb=earlyis 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
iretqis stable (no more #GP / double-fault when stepping under GDB). The interrupt stack frame layout is guarded with astatic_assertto stay in sync withstubs.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