Naveen Singla
Naveen Singla

Reputation: 76

Not able to debug my c++ code in visual studio code

I don't what happened to my vscode all of a sudden I am not able to debug files although I am to run my CPP program but not able to debug please help me I spend 2-3 hours continuously trying to fix my debugger

my program is running fine and compiler is creating a exe file as shown below enter image description here

when I hit the debug button this image appears enter image description here

and then it stuck on this screen enter image description here

when I press any kind of key it exits and the normal terminal window appears enter image description here

it is just like it is trying to open the external terminal but not able to open it some how this is what i think spending a whole day solving this problem

Lauch.json file

{
    // 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": "g++.exe - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file"
        }
    ]
}

Task.json

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

Upvotes: 0

Views: 6769

Answers (2)

Andrej
Andrej

Reputation: 29

Try add -g to flags. -g is flag to enable debugging.

Upvotes: 0

Ravindra
Ravindra

Reputation: 38

Deleting the

  1. %USERPROFILE%.vscode\extensions\ms-vscode.cpptools-1.6.0-insiders\install.lock
  2. %USERPROFILE%.vscode\extensions\ms-vscode.cpptools-1.6.0-insiders\debugAdapters

worked for me. Windows 10

for more information Please see: https://github.com/microsoft/vscode-cpptools/issues/7971

Upvotes: 1

Related Questions