Skip to content

Debugger hangs starting gdb.exe on Windows 10 with UTF-8 enabled. #1527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
weinand opened this issue Feb 7, 2018 · 39 comments · Fixed by microsoft/MIEngine#942
Closed

Debugger hangs starting gdb.exe on Windows 10 with UTF-8 enabled. #1527

weinand opened this issue Feb 7, 2018 · 39 comments · Fixed by microsoft/MIEngine#942
Assignees
Labels
bug debugger fixed Check the Milestone for the release in which the fix is or will be available.
Milestone

Comments

@weinand
Copy link

weinand commented Feb 7, 2018

From @leoliuasia on February 7, 2018 6:6

  • VSCode Version:1.19.3
  • OS Version: Windows 10 Pro 1709 16299.214

Steps to Reproduce:

  1. Debug->Start Debugging
  2. Nothing happens.... just hang in there with little blue block progressbar scrolling...

But when I force end task for gdb.exe in task manager window, vscode shows up an error, and little blue block disappears.

c_cpp_properties.json:

{
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}",
                "C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include\\c++"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE"
            ],
            "intelliSenseMode": "msvc-x64",
            "browse": {
                "path": [
                    "${workspaceRoot}",
                    "C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include\\c++"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }

task.json:

"tasks": [
        {
            "label": "build cpp",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "-o",
                "a.out",
                "main.cpp",
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]

launch.json

"configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\a.out",
            "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
                }
            ]
        }
    ]

Copied from original issue: microsoft/vscode#43075

@pieandcakes
Copy link
Contributor

@leoliuasia Can you enable "logging": { "engineLogging": true } and see where it stops while communicating with gdb?

@pieandcakes pieandcakes added debugger more info needed The issue report is not actionable in its current state labels Feb 7, 2018
@leoliuasia
Copy link

leoliuasia commented Feb 8, 2018

@pieandcakes Thanks for your time! Below are the output informations from the DEBUG CONSOLE after logging enabled.

  • 1: (267) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014'
  • 1: (283) LaunchOptions ExePath='c:\Users\Leo\Desktop\cpp\a.out'
  • 1: (283) LaunchOptions WorkingDirectory='c:\Users\Leo\Desktop\cpp'
  • 1: (283) LaunchOptions ExeArguments=''
  • 1: (283) LaunchOptions MIMode='gdb'
  • 1: (283) LaunchOptions MIDebuggerPath='C:\MinGW\bin\gdb.exe'
  • 1: (283) LaunchOptions WaitDynamicLibLoad='false'
  • 1: (283) LaunchOptions ExternalConsole='true'
  • 1: (283) LaunchOptions>
  • 1: (283) LaunchOptions
  • 1: (283) LaunchOptions -enable-pretty-printing
  • 1: (283) LaunchOptions
  • 1: (283) LaunchOptions
  • 1: (361) Starting: "C:\MinGW\bin\gdb.exe" --interpreter=mi
  • 1: (1914) DebuggerPid=9076
  • 1: (1982) ->=thread-group-added,id="i1"
  • 1: (1983) ->~"GNU gdb (GDB) 7.6.1\n"
  • 1: (1983) ->~"Copyright (C) 2013 Free Software Foundation, Inc.\n"
  • 1: (1983) ->~"License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law. Type "show copying"\nand "show warranty" for details.\n"
  • 1: (1983) ->~"This GDB was configured as "mingw32".\nFor bug reporting instructions, please see:\n"
  • 1: (1983) ->~"http://www.gnu.org/software/gdb/bugs/.\n"
  • 1: (1983) ->(gdb)
  • 1: (1992) <-1001-gdb-set target-async on
  • 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"."
  • 1: (1993) ->(gdb)
  • 1: (1993) ->&"\n"
  • 1: (1993) ->^done
  • 1: (1993) ->(gdb)

@leoliuasia
Copy link

@pieandcakes When this kind of things happens, I think the "Stop Debugging" should also be working, but it does not. The whole debug process only can start again util reopen the vscode.

@pieandcakes
Copy link
Contributor

@leoliuasia I don't know if you are using a different encoding, but for some reason gdb is receiving

