C / C ++ VS代码-无法开始调试。启动管道程序时出错

时间:2019-10-05 22:36:00

标签: c++ c bash visual-studio-code windows-subsystem-for-linux

我正在学习Visual Studio Code C / C ++调试工具,并且在遵循教程here以及开始进行调试时。我收到此错误。

enter image description here

我在Ubuntu上运行WSL / Bash,并在WSL上安装了gcc / g ++和gdb。

这是我在launch.json中的代码。非常感谢您的帮助。

{
"version": "0.2.0",
"configurations": [
  {
    "name": "(gdb) Launch",
    "type": "cppdbg",
    "request": "launch",
    "program": "/mnt/c/Users/myusername/Projects/CPP/helloworld/helloworld.out",
    "args": [""],
    "stopAtEntry": true,
    "cwd": "/mnt/c/Users/myusername/Projects/CPP/helloworld/",
    "environment": [],
    "externalConsole": true,
    "windows": {
      "MIMode": "gdb",
      "miDebuggerPath": "/usr/bin/gdb",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    },
    "pipeTransport": {
      "pipeCwd": "",
      "pipeProgram": "C:\\Windows\\System32\\bash.exe",
      "pipeArgs": ["-c"],
      "debuggerPath": "/usr/bin/gdb"
    },
    "sourceFileMap": {
      "/mnt/c": "C:\\",
      "/usr": "C:\\Users\\myusername\\AppData\\Local\\Packages\\CanonicalGroupLimited.UbuntuonWindows79rhkp1fndgsc\\LocalState\\rootfs\\usr\\"
    }
  }
]
}

1 个答案:

答案 0 :(得分:0)

我遇到了同样的错误,终于让它起作用了!

两项更改:

1)在pipeTransport下,更改pipeProgram:       "pipeProgram": "bash.exe"

2)在SourceFileMap下:  删除/usr

这是我完整的launch.json文件(只需用您的用户名替换USERNAME):

{
    "version": "0.2.0",
    "configurations": [

      {
        "name": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "/home/USERNAME/projects/helloworld/helloworld.out",
        "args": [""],
        "stopAtEntry": true,
        "cwd": "/home/USERNAME/projects/helloworld/",
        "environment": [],
        "externalConsole": true,
        "windows": {
          "MIMode": "gdb",
          "miDebuggerPath": "/usr/bin/gdb",
          "setupCommands": [
            {
              "description": "Enable pretty-printing for gdb",
              "text": "-enable-pretty-printing",
              "ignoreFailures": true
            }
          ]
        },
        "pipeTransport": {
          "pipeCwd": "",
          "pipeProgram": "bash.exe", 
          "pipeArgs": ["-c"],
          "debuggerPath": "/usr/bin/gdb"
        },
        "sourceFileMap": {
          "/mnt/c": "c:\\",
        }
      }
    ]
  }