Required kernel configuration
Enable the following Kconfig options and rebuild the kernel:Serial setup
KGDB communicates over a serial port using thekgdboc (KGDB over console)
driver.
Kernel command-line parameters
Add the following toKERNEL_CMDLINE_EXTRA in
meta-qcom/conf/machine/include/qcom-<SoC>.conf:
| Parameter | Effect |
|---|---|
kgdboc=ttyMSM0,115200n8 | Register ttyMSM0 at 115200 baud as the KGDB I/O channel |
kgdbwait | Pause the kernel during boot and wait for a GDB connection before proceeding. Omit this if you prefer to connect GDB at a later point using SysRq. |
nokaslr | Disable kernel address-space layout randomisation. Required for GDB symbol matching. |
Disable the watchdog
The Qualcomm SoC watchdog resets the device if the kernel stops responding. Disable it before starting a KGDB session to prevent unexpected resets:Enter debug mode
Choose one of the following methods to pause the kernel and activate the KGDB stub.Method 1: kgdbwait (boot-time)
Whenkgdbwait is present on the kernel command line, the kernel stops during
boot and prints the following message on the serial console:
Method 2: Magic SysRq (runtime)
From a shell on the target:Method 3: Compile-time breakpoint
Insert a hard breakpoint in driver source code:Method 4: Kernel panic (exception-driven)
The kernel automatically enters KGDB mode when an unhandled exception or panic occurs. To deliberately trigger a crash for testing:Connect GDB from the host
Installgdb-multiarch on the host machine:
Linux host
Windows host
On Windows, set the COM port number above 16 in Device Manager and use the\\.\comN path syntax:
GDB debug session
Essential GDB commands
Table: GDB command reference| Command | Description |
|---|---|
bt | Print a backtrace of the current call stack |
break <function> | Set a breakpoint at the start of a function |
break <file>:<line> | Set a breakpoint at a specific source line |
info break | List all current breakpoints |
info reg | Display all CPU registers |
x/<n>x <addr> | Examine n words of memory at address addr in hex |
p <expression> | Print the value of a C expression or variable |
s | Step one source line (step into function calls) |
n | Next source line (step over function calls) |
c | Continue execution until the next breakpoint or interrupt |
finish | Run until the current function returns |
detach | Detach from the target (kernel continues running) |
Load module symbols
To debug a dynamically loaded kernel module, retrieve the.text section
address from the target:

