vs code c ++ breakpoint无法在mac中运行

时间:2017-01-16 11:31:02

标签: c++ macos debugging visual-studio-code

我的os版本是sierra 10.12.1,vs代码版本是1.8.1。我在vs代码中安装了c ++插件。然后我创建了一个c ++项目。 有我的c ++源文件。

my_simple.cc

int main(int argc, char const *argv[])
{
    printf("%s\n", "******begin******");
    int a = 1;
    int b = a;
    printf("%s\n", "******end******");
    return 0;
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "preLaunchTask": "pre_compile",
            "showDisplayString": true,
            "name": "my_debug",
            "type": "cppdbg",
            "request": "launch",
            "program": "${file}.o",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": false,
            "osx": {
                "MIMode": "lldb"
            }
        }
    ]
}

tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "g++",
    "isShellCommand": true,
    "args": [
    ],
    "showOutput": "always",
    "echoCommand": true,
    "suppressTaskName": true,
    "tasks": [
        {
            "taskName": "pre_compile",
            "args": [
                "${file}",
                "-o${file}.o"
            ],
            "isBuildCommand": true
        }
    ]
}

当我向my_simple.cc添加一些断点然后按f5编译并运行它。断点没有按预期工作。请帮我在代码中找到错误。感谢

1 个答案:

答案 0 :(得分:1)

1)使用:

创建新的CMakeList.txt
cmake_minimum_required(VERSION 3.0)
project(FirstProgram)
set(SOURCE Hello.cpp)
add_executable(${PROJECT_NAME} ${SOURCE})

2)Task.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "sh",
    "isShellCommand": true,
    "args": ["-c"],
    "showOutput": "always",
    "suppressTaskName": true,
    "options": {
        "cwd": "${workspaceRoot}/build"
    },
    "tasks": [
        {
            "taskName": "cmake",
            "args": ["cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Debug .."]     
        },
        {
            "taskName": "make",
            "args": ["make -j 8"],
            "isBuildCommand": true            
        }
    ]
}

3)launch.json:

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

            "showDisplayString": true,
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/Build/FirstProgram",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb"
        }
    ]
}

4)任务运行 - > cmake然后:make