1: (1992) <-1001-gdb-set target-async on
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"."

and the issue looks like ->&"\357\273\2771001-gdb-set target-async on\n" with the strangely escaped characters.

@WardenGnaw
Copy link
Member

@leoliuasia Can you run reg query "hklm\system\controlset001\control\nls\language" /v Installlanguage? This will help us understand which language you have enabled on your OS for us to recreate the issue.

@leoliuasia
Copy link

@WardenGnaw Below is the output:

D:\Integration Projects>reg query "hklm\system\controlset001\control\nls\language" /v Installlanguage
HKEY_LOCAL_MACHINE\system\controlset001\control\nls\language
Installlanguage REG_SZ 0409

@WardenGnaw
Copy link
Member

Could you also share what CodePage your OS is running? You can find this out by building and running the attached project.

You can build and run this by installing dotnet core at https://www.microsoft.com/net/learn/get-started/windows. Then unzip that project and run dotnet build and dotnet run.

You should see something similar to Your code page is 437 but with a different number.

CheckCodePage.zip

@WardenGnaw
Copy link
Member

Hi,

We may have a potential fix. Can you try installing this patched cpptools vsix and see if this fixes your issue?

cpptools.zip

Please uninstall the c/c++ extension that is already installed, then in the Extensions menu, click on the 3 dots and you should see install from vsix.

image

Thank you.

@bolu61
Copy link

bolu61 commented Feb 12, 2018

@WardenGnaw I ran into the exact same issue. My code page is 65001. The potential fix does not work.
@pieandcakes I believe that \357\273\277 is a BOM indicating UTF-8 encoding?

@pieandcakes
Copy link
Contributor

@MUTTSU which OS installation are you using? Please give the OS version and the locale that you installed so we can setup a proper test machine. We haven't been able to duplicate this issue here yet.

@bolu61
Copy link

bolu61 commented Feb 12, 2018

Im using win10pro build 17093.1000 (though i had this issue with older builds). Locale is en_CA.

Also I was wondering when the extension starts gdb, where does "set target-async on" come from? I couldn't figure out where in the extension's code it tries to put these configurations.

@pieandcakes
Copy link
Contributor

Do you have any additional language packs installed? are you using an input method other than English?

@bolu61
Copy link

bolu61 commented Feb 12, 2018

@pieandcakes I do have french, chinese and japanese keyboard layouts installed, but i use english(us) for coding. I noticed that vscode would switch my keyboard layout sometimes? it's weird

@WardenGnaw
Copy link
Member

@MUTTSU The "set target-async on" comes from MIEngine which the extension uses as part of the debug adapter.

https://github.com/Microsoft/MIEngine/blob/8e4eae7c0bc5b363ceef02002c95db9384f1ec29/src/MICore/CommandFactories/gdb.cs#L203

@leoliuasia
Copy link

@WardenGnaw My CodePage is 65001. The potential fix does not work.

@pieandcakes
Copy link
Contributor

@leoliuasia What region is your English keyboard setting?

@leoliuasia
Copy link

@pieandcakes English(United States) with keyboard layout: US.

@pieandcakes
Copy link
Contributor

@leoliuasia @MUTTSU we are having problems reproducing this issue.

I’ve tried installing non-US windows and changing locales and keyboards but I can’t seem to get my Windows installation to report code page 65001. Can either of you provide some guidance as to what other configuration you did? It doesn’t matter what I change I still get my base code page.

Win 10 installation: Simplified Chinese
keyboards installed: en-us, en-ca and en-Uk
Locale: en-ca

Encoding: 936

@bolu61
Copy link

bolu61 commented Mar 8, 2018

@pieandcakes I think I had the beta option that let me use some universal UTF-8 encoding in locale settings. I'm going to uncheck that and see if it works.
Edit: It worked, but I also changed the locale to en-US, so I can't tell which actually solved the problem. I'm pretty sure that this setting was not there until recent insider releases...

@kinokn
Copy link

kinokn commented Jun 11, 2018

@pieandcakes @MUTTSU Same problem and I've fixed it by disabling unicode UTF-8 encoding in region settings and current system locate is Chinese (Simplified, China)

