搭建自制可上网操作系统环境2-bochsgdb

本文介绍了如何在Ubuntu系统上安装Bochs2.7版本,配置GDBstub支持,以便在VSCode中调试C代码。步骤包括下载、编译、解决Curses库问题,以及在VSCode的launch.json中设置调试配置。
摘要由CSDN通过智能技术生成

开始安装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语言代码(目前还是实模式)当中,所以暂时不能调试,等到进入保护模式便可以尝试一下了

  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李文区

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值