VSCode 调试C++启动外部终端,但不运行程序



我已经设置了一个launch.json文件,这样C++程序就可以使用外部控制台(这样它就可以接收用户输入(,但在启动时,VSCode只是打开一个终端窗口,而不在其中运行程序。如果"externalConsole": true,设置为false,则程序可以运行并调试良好,只是不能接受输入。

注意:没有使用task.json文件,CMake用于创建可执行二进制文件。

启动文件:

{
// 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++ - Debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/bin/program_bin",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/bin",
"environment": [],
"MIMode": "lldb",
"externalConsole": true,
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true,
}
]
}
]
}

VSCode是否可能没有运行外部终端的"权限"?在MacOS上使用。

我也有同样的问题。这可能不是一个有效的答案,但希望它能让我们走上正确的道路。

我做了一些挖掘,发现了以下内容:

  • VS代码文档提到它通过lldb-mi打开了一个外部控制台
  • 搜索lldb mi后,苹果开发者论坛上出现了这篇帖子
  • 。。。这导致了一个开源的Github Repo,构建了lldb-mi

我需要先通读该构建的文档,然后再尝试一下。如果它解决了问题,我会发布结果。

我曾尝试使用标准(从vscode文档中推荐的调试方法(,但在外部终端上遇到了同样的问题。

我也在使用mac并切换到CodeLLDB插件来使用LLDB进行调试帮助

https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb

只需遵循文档:https://github.com/vadimcn/vscode-lldb/blob/v1.8.1/MANUAL.md

但作为一个提示,这里是我的工作设置:(虽然我不能让它在windows上工作,但我通过Parallel II运行windows,所以也许这个插件在本机上也能工作(

tasks.json

{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang build active file",
"command": "/usr/bin/g++",
"args": [
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-g", 
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

launch.json

{
"configurations": [
{
"name": "(lldb) Launch",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
// "stdio": ["input.txt", null, null], // https://github.com/vadimcn/vscode-lldb/blob/v1.8.1/MANUAL.md#stdio-redirection
"cwd": "${fileDirname}",
"preLaunchTask": "C/C++: clang build active file" // this have to be the same as "label" in tasks.json
}
],
"version": "2.0.0"
}

只需确保您拥有所有可用的工具,即可通过在cli:中运行进行检查

/usr/bin/clang --version
# and
lldb --version

祝好运

最新更新