1. 程式人生 > >Bochs + GDB 原始碼級除錯C語言核心

Bochs + GDB 原始碼級除錯C語言核心

環境:
Ubuntu 14.04 64bit Bochs 2.6.6 GDB 7.7 想要原始碼級除錯C核心,需要在編譯Bochs時加上 --enable-gdb-stub 引數 sudo ./configure --enable-all-optimizations --enable-long-phy-address --enable-disasm --enable-alignment-check --enable-pci --enable-cdrom --enable-gameport --enable-large-ramfile --enable-gdb-stub  --enable-show-ips  --with-all-libs 配置bochsrc檔案: gdbstub:enable=1,port=1234,text_base=0,data_base=0,bss_base=0 開啟兩個終端,在第一個終端中執行Bochs: $:bochs -f bochsrc 在第二個終端中執行GDB: $:gdb ./src/kernel.elf 進入gdb命令列,在gdb命令列中輸入命令: break main(在main函式開始處下斷點) target remote localhost:1234(連線到Bochs) c(執行到斷點處停下) ...後續GDB除錯命令... 注意: 1、使用Bochs+GDB原始碼除錯,必須以-g編譯C原始碼,當使用ld連結時,去掉-s選項 2、可以用list檢視原始檔程式碼,但不能使用s或n單步除錯和檢視變數值,出現如下錯誤:         (gdb) n
Cannot find bounds of current function
(gdb) n
Cannot find bounds of current function
(gdb) n
Cannot find bounds of current function
     出現這種情況,可能與編譯Bochs選項有關,去掉 --enable-x86-64, --enable-vmx兩個選項後重新編譯Bochs,然後在bochsrc檔案中註釋掉這兩行:
cpu:model=core2_penryn_t9600,count=1,ips=50000000,reset_on_triple_fault=1,ignore_bad_msrs=1,msrs="msrs.def" cpu:cpuid_limit_winnt=0
有圖有真相: