vs code c++ debug配置

  1. 配置tasks.json编译c++项目
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "cmake",
            "type": "shell",
            "command": "cmake",
            "args": [
                "-G",
                "Unix Makefiles",
                "-DCMAKE_BUILD_TYPE=Debug",
                "-DAPP_NAME=yw",
                ".."
            ],
            "options": {
                "cwd": "${workspaceFolder}/build"
            },
            "group": "build",
            "detail": "CMake template build task"
        },
        {
            "label": "make",
            "type": "shell",
            "command": "make",
            "args": [
                "-j6"
            ],
            "options": {
                "cwd": "${workspaceFolder}/build"
            },
        },
        {
            "label": "Build",
            "dependsOrder": "sequence",
            "dependsOn": [
                "cmake",
                "make"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
    ],

    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": [
            "relative",
            "${workspaceFolder}/build"
        ],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }
}
  1. 配置launch.json debug
{
    // 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": "yw",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/yw",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }

    ]
}
posted @ 2024-05-15 11:46  RenjieW  阅读(9)  评论(0)    收藏  举报