Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a cmake/make project in VSCode?

I'm making a project and in order to assist in building, I'm using CMake.

However, I notice that I can't debug.

Here's my launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug",
            "type": "gdb",
            "request": "launch",
            "target": "./build/bin/CHIP8",
            "cwd": "${workspaceRoot}",
            "preLaunchTask": "build"
        }
    ]
}

And here's my tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "cd build && cmake .. && make"
        }
    ]
}

I can't find anything online to help with this problem, so I'm really not sure where to go from here. VSCode docs has an example to debug where they use g++, but I'm using make --- so I'm not sure how to do it!

Thanks.

like image 258
Kevin Avatar asked Mar 31 '18 01:03

Kevin


1 Answers

It seems you built release version of your program. Try to build debug version of your program.

rm -r build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake --build .

It is better to separate debug and release builds.

mkdir Debug
cd Debug
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake --build .

With appropriate update of launch.json:

{
    "version": "2.0.0",
    "configurations": [
        {
            "name": "Debug",
            "type": "cppgdb",
            "request": "launch",
            "target": "./Debug/bin/CHIP8",
            "cwd": "${workspaceRoot}",
            "preLaunchTask": "build"
        }
    ]
}

Updated "type" according to VS Code updates. "type": "gdb" was previously

like image 90
273K Avatar answered Sep 28 '22 07:09

273K