开发环境: Ubuntu 11.10 + gcc 4.6.1 + bochs 2.6
1. http://bochs.sourceforge.net/ 上下载bochs
2.6的源代码包: bochs-2.6.tar.gz
2. 编辑bochs 2.6,加入--enable-gdb-stub选项以支持GDB调试
# ./configure --enable-gdb-stub
# make
# sudo make install
3. 以下为bochs 2.6的配置文件bochsrc-2.6-linux.bxrc,加入了gdbstub配置项
--------------------------------------------------------------------
gdbstub: enabled=1, port=1234, text_base=0, data_base=0,
bss_base=0
config_interface: textconfig
display_library: x
memory: host=32, guest=32
romimage: file=$BXSHARE/BIOS-bochs-latest
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest-cirrus
boot: floppy
floppy_bootsig_check: disabled=0
floppya: type=1_44, 1_44="Image", status=inserted,
write_protected=0
4. 启动bochs, bochs会提示等待gdb连接
# bochs -qf bochsrc-2.6-linux.bxrc
5. 启动gdb
steve@steve-virtual-machine:/mnt/hgfs/my_git_project/linux-0.11/src$
gdb tools/system
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
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 "i686-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from
/mnt/hgfs/my_git_project/linux-0.11/src/tools/system...done.
(gdb) break main
Breakpoint 1 at 0x67f0: file init/main.c, line 110.
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x0000fff0 in sys_unlink (name=0x0) at
namei.c:712
712 brelse(bh);
(gdb) cont
Continuing.
Breakpoint 1, main () at init/main.c:105
105 { (gdb)
注意在gdb中运行target remote
localhost:1234后,程序停在了0x0000fff0处,因为机器加电后CS:IP就指向0xF000:0xFFF0这个位置.
(gdb) x $cs
0xf000
: 0x00000000