简体   繁体   中英

Cannot Debug C++ in VS Code

I want to debug my C++ code in VSCode, but after I pressed F5 , the external console didn't pop up as expected.

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Debug",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,
            "internalConsoleOptions": "neverOpen",
            "MIMode": "gdb",
            "miDebuggerPath": "E:\\MinGW\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "Compile for Debug"
        }
    ]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Compile for Debug",
            "type": "shell",
            "command": "g++",
            "args": [
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}",
                "-g",
                "-Wall",
                "-Wextra",
                "-Wl,--stack=1024000000"
            ]
        }
    ]
}

When I press F5 , the window looks like this: enter image description here

It seems that the debug session runs normally (the bar in the red box), but as you can see, the external console doesn't appear.

PS My system is Windows 10 (x64), and the vscode is the latest.

From what I can tell looking at your picture, is that I the program stopped at your break point (I don't use the same version so I'm not entirely sure). You have to click next for your program to finish compiling. If you just want to see what your output is, no break points or anything, hit Crtl + F5.

Finally, I know how to solve that. It seems a bug of C/C++ extension.

I just set the option "Beta: Use Unicode UTF-8 for worldwide language support" in Windows OFF, and everything works.

More details can be found here . Thanks a lot to Github user @everything411.

You can follow this link to learn how to use C++ debugger in Linux :

VS Code Debugger for C++

This tutorial is the official tutorial by the Microsoft VS Code Community .

Follow the steps and you will get to know how to debug C++ files.

Note : You need to have a project folder and keep you .cpp inside it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM