首页 > 解决方案 > 如何在 macOS 上的 vscode 上调试 C++ 时添加用户输入

问题描述

在 VScode 上调试时如何添加用户输入?

我试过以下

不管一步一步地遵循上述方法,有些事情是错误的。

我不断得到一个窗口,我无法做任何事情。上/下/入按钮无效。

在我的 launch.json 文件中

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++-10 - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "lldb",
            "preLaunchTask": "C/C++: g++-10 build active file"
        }
    ]
} 

这是我的tasks.json文件

{
    "tasks": [

        {
            "type": "shell",
            "label": "C/C++: g++-10 build active file",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-std=c++17",
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
    "version": "2.0.0"
}

系统详情

Version: 1.48.1
Commit: 3dd905126b34dcd4de81fa624eb3a8cbe7485f13
Date: 2020-08-19T17:09:41.484Z
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 20.0.0

标签: debuggingvisual-studio-code

解决方案


解决方案在这里的要点中给出

问题是当 VSCode 启动调试适配器时,调试适配器启动 lldb-mi,然后 lldb-mi 启动终端。应该出现一个提示,但不知何故 DebugAdapter 没有转发此权限请求。

解决方法是让 VS Code 启动终端一次。您可以通过在您的tasks.json

{
  "label": "Open Terminal",
  "type": "shell",
  "command": "osascript -e 'tell application \"Terminal\"\ndo script \"echo hello\"\nend tell'",
  "problemMatcher": []
}

您可以使用 Command + Shift + p 运行此特定任务。键入任务并查找任务:运行任务,然后选择打开终端。

我已经写了一篇关于相同的小博客文章,详细说明了每一步的图片,可以在这里找到。


推荐阅读