远程Ubuntu服务器上VSCode搭建xv6内核交互式调试环境遇阻
远程Ubuntu 20服务器上VSCode调试xv6的问题
我通过VSCode的SSH会话在远程Ubuntu 20服务器上开发xv6操作系统,目前能通过gdb命令行正常调试,但想搭建VSCode的交互式调试会话。按照博客指引安装了VSCode的Native Debug插件后,遇到了连接问题。
终端GDB运行输出
baadalvm@baadalvm:~/personal_xv6/col331$ gdb kernel GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2 Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 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 "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from kernel... + target remote localhost:26000 The target architecture is assumed to be i8086 [f000:fff0] 0xffff0: ljmp $0x3630,$0xf000e05b 0x0000fff0 in ?? () + symbol-file kernel (gdb)
VSCode启动调试的输出
Reading symbols from /home/baadalvm/personal_xv6/col331/kernel... + target remote localhost:26000 The target architecture is assumed to be i8086 [f000:fff0] 0xffff0: ljmp $0x3630,$0xf000e05b 0x0000fff0 in ?? () + symbol-file kernel WARNING: Error executing command 'gdb-set target-async on' warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default i8086 settings.
错误信息
启动qemu-gdb目标后启动调试会话,收到如下错误:
Failed to attach: Remote communication error. Target disconnected.:: Connection reset by peer.(from target-select remote:26000)
我认为问题不是未配置.gdbinit导致的,因为已经添加了路径,且命令行连接gdbserver正常。
我的配置文件
launch.json
{ "version": "0.2.0", "configurations": [ { "type": "gdb", "request": "attach", "name": "debug xv6", "executable": "kernel", "target": ":26000", "remote": true, "cwd": "${workspaceRoot}", } ] }
tasks.json
{ "version": "2.0.0", "tasks": [ { "label": "compile xv6 and run in debug mode", "command": "bash", "args": [ "-c", "make && make qemu-gdb" ], "presentation": { "echo": true, "reveal": "always", "focus": true, "panel": "new", "showReuseMessage": true, "clear": true }, "group": { "kind": "build", "isDefault": true } } ] }
解决方法
1. 禁用目标异步模式
你使用的GDB 9.2不支持target-async命令,这是Native Debug插件默认发送的指令,直接导致连接失败。在launch.json中添加"targetAsync": false关闭该功能:
{ "version": "0.2.0", "configurations": [ { "type": "gdb", "request": "attach", "name": "debug xv6", "executable": "kernel", "target": ":26000", "remote": true, "cwd": "${workspaceRoot}", "targetAsync": false } ] }
2. 明确指定目标架构
GDB默认架构识别不匹配xv6的i8086,在launch.json中添加架构配置消除ABI警告:
{ // ...其他配置项 "architecture": "i8086", "targetAsync": false }
3. 确认QEMU监听配置
检查Makefile中qemu-gdb目标的配置,确保是监听本地26000端口且启动后暂停等待连接:
QEMUOPTS += -gdb tcp::26000 -S
-S参数会让QEMU启动后暂停,必须保留才能正常等待GDB连接。
4. 严格执行启动顺序
先运行compile xv6 and run in debug mode任务,等终端显示Waiting for gdb connection后,再启动VSCode的调试会话,避免QEMU未完全就绪就发起连接。
5. 替换为官方C/C++插件(可选)
如果Native Debug插件仍有问题,换成官方C/C++插件更稳定,修改launch.json为以下配置:
{ "version": "0.2.0", "configurations": [ { "name": "Debug xv6", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/kernel", "miDebuggerServerAddress": "localhost:26000", "args": [], "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "text": "set architecture i8086" } ] } ] }
内容的提问来源于stack exchange,提问作者Tejas Anand
相关产品推荐
相关产品推荐

