debugging - 如何在 macOS 上的 vscode 上调试 C++ 时添加用户输入
问题描述
在 VScode 上调试时如何添加用户输入?
我试过以下
- 编辑了我的 launch.json 以设置
externalConsole : true
- 尝试将输入作为命令行参数提供,如此处所述
不管一步一步地遵循上述方法,有些事情是错误的。
我不断得到一个窗口,我无法做任何事情。上/下/入按钮无效。
在我的 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
解决方案
解决方案在这里的要点中给出
问题是当 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 运行此特定任务。键入任务并查找任务:运行任务,然后选择打开终端。
我已经写了一篇关于相同的小博客文章,详细说明了每一步的图片,可以在这里找到。
推荐阅读
- php - 在没有 httponly 标志的情况下创建的 Cookie XSRF-TOKEN - Laravel 5.8
- flutter - Flutter - 将背景渐变应用于可滚动视图
- python - 使用字典标记句子中的单词
- curl - OpenSSL SSL_connect:SSL_ERROR_SYSCALL 连接到 ubuntu 上的 storage.googleapis.com:443
- python - 创建图表时出现未知索引错误
- python - 找到一组特征向量的对应特征值
- android - 如何签署 Expo 应用程序 APK 以更新 Google Play 商店中的现有应用程序?
- google-cloud-platform - 为什么 terraform 创建的负载均衡器无法连接我的后端?
- python - 在 python 中使用 ARIMA 并进行集成时,如何使预测未集成?
- javascript - 未捕获的类型错误:无法读取未定义的属性“toFixed”