【发布时间】:2017-10-07 21:33:26
【问题描述】:
我想要达到的目标
我想自定义一个 GRUB EFI 映像,并在 QEMU 上运行时对其进行调试。
所以我想在自定义之前调试一个普通的 GRUB 图像。
到目前为止我做了什么
我从http://git.savannah.gnu.org下载了GRUB2并编译了它:
./autogen.sh
./configure --prefix=`pwd`/local --with-platform=efi --target=i386 CFLAGS=-g
make
make install
然后,生成一个普通的 EFI 图像:
./local/bin/grub-mkstandalone -O i386-efi -o bootIA32.efi
并将其放入磁盘映像文件中:
qemu-img create -f raw hda.img 1G
mkfs.fat hda.img
sudo mount -o uid=$UID hda.img /mnt
mkdir -p /mnt/efi/boot/
mv bootIA32.efi /mnt/efi/boot/
sudo umount /mnt
为了启动它,我编译了一个 IA32 OVMF.fd 以将它与 QEMU 一起使用:
qemu-system-i386 -bios $UDK_PATH/Build/OvmfIa32/RELEASE_GCC48/FV/OVMF.fd \
-hda hda.img
它正确启动,给了我一个 grub shell。
我卡住的地方
现在,我想调试 GRUB。所以我用附加参数调用了 QEMU:
qemu-system-i386 -bios $UDK_PATH/Build/OvmfIa32/RELEASE_GCC48/FV/OVMF.fd \
-hda hda.img \
-s -S
并将 gdb 附加到 QEMU:
cd grub-core/
gdb -x gdb_grub
但是,似乎缺少调试符号:
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
(...)
For help, type "help".
Type "apropos word" to search for commands related to "word".
0x0000fff0 in grub_disk_cache_table ()
Breakpoint 1 at 0x49b1: file kern/dl.c, line 53.
(gdb) n
Single stepping until exit from function grub_disk_cache_table,
which has no line number information.
0xffffff75 in ?? ()
(gdb)
我做错了什么?
添加符号后
@unixsmurf 当我使用symbol-file 命令时,它似乎正在加载调试符号。确实,gdb 说
(gdb) symbol-file ../local/lib/grub/i386-efi/kernel.exec
Reading symbols from ../local/lib/grub/i386-efi/kernel.exec...done.
但是,我仍然无法使用next 命令,该命令返回
(gdb) n
Single stepping until exit from function grub_disk_cache_table,
which has no line number information.
0xffffff75 in ?? ()
例如,我想在grub_core/kern/main.c:grub_main 函数中设置一个断点并逐步运行它。
但是虽然设置了断点,但是当我continue 执行时,GRUB 到达shell 并没有在断点处停止:
(gdb) b main.c:grub_main
Note: breakpoint 2 also set at pc 0x6082.
Breakpoint 3 at 0x6082: file kern/main.c, line 266.
(gdb) c
Continuing.
【问题讨论】: