开始安装bochsgdb,方便之后使用vscode debug调试c代码
如果在bochsrc文件中末尾添加gdbstub: enabled=1, port=1234, text_base=0, data_base=0, bss_base=0
启动bochs -q
会报错Bochs is not compiled with gdbstub support
说明安装的bochs不支持gdbstub
先下载bochs2.7, 下面两个地址都可以
https://udomain.dl.sourceforge.net/project/bochs/bochs/2.7/bochs-2.7.tar.gzhttps://sourceforge.net/projects/bochs/files/bochs/2.7/bochs-2.7.tar.gz
可以用迅雷下载
随便下载到一个目录下面
切换到root账户sudo su
tar -zxvf bochs-2.7.tar.gz
cd bochs-2.7
./configure --prefix=/usr/local --without-wx --with-x11 --with-x --with-term --disable-docbook --enable-cpu-level=6 --enable-fpu --enable-3dnow --enable-disasm --enable-long-phy-address --enable-disasm --enable-pcidev --enable-usb --enable-all-optimizations --enable-gdb-stub --with-nogui
最后显示代表执行成功
遇到这个报错Curses library not found: tried curses, ncurses, termlib and pdcurses.
执行apt-get install ncurses-devel
然后执行
make && make install
cd /usr/local/bin
mv bochs bochs-gdb
rm -rf bochs-gdb-a20
然后通过bximage生成一个新的配置文件bochsrc
我生成好了
# configuration file generated by Bochs
plugin_ctrl: unmapped=true, biosdev=true, speaker=true, extfpuirq=true, parallel=true, serial=true, pcidev=false, usb_uhci=false
config_interface: textconfig
display_library: x
memory: host=32, guest=32
romimage: file="/usr/share/bochs/BIOS-bochs-latest", address=0x00000000, options=none
vgaromimage: file="/usr/share/bochs/VGABIOS-lgpl-latest"
boot: disk
floppy_bootsig_check: disabled=0
floppya: image="../build/floppya.img", status=inserted
# no floppyb
ata0: enabled=true, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=disk, path="./myos.img", mode=flat
ata0-slave: type=none
ata1: enabled=true, ioaddr1=0x170, ioaddr2=0x370, irq=15
ata1-master: type=none
ata1-slave: type=none
ata2: enabled=false
ata3: enabled=false
optromimage1: file=none
optromimage2: file=none
optromimage3: file=none
optromimage4: file=none
optramimage1: file=none
optramimage2: file=none
optramimage3: file=none
optramimage4: file=none
pci: enabled=1, chipset=i440fx, slot1=none, slot2=none, slot3=none, slot4=none, slot5=none
vga: extension=vbe, update_freq=5, realtime=1, ddc=builtin
cpu: count=1, ips=4000000, model=bx_generic, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0
cpuid: level=6, stepping=3, model=3, family=6, vendor_string="AuthenticAMD", brand_string="AMD Athlon(tm) processor"
cpuid: mmx=true, apic=xapic, simd=sse2, sse4a=false, misaligned_sse=false, sep=true
cpuid: movbe=false, adx=false, aes=false, sha=false, xsave=false, xsaveopt=false, smep=false
cpuid: smap=false, mwait=true
print_timestamps: enabled=0
gdbstub: enabled=1, port=1234, text_base=0, data_base=0, bss_base=0
port_e9_hack: enabled=0
private_colormap: enabled=0
clock: sync=none, time0=local, rtc_sync=0
# no cmosimage
log: -
logprefix: %t%e%d
debug: action=ignore
info: action=report
error: action=report
panic: action=ask
keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none
mouse: type=ps2, enabled=false, toggle=ctrl+mbutton
speaker: enabled=true, mode=system
parport1: enabled=true, file=none
parport2: enabled=false
com1: enabled=true, mode=file, dev=../build/serial.txt
com2: enabled=false
com3: enabled=false
com4: enabled=false
使用命令执行 bochs-gdb -q -f bochsrc
vscode在.vscode的launch.json中增加
{
"name": "myos - Build and debug kernel",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/kernel.bin",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/src",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerServerAddress": "localhost:1234",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"miDebuggerPath": "/usr/bin/gdb"
},
然后可以看到vscode debug窗口有反应即可,由于现在还不能进入32位c语言代码(目前还是实模式)当中,所以暂时不能调试,等到进入保护模式便可以尝试一下了