利用Qemu + Buildroot 进行内核源码级调试
概要:最近想研究下内核里Bridge的具体实现过程,加之公司使用的嵌入式开发环境是基于Buildroot的,想着借用Buildroot来编译qemu可以使用的内核和文件系统,顺便熟悉下Buildroot环境,也省去自己编译内核通过busybox制作文件系统的麻烦。
一、环境
1. 宿主机(64位)系统:
$ lsb_release -d
Description: CentOS Linux release 7.2.1511 (Core)
2. Buildroot环境:
Buildroot是网上https://buildroot.org/download.html下载的最新版本:buildroot-2016.05.tar.gz,默认编译qemu_x86_64可用的版本。
$ tar zxvf buildroot-2016.05.tar.gz
$ cd buildroot-2016.05
$ make list-defconfigs // 列出所有buildroot支持的平台的默认编译。
$ make qemu_x86_64_defconfig // Build for qemu_x86_64
$ make linux-menuconfig // 打开内核编译选项
默认情况内核是没有开启调试信息的,需要开启内核调试信息,否则gdb时候会出现:no debugging symbols found,开启内核调试信息选项的方式如下:
可能有些时候这个”Compile the kernel with debug info”选项没有直接显示,可能会依赖其他编译选项。开启选项然后保存。
$ make
直接编译,最后编译结果都会在output/images/目录下面:
3. Gdb环境
[james_xie@james-desk images]$ gdb -v
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-80.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
系统自带的gdb会有一个问题,当给内核设置断点之后,继续运行的时候回显示:
Remote 'g' packet reply is too long
再继续运行则显示:
这样没办法进行跟踪调试