[Yocto] QEMU kernel debugging with GDB
Created:
Updated:
This is a post about aarch64 kernel debugging using qemu and gdb in yocto environment
kernel configuration to debug kernel with gdb
To include debugging information in the vmlinux binary image,set CONFIG_DEBUG_INFO to y. Usually it is not set as default.
1
CONFIG_DEBUG_INFO=y
kernel compilation option in the yocto environment
In ~~~temp/log.do_compile file, there is a compilation log as below. This information is used when specifying the path to the source code in gdb.
1
-fdebug-prefix-map=/mnt/sdb1/src/git/yocto/poky/build/tmp/work-shared/qemuarm64/kernel-source=/usr/src/kernel
Look at the description about the debug-prefix-map option here
- This option is added by the code below.
In conf/bitbake.conf1
KERNEL_SRC_PATH = "/usr/src/kernel"
In conf/bitbake.conf
1
STAGING_KERNEL_DIR = "${TMPDIR}/work-shared/${MACHINE}/kernel-source"
In classes/kernel-arch.bbclass
1
KERNEL_CC = "${CCACHE}${HOST_PREFIX}gcc ${HOST_CC_KERNEL_ARCH} -fuse-ld=bfd ${DEBUG_PREFIX_MAP} -fdebug-prefix-map=${STAGING_KERNEL_DIR}=${KERNEL_SRC_PATH}"
Run qemu
After building, run the command below in the build directory.
-s means -gdb tcp::1234. -S means Do not start CPU at startup(you must type ‘c’ in the monitor)
1
runqemu qemuarm64 qemuparams="-s -S"
Run gdb for aarch64
- Run gdb
1 2 3 4 5 6
$ ./aarch64-poky-linux-gdb ... ... For help, type "help". Type "apropos word" to search for commands related to "word". (gdb)
- Load symbol from vmlinux
1
(gdb) add-symbol-file ~/src//git/yocto/poky/build/tmp/work/qemuarm64-poky-linux/linux-yocto/5.15.14+gitAUTOINC+72e4eafb6b_f77b2ba7d5-r0/linux-qemuarm64-standard-build/vmlinux
- Connect to a target machine
1
(gdb) target remote:1234
- Set source path. Specify the path according to the debug-prefix-map setting specified during compilation. Specify the path as an absolute path.
1
(gdb) set substitute-path /usr/src/kernel /home/chuljeon39a/src/git/yocto/poky/build/tmp/work/qemuarm64-poky-linux/linux-yocto/5.15.14+gitAUTOINC+72e4eafb6b_f77b2ba7d5-r0/linux-qemuarm64-standard-build/source/
- Run layout subcommands
1 2 3
(gdb) layout asm (gdb) layout src (gdb) layout split
- set breakpoint at start_kernel
1
(gdb) b start_kernel
- Continue program being debugged
1
(gdb) c
Debugging using eclipse cdt
If you use eclipse cdt, you can debug more conveniently in the GUI environment.
- Execute eclipse
- In menu, Run -> Debug Configurations…
- Choose GDB QEMU Debugging and click the right mouse button. Then choose New Configuration.
- On Main tab, set Name and C/C++ Application: to the path of vmlinux.
- On Debugger tab, set GDB Client Setup to the path of GDB and set Remote Target to localhost 1234.
- On Startup tab, set Load Symbols and Executable to the path of vmlinux.
Set Set breakpoint at: to start_kernel. - On Source tab, set Path Mapping to the paths that were set as debug-prefix-map during compilation.
- Click Apply and Debug
- Click resume(F8) button or press ‘c’ at Debugger Console window. Then it stops at start_kernel
* To debug repeatedly,
- Run qemu
- Relaunch Debug
Do debugging - Terminate gdb and qemu
- repeat 1 ~ 3
Leave a comment