使用 QEMU + gdb 搭建调试 Linux 内核环境
-
获取 Linux 源码
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git // 镜像地址,下载速度更快。 $ git clone git://kernel.source.codeaurora.cn/pub/scm/linux/kernel/git/torvalds/linux.git
-
安装依赖环境
sudo apt install flex bison libssl-dev libelf-dev debootstrap qemu-system dwarves qemu-kvm qemu-system-x86
-
编译 Linux 内核
// 第一步,进入 Linux 源码目录 $ cd /your_linux_source_path/linux $ make CC="$GCC/bin/gcc" defconfig // 第二步,打开内核调试宏:CONFIG_DEBUG_INFO=y,CONFIG_GDB_SCRIPTS=y $ make menuconfig // 选择如下路径: Kernel hacking ---> Compile-time checks and compiler options ---> [*] Compile the kernel with debug info Kernel hacking ---> Compile-time checks and compiler options ---> [*] Provide GDB scripts for kernel debugging 添加完以上两个选项之后,会保