Ubuntu vscode cmake c/c++ 断点调试

  1. 安装c/c++插件“C/C++ -- C/C++ IntelliSense, debugging, and code browsing.”
  2. 添加launch.json, 具体内容见下方。
  3. 添加tasks.json,具体内容见下方。

launch.json,主要preLaunchTask对cmake编译任务的引用。

{
    // 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": "Luanch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/hello",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "cmake build",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

tasks.json, 注意先手动生成build文件夹,cmake的Debug参数也很重要。

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "cmake build",
            "command": "cd ./build ;cmake ../ -DCMAKE_BUILD_TYPE=Debug;make",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
    ]
}

标签: ubuntu

添加新评论