Windows 10 的 Unicode新特性导致 VS Code 无法debug gdb

因为需要在Windows下调试一个基于C语言的开源工具,调试环境为VS Code、Microsoft C/C++ Extension、GCC和GDB环境(Mingw-w64)。

按照VS Code官方文档Using Mingw-w64 in VS Code一步一步搭建好调试环境,编译很顺利通过了。

但是调试的时候出问题了。在VS Code中按F5启动Debug,VS的终端(Terminal)中输出了一段命令:c:\Users\efrey\.vscode\extensions\ms-vscode.cpptools-0.25.0\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-gkkeppw1.hde --stdout=Microsoft-MIEngine-Out-frcxsnxq.e4y --stderr=Microsoft-MIEngine-Error-htrolgld.kn1 --pid=Microsoft-MIEngine-Pid-mjgquuhh.yua --dbgExe=C:/mingw-w64/mingw64/bin/gdb.exe --interpreter=mi,然后就一直停在那里了,VS Code的Debug视图左上角也一直在显示正在加载的滚动进度条。
此时除了终端窗口(Terminal)无响应,输出(Output)、调试控制台(Debug Console)也没有任何信息。

停掉调试器,在VS Code中配置开启日志,即将"logging": { "engineLogging": true },加入到launch.json文件,配置后文件如下:

{
    // 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": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:/mingw-w64/mingw64/bin/gdb.exe",
            "logging": { "engineLogging": true },
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

重启按下F5启动调试,终端窗口还是和之前一样,停在那里。不过在调试控制台里可以看到调试启动的日志了,发现其中有一段提示错误的信息:"\357\273\2771001-gdb-set target-async onUndefined command: \"\357\"

DEBUG CONSOLE
1: (119) LaunchOptions  MIMode='gdb'
1: (119) LaunchOptions  MIDebuggerPath='C:/mingw-w64/mingw64/bin/gdb.exe'
...
1: (496) ->(gdb)
1: (500) <-1001-gdb-set target-async on
1: (500) ->&"\357\273\2771001-gdb-set target-async on\n"
1: (500) ->&"Undefined command: \"\357\".  Try \"help\".\n"
1: (500) ->^error,msg="Undefined command: \"\357\".  Try \"help\"."
...

未定义的命令中的357看起来像是Unicode字符集的格式,导致了gdb无法识别因此报错。想起了自己好像在更改系统区域设置中开启了一个测试版的Unicode UTF8的特性支持。

控制面板中依次进入时钟和区域>区域,点击更改位置,然后切换到管理页,进入更改系统区域设置,然后取消勾选Beta版:使用Unicode UTF8提供全球语言支持(U)复选框。
重启电脑后,打开VS Code,按下F5,调试器正常的运行并停在源文件的断点位置了。

你可能感兴趣的:(c,debug,windows-10,unicode)