@pieandcakes
Copy link
Contributor

@MUTTSU @KIRI-Z We haven't found a good solution beyond having users disable Unicode UTF-8 encoding.

@KIRI-Z Do you have a good set of steps that users can use to disable this setting? If so, please share it here so users know how to work around the problem.

@kinokn
Copy link

kinokn commented Jun 12, 2018

@pieandcakes Sure.
The unicode UTF-8 (region setting) is a beta feature in Windows10 1803 which is disabled by default.
It is at Control Panel - Clock and Region - Region - Administrative - Change system locate (administrator authorization required) - Beta: Use Unicode UTF-8 for worldwide language support (system reboot needed). Disable it maybe helpful.

@pieandcakes pieandcakes changed the title why vscode just hang in there when start debugging with gdb.exe? Debugger hangs starting gdb.exe on Windows 10 with UTF-8 enabled. Jun 13, 2018
@pieandcakes pieandcakes added bug and removed more info needed The issue report is not actionable in its current state labels Jun 13, 2018
@Summon528
Copy link
Contributor

Summon528 commented May 15, 2019

Is this actually fixed? cause debugger still hangs if I enable UTF-8. I'm using v0.23.1

@pieandcakes pieandcakes reopened this May 15, 2019
@pieandcakes
Copy link
Contributor

@Summon528 No I think this was closed by accident. The codepage issue has not been fixed. I have been unable to determine why we are receiving a UTF-8 BOM from gdb and unfortunately this is still causing problems.

@Iamnvincible
Copy link

I encounter the same problem, and my Beta: Use Unicode UTF-8 for worldwide language support is enabled.
Just make Beta: Use Unicode UTF-8 for worldwide language support unchecked can solve the problem.
Thanks

@pieandcakes pieandcakes removed the fixed Check the Milestone for the release in which the fix is or will be available. label Aug 20, 2019
@phanthaiduong22
Copy link
Member

phanthaiduong22 commented Sep 8, 2019

I have the same problems: i cannot type input when debug. I reinstall window yesterday.
I tried Beta: Use Unicode UTF-8 for worldwide language support unchecked. But it does not work.https://imgur.com/a/0rJtOVL

@pieandcakes
Copy link
Contributor

@phanthaiduong22 if you would like help, please post an engine log and more additional information.

@rivy
Copy link

rivy commented Sep 15, 2019

@pieandcakes , Any status on fixing this?

As a workaround...

  1. add a "gdb-with-chcp.BAT" within to your project (eg, "dbin/gdp-with-chcp.BAT"):
@:: gdb-with-chcp.BAT
@chcp 1257 >NUL 2>&1 && @"gdb.exe" %*
  1. use "PATHTO/gdb-with-chcp.BAT" as "miDebuggerPath" within "launch.json"
// eg
// ...
"miDebuggerPath": "${workspaceFolder}/dbin/gdb-with-chcp.BAT",
// ...

@pieandcakes
Copy link
Contributor

pieandcakes commented Sep 16, 2019

We are trying to determine what needs to happen to block sending of the BOM to gdb. Our problem is that the pipe we create when Unicode is enabled is causing a BOM to be sent on the gdb side of the communication pipe which causes gdb to generate an error.

We have a repro but not a good way to make a fix unfortunately.

@phanthaiduong22
Copy link
Member

@phanthaiduong22 if you would like help, please post an engine log and more additional information.
https://imgur.com/a/dzySuvV

I just install Window yesterday so Beta: Unicode UTF-8 for worldwide language support was already disabled. But when i debugging i still can't type in terminal my input( like image i want to type a,b but it doesn't work.

OS: win10 pro
Version: 1.38.1 (user setup)
Commit: b37e54c98e1a74ba89e03073e5a3761284e3ffb0
Date: 2019-09-11T13:35:15.005Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.18362
Extension: C/C++, Version 0.25.1: August 28, 2019

Here is my .vscode : https://pastebin.com/SE3gmACy

@pieandcakes
Copy link
Contributor

