簡體   English   中英

如何在 Mac 上的 VS Code 上調試 C++ 代碼?

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

我正在嘗試在 Mac 上的 VS Code 中調試我的 C++ 代碼。 我能夠編譯它並運行可執行文件,但是當我使用 launch.json 啟動調試器時,它不會在斷點處停止。 斷點變灰,當我將光標放在上面時,它顯示未驗證斷點。 並且調用堆棧顯示未知來源。 我錯過了什么嗎?

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"
        }
    ]
} 

任務.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 :

    "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
}

為此,請遵循以下步驟

  1. 打開工作目錄

  2. 安裝擴展
    名稱:C/C++ 鏈接: https : //marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools

  3. 打開調試選項並單擊打開launch.json文件的設置按鈕。
  4. 您需要使用完整路徑執行的文件更改程序字段。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM