无法使用gdb

时间:2018-06-11 07:29:45

标签: c++ debugging visual-studio-code gdb mingw

我正在尝试在Visual Studio Code中调试C ++,但这里出了点问题。 调试状态保持滚动,但没有控制台显示。如果我停止调试(shift + F5),我将无法再次调试。无论是点击绿色三角形还是F5,都没有任何反应。 Debug screenshot

建筑还可以。这只是调试问题 MinGW已被添加到PATH中。我可以在CMD中使用g ++或gdb。

我的环境:

  • 操作系统:Windows10 1803
  • Visual Studio代码:1.24.0
  • C / C ++扩展名:0.17.4
  • MinGW_w64:x86_64-8.1.0-release-posix-seh-rt_v6-rev0

以下是我的配置:

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "C:/MinGW/include",
                "C:/MinGW/x86_64-w64-mingw32/include",
                "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include",
                "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
                "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
                "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1",
                "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
                "${workspaceFolder}"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE"
            ],
            "compilerPath": "C:/MinGW/bin/gcc.exe",
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "C:/MinGW/include",
                    "C:/MinGW/x86_64-w64-mingw32/include",
                    "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include",
                    "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
                    "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
                    "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1",
                    "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
                    "${workspaceFolder}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "cStandard": "c11",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "preLaunchTask": "build",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:/MinGW/bin/gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "windows": {
                "command": "g++",
                "args": [
                    "-g",
                    "\"${file}\"",
                    "--std=c++11",
                    "-o",
                    "\"${fileDirname}\\${fileBasenameNoExtension}.exe\""
                ]
            }
        }
    ]
}

settings.json

{
    "files.associations": {
        "iostream": "cpp",
        "ostream": "cpp",
        "cmath": "cpp",
        "array": "cpp",
        "chrono": "cpp",
        "functional": "cpp",
        "ratio": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "utility": "cpp",
        "future": "cpp",
        "streambuf": "cpp",
        "sstream": "cpp",
        "initializer_list": "cpp",
        "valarray": "cpp"
    }
}

1 个答案:

答案 0 :(得分:4)

我发现这是一个编码问题,我自己解决了。

首先,尝试gdb日志记录以确定您是否遇到了同样的问题。
启用"logging": { "engineLogging": true },如果您看到类似

的内容
1: (1992) ->&"\357\273\2771001-gdb-set target-async on\n"
1: (1993) ->&"Undefined command: "\357". Try "help".\n"
1: (1993) ->^error,msg="Undefined command: "\357". Try "help"."

然后你有同样的问题。

要解决此问题,您需要禁用 Unicode UTF-8以获得全球语言支持,这是自Windows10 1803以来的测试版功能,默认情况下处于禁用状态。
它位于控制面板 - 时钟和区域 - 区域 - 管理 - 更改系统位置(需要管理员授权) - Beta:使用Unicode UTF-8进行全球语言支持(需要重启系统)。

转到GitHub的why vscode just hang in there when start debugging with gdb.exe?了解更多详情。