You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode调试模式下D语言程序输入挂起无法继续执行问题求助

D语言程序在VS Code Native Debug插件下调试时stdin输入无响应问题

环境信息

Version: 1.62.0
Commit: b3318bc0524af3d74034b8bb8a64df0ccf35549a
Date: 2021-11-04T20:38:29+02:00
Electron: 13.5.1
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
ОС: Solus 4.3 Fortitude, Linux x64 5.14.16-204.current

问题描述

现有一个使用D语言编写的程序,程序在循环中接收输入字符串、读取内容后执行后续算法逻辑。该程序在正常运行模式下工作无任何问题。
正常运行示意图
在调试模式下运行时,程序会卡在输入进程中无法继续运行,按下“Enter”后也无法继续执行代码。
调试挂起示意图

已尝试的配置

初始launch.json配置

"version": "0.2.0",
"configurations": [
    {
        "type": "gdb",
        "request": "launch",
        "name": "Launch Program",
        "target": "./lesson_2/bin/lesson_2",
        "cwd": "${workspaceRoot}",
        "valuesFormatting": "parseText"
    }
]

尝试外部终端配置1

"version": "0.2.0",
"configurations": [
    {
        "type": "gdb",
        "request": "launch",
        "name": "Launch Program",
        "target": "./lesson_2/bin/lesson_2",
        "cwd": "${workspaceRoot}",
        "valuesFormatting": "parseText",
        "console": "externalTerminal",
        "debugOptions": [
            "RedirectOutput"
        ]
    }
]

尝试外部终端配置2

"version": "0.2.0",
"configurations": [
    {
        "type": "gdb",
        "request": "launch",
        "name": "Launch Program",
        "target": "./lesson_2/bin/lesson_2",
        "cwd": "${workspaceRoot}",
        "valuesFormatting": "parseText",
        "externalConsole": true
    }
]

尝试集成终端配置

额外添加参数:

"console": "integratedTerminal"

以上所有配置修改后问题无任何改善,使用的调试插件为Native Debug。

解决方案

该问题是Native Debug插件在Linux环境下默认未正确将stdin绑定到活动终端导致的,按照如下步骤修改即可解决:

  1. 打开launch.json配置文件,删除之前尝试添加的console、externalConsole、RedirectOutput相关参数
  2. 在配置段中添加"terminal": "integrated"参数,最终配置参考如下:
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "gdb",
            "request": "launch",
            "name": "Launch Program",
            "target": "./lesson_2/bin/lesson_2",
            "cwd": "${workspaceRoot}",
            "valuesFormatting": "parseText",
            "terminal": "integrated"
        }
    ]
}

如果需要使用外部终端,将"terminal"的值改为"external"即可,不需要额外添加其他控制台相关参数。
如果修改后仍有问题,可以检查本地gdb版本是否高于8.0,低版本gdb和新版VS Code的兼容性问题也可能引发类似输入无响应的故障,升级gdb到稳定最新版即可解决。

内容的提问来源于stack exchange,提问作者alexanderzhirov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 06:24:03