【发布时间】:2019-09-30 13:12:59
【问题描述】:
我是 Linux 内核的新手,我正在尝试通过 QEMU 使用 gdb 对其进行调试。我的问题是 gdb 在break start_kernel 之后没有停止。更多详情如下。
我的主机系统是 ArchLinux 5.0.10-arch1-1-ARCH x86_64。
Qemu 是QEMU emulator version 4.0.0
gdb 是GNU gdb (GDB) 8.2.1。
调试内核为linux-4.20.12
我已经完成了以下步骤:
- 用 编译内核
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_KERNEL=y
CONFIG_GDB_SCRIPTS=y
# CONFIG_DEBUG_INFO_REDUCED is not set
- 尝试通过 QEMU 用它的内核运行 LFS-8.4 系统
qemu-system-x86_64 lfs-8.4-08052019.raw
系统启动良好。
- 通过 QEMU 使用
stop CPU和gdbserver选项运行此系统
qemu-system-x86_64 lfs-8.4-08052019.raw -S -s
- 启动 gdb
$ gdb
- 加载符号
(gdb) file /mnt/lfs/sources/linux-4.20.12/vmlinux
Reading symbols from /mnt/lfs/sources/linux-4.20.12/vmlinux...done.
- 连接到 QEMU
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x000000000000fff0 in cpu_hw_events ()
- 设置断点
(gdb) break start_kernel
Breakpoint 1 at 0xffffffff82761ab5: file init/main.c, line 538.
(我试过硬件断点hbreak,结果还是一样)
- 继续
(gdb) c
Continuing.
进一步的系统加载登录提示没有任何中断,gdb 不显示任何新消息。 我做错了什么?
UPD:使用嵌入 -kernel 工具启动 QEMU 会得到相同的结果
qemu-system-x86_64 -kernel /mnt/lfs/sources/linux-4.20.12/arch/x86/boot/bzImage -append 'root=/dev/sda3' -drive file=lfs-8.4-08052019.raw -S -s
UPD2:我尝试在没有 -S 键的情况下启动 QEMU 并立即在 gdb 中运行 target remote localhost:1234。 QEMU 已停止加载
Decompressing Linux... Parsing ELF... Performing relocations... done.
Booting kernel.
当我在 gdb 中输入 s 时,它会说
(gdb) s
Cannot find bounds of current function
我怀疑 vmlinux 中的调试符号与 bzImage 无关。也许他们是错的,但我不知道如何让他们以另一种方式。
UPD3:我在 LFS-8.4 chroot 环境中构建了内核 2.6。系统没有加载,但是通过上述方法成功调试内核!所以,我认为这是新内核的问题。也许我应该在我的 4.20.12 内核中关闭/打开某些东西,但我不知道到底是什么。对于我的目的(阅读 Robert Love “Linux Kernel Development”)内核版本 2.6 就足够了。
【问题讨论】:
标签: linux linux-kernel gdb