简体   繁体   English

如何在 Mac 上的 VS Code 上调试 C++ 代码?

[英]How can I debug C++ code on VS Code on Mac?

I am trying to debug my C++ code in VS Code on Mac.我正在尝试在 Mac 上的 VS Code 中调试我的 C++ 代码。 I am able to compile it and run the executable, but when I launch the debugger using launch.json, it doesn't stop at breakpoints.我能够编译它并运行可执行文件,但是当我使用 launch.json 启动调试器时,它不会在断点处停止。 The breakpoints get greyed out and when I put the cursor on it, it says Unverified breakpoint.断点变灰,当我将光标放在上面时,它显示未验证断点。 And the call stack shows Unknown source.并且调用堆栈显示未知来源。 Am I missing something ?我错过了什么吗?

Launch.json code: 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": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/xyz",
            "preLaunchTask": "Makefile",
            "logging": {
                "moduleLoad": false,
                "programOutput": true,
                "trace": true
            },
            "args": ["--file", "file", "> abc.json"],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb"
        }
    ]
} 

tasks.json:任务.json:

    "version": "0.1.0",
    "command": "make",
    "isShellCommand": true,
    "tasks": [
        {
            "taskName": "Makefile",

            // Make this the default build command.
            "isBuildCommand": true,

            // Show the output window only if unrecognized errors occur.
            "showOutput": "always",

            // Pass 'all' as the build target
            "args": ["all"],

            // Use the standard less compilation problem matcher.
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": ["relative", "${workspaceRoot}"],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
    ]
} 

c_cpp_properties.json : c_cpp_properties.json :

    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "${workspaceRoot}/deps"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

for that follow below step为此,请遵循以下步骤

  1. opne work directory打开工作目录

  2. install extension安装扩展
    Name: C/C++ Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools名称:C/C++ 链接: https : //marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools

  3. open debug option and click on setting button that open launch.json file.打开调试选项并单击打开launch.json文件的设置按钮。
  4. you need to change program feild with your executed file with full path.您需要使用完整路径执行的文件更改程序字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM