How do I get my breakpoints to work in VSCode?

Viewed 43

I'm trying to debug this C source file in VS Code on Windows 10:

#include <stdio.h>
#include <stdlib.h>

int main(void){

    printf("Test 1\n");
    printf("Test 2\n");
    printf("Break here\n");
    printf("Test4\n");
    system("pause");
    return 0;

}

But when I do, all breakpoints are ignored by the debugger. It says "No symbols have been loaded for this document." as seen below: Screenshot of VS Code during debugging session.

I've read that the -g flag is required to be passed to g++ in order to be debugged, but even though it's there, I still get the same "No symbols have been loaded for this doucment." message.

tasks.json:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "[!] C/C++: g++.exe build active file",
            "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-static"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler: C:\\msys64\\mingw64\\bin\\g++.exe"
        },
    ],
    "version": "2.0.0"
}

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "console": "integratedTerminal",
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
            "preLaunchTask": "[!] C/C++: g++.exe build active file"
        }
    ],
    "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe"
}

Is there anything else I need to do to get the breakpoints to work?

1 Answers

I narrowed down the problem. In the launch.json, I changed "type": "cppvsdbg" to "type": "cppdbg" as seen below:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            // "console": "integratedTerminal",
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
            "preLaunchTask": "[!] C/C++: g++.exe build active file"
        }
    ],
    "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe"
}

And now all the breakpoints are working properly.

Related