The UTF8 issue is not the issue you are running into @phanthaiduong22. It looks like its waiting for input but i don't see you typing anything in the terminal. You can also try "externalConsole": true to see if that provides the experience you are looking for. It might be clearer if you first cout something so you can see it in the terminal window.

@phanthaiduong22
Copy link
Member

Actually, I typed a,b (ex: 3 4) in temminal in vscode . but nothing happened.

@z7z8th
Copy link

z7z8th commented Oct 20, 2019

This issue blocked me several days until I know it's caused by UTF BOM.
After some debugging, I found that the BOM does not come from the PIPE, but comes from the input stream of the debugger(gdb for me).

In file https://github.com/microsoft/MIEngine/blob/master/src/WindowsDebugLauncher/DebugLauncher.cs :
I think the UTF BOM is already in the BaseStream when creating the debugger process.
So the following line did not remove the BOM.

_debuggerCommandStream = new StreamWriter(_dbgProcess.StandardInput.BaseStream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)) { AutoFlush = true };

Two possible solutions:

  1. flush the UTF8 BOM individually:
    Add the following lines after https://github.com/microsoft/MIEngine/blob/ccec0b00986ca4606b19291a3a3fcf986e5728a6/src/WindowsDebugLauncher/DebugLauncher.cs#L135
_debuggerCommandStream.WriteLine();
_debuggerCommandStream.Flush();

Log after this change:

1: (993) ->~"For help, type \"help\".\n"
1: (994) ->~"Type \"apropos word\" to search for commands related to \"word\".\n"
1: (996) ->(gdb)
1: (996) ->&"\357\273\277\n"
1: (996) ->&"Undefined command: \"\".  Try \"help\".\n"
1: (996) ->^error,msg="Undefined command: \"\".  Try \"help\"."
1: (996) ->(gdb)
1: (1000) <-1001-gdb-set target-async on
1: (1005) Send Event AD7MessageEvent
1: (1007) ->1001^done
1: (1007) ->(gdb)
1: (1007) ->&"\n"
1: (1007) ->^done
1: (1007) ->(gdb)
1: (1007) 1001: elapsed time 6
1: (1014) <-1002-enable-pretty-printing
  1. change the encoding of the console of windowsdebugadapter.exe, so the debugger inherits it's settings
    Add the following line before _dbgProcess.Start(); in https://github.com/microsoft/MIEngine/blob/master/src/WindowsDebugLauncher/DebugLauncher.cs
Console.InputEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);

Log after this change:

1: (993) ->~"Type \"apropos word\" to search for commands related to \"word\".\n"
1: (995) ->(gdb)
1: (999) <-1001-gdb-set target-async on
1: (1005) ->1001^done
1: (1005) ->(gdb)
1: (1005) ->&"\n"
1: (1005) ->^done
1: (1005) ->(gdb)
1: (1006) 1001: elapsed time 7
1: (1012) <-1002-enable-pretty-printing

I tested the 2nd solution with English+UTF8, Chinese+UTF-8 and Chinese+Unicode(UTF16), all works.

The 2nd solution seems cleaner if no other impact.

@phanthaiduong22
Copy link
Member

  1. DebugLauncher.cs

Excuse me, Where is DebugLauncher.cs located in my computer.

Thanks

@z7z8th
Copy link

z7z8th commented Oct 21, 2019

@phanthaiduong22
You need to download the MIEngine source code to get that file. It's part of the source code of the c/c++ extension. the source code needed to be built in visual studio to generate windowsdebugadapter.exe and serveral other files. but your problem is not related to this issue.

@pieandcakes
Copy link
Contributor

@z7z8th Thank you for your investigation. Let me take that fix and do some additional testing.

Thanks!

@pieandcakes pieandcakes self-assigned this Oct 25, 2019
@pieandcakes pieandcakes added the fixed Check the Milestone for the release in which the fix is or will be available. label Oct 25, 2019
@pieandcakes pieandcakes added this to the 0.26.1 milestone Oct 25, 2019
@michelleangela
Copy link
Contributor

Fixed in 0.26.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug debugger fixed Check the Milestone for the release in which the fix is or will be available.
Projects
None yet
Development

Successfully merging a pull request may close this issue.