0

I am having trouble getting the F5 debugger to work properly.

I have been trying to follow the Microsoft tutorial to get things going, but after building successfully the debugging process never really works out the way it should.

When I use the Ctrl + Shift + B command to build, it successfully creates a main.exe file, but I cannot change the launch.json file in a way that works hand-in-hand.

While tasks.json has this "-o","${fileDirname}\\${fileBasenameNoExtension}.exe" as the object path/name, 'main.cpp' is compiled into main.exe.

So, initially, I had tried to set launch.json to have program": ${fileDirname}\\${fileBasenameNoExtension}.exe. Which would be neat and effective, matching the build file that would be produced.

I get this error: screenshot

Next, I tried to change launch.json to run as a.exe hardcoded. In the PS terminal within VSCode, I ran g++ .\main.cpp and produced an a.exe file. Which successfully allows F5 debugging giving me an exit code '0' in the debug console when I changed launch.json to have "program": "${workspaceFolder}\\a.exe".

I have also tried to use ${workspaceFolder}\\${fileBasenameNoExtension}.exe with no luck.

It makes no logical sense to me that the same parameters for cwd with the same object name in tasks won't run successfully for debugging in launch.

The entire tasks.json:

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

The entire launch.json:

{
    "configurations": [
    {
        "name": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}\\a.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${fileDirname}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
        "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
            }
        ]
    }
    ]
}

Could someone please take a look for me? This is infuriating.. Thanks in advance!

1
  • 1
    Please don't add "solved" to the title, nor edit the solution into your question. Instead, post the solution as an "answer" below, and press the checkmark next to it to mark your question as solved. Commented Feb 12, 2022 at 20:14

1 Answer 1

2

I figured out the problem. Hopefully will help someone else, too.

First I updated the architecture portion of the options for launch.json - not relevant to the file-path issue, but figured I would mention. Add "targetArchitecture": "x64"(or the 32bit option if necessary) to the tasks.json file.

==================================================================

Solution: After fiddling around a bit I have found that tasks.json was the issue, not launch.json. After a good amount of confusion I took a break and came back to the problem and noticed that tasks was running cpp.exe to build the file. Out of curiosity I replaced it with g++.exe and voilà - it works.

So, if you have issues with using F5 in VSCode with MinGW for compiling/debugging - ensure that g++.exe is compiling. At least from my limited knowledge, that should fix the issue if you are running VSCode and using MinGW for building/debugging.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.