首页 > 解决方案 > macOS 上带有 c++ ext 的 VS Code 无法调试我的代码

问题描述

我安装了插件并编写了默认配置,但是断点和调用堆栈并没有绑定到 vs 代码。

启动.json:

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

    {
      "name": "(lldb) Launch",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}.o",
      "args": [],
      "stopAtEntry": true,
      "cwd": "${fileDirname}",
      "environment": [],
      "externalConsole": true,
      "MIMode": "lldb"
    }
  ]
}

任务.json:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build",
      "command": "clang++",
      "args": [
        "-Wall",
        "-std=c++17",
        "-g",
        "-o",
        "${fileBasenameNoExtension}.o",
        "${fileBasename}",
      ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": {
        "owner": "cpp",
        "fileLocation": [
          "relative",
          "${fileDirname}"
        ],
        "pattern": {
          "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
          "file": 1,
          "line": 2,
          "column": 3,
          "severity": 4,
          "message": 5
        },
      },
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "presentation": {
        "echo": true,
        "reveal": "never",
        "focus": false,
        "panel": "shared",
        "showReuseMessage": true,
        "clear": false
      }
    }
  ]
}

输出(应用程序刚刚在断点停止时执行):

Loaded '/Users/mxtnr/xp/coursera-cpp/practices/1.o'. Symbols loaded.

Execute debugger commands using "-exec <command>", for example "-exec info registers" will list registers in use (when GDB is the debugger)

The program '/Users/mxtnr/xp/coursera-cpp/practices/1.o' has exited with code 0 (0x00000000).

我究竟做错了什么?

标签: visual-studio-code

解决方案


@atombit,只是,替换g++clang++


推荐阅读