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

wlwcrazw  于 2022-12-23  发布在  Vscode
关注(0)|答案(2)|浏览(581)

我已经设置了一个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上使用。

pexxcrt2

pexxcrt21#

我也有同样的问题。这可能不是可行的答案,但希望它能使我们在正确的道路上走得更远。
我做了一些调查,发现了以下内容:

  • VS代码文档mentioned,它通过lldb-mi打开外部控制台。
  • 在苹果开发者论坛上搜索lldb-mi会得到this post
  • ......这导致了带有lldb-mi构建版本的开源Github Repo

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

drnojrws

drnojrws2#

我试过使用标准(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

祝好运

相关问题