无法使用gdb在VS代码中调试C.

我正在尝试在Visual Studio Code中调试C,但这里有些错误.
调试状态保持滚动,但没有控制台显示.如果我停止调试(转换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"
    }
}

解决方法:

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

首先,尝试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以来的测试版功能,默认情况下处于禁用状态.
它位于控制面板 – 时钟和区域 – 区域 – 管理 – 更改系统定位(需要管理员授权) – 测试版:使用Unicode UTF-8进行全球语言支持(需要重新启动系统).

有关详细信息,请访问GitHub上的why vscode just hang in there when start debugging with gdb.exe?.

上一篇:c – 无法解析Eclipse C/C++函数’printf’


下一篇:VSCode在windows下使用MinGW-w64的gcc/g++编写调试程序