Kernel config options for kgdb
To enable CONFIG_KGDB
you should look under
:menuselection:Kernel hacking --> Kernel debugging
and select
:menuselection:KGDB: kernel debugger
.
While it is not a hard requirement that you have symbols in your vmlinux
file, gdb tends not to be very useful without the symbolic data, so you
will want to turn on CONFIG_DEBUG_INFO
which is called
:menuselection:Compile the kernel with debug info
in the config menu.
It is advised, but not required, that you turn on the
CONFIG_FRAME_POINTER
kernel option which is called :menuselection:Compile the kernel with frame pointers
in the config menu. This option inserts code
into the compiled executable which saves the frame information in registers
or on the stack at different points which allows a debugger such as gdb to
more accurately construct stack back traces while debugging the kernel.
If the architecture that you are using supports the kernel option
CONFIG_STRICT_KERNEL_RWX
, you should consider turning it off. This
option will prevent the use of software breakpoints because it marks
certain regions of the kernel’s memory space as read-only. If kgdb
supports it for the architecture you are using, you can use hardware
breakpoints if you desire to run with the CONFIG_STRICT_KERNEL_RWX
option turned on, else you need to turn off this option.
Next you should choose one of more I/O drivers to interconnect debugging
host and debugged target. Early boot debugging requires a KGDB I/O
driver that supports early debugging and the driver must be built into
the kernel directly. Kgdb I/O driver configuration takes place via
kernel or module parameters which you can learn more about in the in the
section that describes the parameter kgdboc.
Here is an example set of .config
symbols to enable or disable for kgdb::
# CONFIG_STRICT_KERNEL_RWX=is not set
CONFIG_FRAME_POINTER=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
CONFIG_KALLSYMS
root Makefile
ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
KBUILD_CFLAGS += -O1
else ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3
KBUILD_CFLAGS += -O3
else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
KBUILD_CFLAGS += -Os
endif
不常用kgdbcon
kgdboc=ttyS0,115200 kgdbwait nokaslr kgdbcon
指定串口
echo ttyS0,115200 > /sys/module/kgdboc/parameters/kgdboc
陷入gdb
echo g > /proc/sysrq-trigger