Type: Debugger
When using this method for C++ debugging using WSL, GDB fails to find the path passed by -environment-cd, this error is displayed instead:

However, GDB changes working directories normally when executed from the command line or WSL. This and the error message led me to believe there is an encoding bug in how the cwd is passed to GDB.
So I tried the same in C:\Users\Public\Documents\Cpp, it ran normally.
To Reproduce
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": "WSL Launch",
"type": "cppdbg",
"request": "launch",
"preLaunchTask": "g++ build active file",
"program": "/mnt/c/Users/Vítor/Desktop/Programação/Cpp/${fileBasenameNoExtension}.out",
"stopAtEntry": false,
"cwd": "/mnt/c/Users/Vítor/Desktop/Programação/Cpp",
"environment": [],
"externalConsole": false,
"windows": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"pipeTransport": {
"pipeCwd": "",
"pipeProgram": "c:\\windows\\sysnative\\bash.exe",
"pipeArgs": ["-c"],
"debuggerPath": "/usr/bin/gdb"
},
"sourceFileMap": {
"/mnt/c": "c:\\"
},
"logging": { "engineLogging": true, "trace": true, "traceResponse": true }
},
]
}
Steps to reproduce the behavior:
Logs from logging in launch.json
--> E (output): {"event":"output","body":{"category":"console","output":"1: (195) LaunchOptions<PipeLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014'\r\n"},"seq":2,"type":"event"}
1: (195) LaunchOptions<PipeLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (206) LaunchOptions ExePath='/mnt/c/Users/Vítor/Desktop/Programação/Cpp/hello.out'\r\n"},"seq":4,"type":"event"}
1: (206) LaunchOptions ExePath='/mnt/c/Users/Vítor/Desktop/Programação/Cpp/hello.out'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (207) LaunchOptions WorkingDirectory='/mnt/c/Users/Vítor/Desktop/Programação/Cpp'\r\n"},"seq":6,"type":"event"}
1: (207) LaunchOptions WorkingDirectory='/mnt/c/Users/Vítor/Desktop/Programação/Cpp'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (207) LaunchOptions ExeArguments=''\r\n"},"seq":8,"type":"event"}
1: (207) LaunchOptions ExeArguments=''
--> E (output): {"event":"output","body":{"category":"console","output":"1: (207) LaunchOptions MIMode='gdb'\r\n"},"seq":10,"type":"event"}
1: (207) LaunchOptions MIMode='gdb'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (209) LaunchOptions PipePath='c:\\windows\\sysnative\\bash.exe'\r\n"},"seq":12,"type":"event"}
1: (209) LaunchOptions PipePath='c:\windows\sysnative\bash.exe'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (209) LaunchOptions PipeArguments='-c \"/usr/bin/gdb --interpreter=mi\"'\r\n"},"seq":14,"type":"event"}
1: (209) LaunchOptions PipeArguments='-c "/usr/bin/gdb --interpreter=mi"'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (209) LaunchOptions PipeCommandArguments='-c'\r\n"},"seq":16,"type":"event"}
1: (209) LaunchOptions PipeCommandArguments='-c'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (210) LaunchOptions PipeCwd=''\r\n"},"seq":18,"type":"event"}
1: (210) LaunchOptions PipeCwd=''
--> E (output): {"event":"output","body":{"category":"console","output":"1: (210) LaunchOptions>\r\n"},"seq":20,"type":"event"}
1: (210) LaunchOptions>
--> E (output): {"event":"output","body":{"category":"console","output":"1: (211) LaunchOptions <SetupCommands>\r\n"},"seq":22,"type":"event"}
1: (211) LaunchOptions <SetupCommands>
--> E (output): {"event":"output","body":{"category":"console","output":"1: (211) LaunchOptions <Command IgnoreFailures='true' Description='Enable pretty-printing for gdb'>-enable-pretty-printing</Command>\r\n"},"seq":24,"type":"event"}
1: (211) LaunchOptions <Command IgnoreFailures='true' Description='Enable pretty-printing for gdb'>-enable-pretty-printing</Command>
--> E (output): {"event":"output","body":{"category":"console","output":"1: (211) LaunchOptions </SetupCommands>\r\n"},"seq":26,"type":"event"}
1: (211) LaunchOptions </SetupCommands>
--> E (output): {"event":"output","body":{"category":"console","output":"1: (212) LaunchOptions</PipeLaunchOptions>\r\n"},"seq":28,"type":"event"}
1: (212) LaunchOptions</PipeLaunchOptions>
--> E (output): {"event":"output","body":{"category":"console","output":"1: (278) Starting: \"c:\\windows\\sysnative\\bash.exe\" -c \"/usr/bin/gdb --interpreter=mi\"\r\n"},"seq":30,"type":"event"}
1: (278) Starting: "c:\windows\sysnative\bash.exe" -c "/usr/bin/gdb --interpreter=mi"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (725) ->=thread-group-added,id=\"i1\"\r\n"},"seq":32,"type":"event"}
1: (725) ->=thread-group-added,id="i1"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (726) ->~\"GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git\\n\"\r\n"},"seq":34,"type":"event"}
1: (726) ->~"GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (727) ->~\"Copyright (C) 2018 Free Software Foundation, Inc.\\n\"\r\n"},"seq":36,"type":"event"}
1: (727) ->~"Copyright (C) 2018 Free Software Foundation, Inc.\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (727) ->~\"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\"\r\n"},"seq":38,"type":"event"}
1: (727) ->~"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"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (728) ->~\"This GDB was configured as \\\"x86_64-linux-gnu\\\".\\nType \\\"show configuration\\\" for configuration details.\"\r\n"},"seq":40,"type":"event"}
1: (728) ->~"This GDB was configured as \"x86_64-linux-gnu\".\nType \"show configuration\" for configuration details."
--> E (output): {"event":"output","body":{"category":"console","output":"1: (728) ->~\"\\nFor bug reporting instructions, please see:\\n\"\r\n"},"seq":42,"type":"event"}
1: (728) ->~"\nFor bug reporting instructions, please see:\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (728) ->~\"<http://www.gnu.org/software/gdb/bugs/>.\\n\"\r\n"},"seq":44,"type":"event"}
1: (728) ->~"<http://www.gnu.org/software/gdb/bugs/>.\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (729) ->~\"Find the GDB manual and other documentation resources online at:\\n<http://www.gnu.org/software/gdb/documentation/>.\\n\"\r\n"},"seq":46,"type":"event"}
1: (729) ->~"Find the GDB manual and other documentation resources online at:\n<http://www.gnu.org/software/gdb/documentation/>.\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (729) ->~\"For help, type \\\"help\\\".\\n\"\r\n"},"seq":48,"type":"event"}
1: (729) ->~"For help, type \"help\".\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (730) ->~\"Type \\\"apropos word\\\" to search for commands related to \\\"word\\\".\\n\"\r\n"},"seq":50,"type":"event"}
1: (730) ->~"Type \"apropos word\" to search for commands related to \"word\".\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (731) ->(gdb)\r\n"},"seq":52,"type":"event"}
1: (731) ->(gdb)
--> E (output): {"event":"output","body":{"category":"console","output":"1: (739) <-1001-gdb-set target-async on\r\n"},"seq":54,"type":"event"}
1: (739) <-1001-gdb-set target-async on
--> E (output): {"event":"output","body":{"category":"console","output":"1: (740) ->1001^done\r\n"},"seq":56,"type":"event"}
1: (740) ->1001^done
--> E (output): {"event":"output","body":{"category":"console","output":"1: (740) ->(gdb)\r\n"},"seq":58,"type":"event"}
1: (740) ->(gdb)
--> E (output): {"event":"output","body":{"category":"console","output":"1: (742) 1001: elapsed time 3\r\n"},"seq":60,"type":"event"}
1: (742) 1001: elapsed time 3
--> E (output): {"event":"output","body":{"category":"console","output":"1: (752) <-1002-enable-pretty-printing\r\n"},"seq":62,"type":"event"}
1: (752) <-1002-enable-pretty-printing
--> E (output): {"event":"output","body":{"category":"console","output":"1: (753) ->1002^done\r\n"},"seq":64,"type":"event"}
1: (753) ->1002^done
--> E (output): {"event":"output","body":{"category":"console","output":"1: (753) ->(gdb)\r\n"},"seq":66,"type":"event"}
1: (753) ->(gdb)
--> E (output): {"event":"output","body":{"category":"console","output":"1: (753) 1002: elapsed time 0\r\n"},"seq":68,"type":"event"}
1: (753) 1002: elapsed time 0
--> E (output): {"event":"output","body":{"category":"console","output":"1: (754) <-1003-interpreter-exec console \"set pagination off\"\r\n"},"seq":70,"type":"event"}
1: (754) <-1003-interpreter-exec console "set pagination off"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (755) ->=cmd-param-changed,param=\"pagination\",value=\"off\"\r\n"},"seq":72,"type":"event"}
1: (755) ->=cmd-param-changed,param="pagination",value="off"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (755) ->1003^done\r\n"},"seq":74,"type":"event"}
1: (755) ->1003^done
--> E (output): {"event":"output","body":{"category":"console","output":"1: (756) ->(gdb)\r\n"},"seq":76,"type":"event"}
1: (756) ->(gdb)
--> E (output): {"event":"output","body":{"category":"console","output":"1: (756) 1003: elapsed time 1\r\n"},"seq":78,"type":"event"}
1: (756) 1003: elapsed time 1
--> E (output): {"event":"output","body":{"category":"console","output":"1: (757) <-1004-gdb-set auto-solib-add on\r\n"},"seq":80,"type":"event"}
1: (757) <-1004-gdb-set auto-solib-add on
--> E (output): {"event":"output","body":{"category":"console","output":"1: (757) ->1004^done\r\n"},"seq":82,"type":"event"}
1: (757) ->1004^done
--> E (output): {"event":"output","body":{"category":"console","output":"1: (758) ->(gdb)\r\n"},"seq":84,"type":"event"}
1: (758) ->(gdb)
--> E (output): {"event":"output","body":{"category":"console","output":"1: (758) 1004: elapsed time 0\r\n"},"seq":86,"type":"event"}
1: (758) 1004: elapsed time 0
--> E (output): {"event":"output","body":{"category":"console","output":"1: (758) <-1005-gdb-set solib-search-path /mnt/c/Users/Vítor/Desktop/Programação/Cpp:\r\n"},"seq":88,"type":"event"}
1: (758) <-1005-gdb-set solib-search-path /mnt/c/Users/Vítor/Desktop/Programação/Cpp:
--> E (output): {"event":"output","body":{"category":"console","output":"1: (759) ->1005^done\r\n"},"seq":90,"type":"event"}
1: (759) ->1005^done
--> E (output): {"event":"output","body":{"category":"console","output":"1: (760) ->(gdb)\r\n"},"seq":92,"type":"event"}
1: (760) ->(gdb)
--> E (output): {"event":"output","body":{"category":"console","output":"1: (760) 1005: elapsed time 1\r\n"},"seq":94,"type":"event"}
1: (760) 1005: elapsed time 1
--> E (output): {"event":"output","body":{"category":"console","output":"1: (761) <-1006-gdb-set stop-on-solib-events 1\r\n"},"seq":96,"type":"event"}
1: (761) <-1006-gdb-set stop-on-solib-events 1
--> E (output): {"event":"output","body":{"category":"console","output":"1: (761) ->1006^done\r\n"},"seq":98,"type":"event"}
1: (761) ->1006^done
--> E (output): {"event":"output","body":{"category":"console","output":"1: (762) ->(gdb)\r\n"},"seq":100,"type":"event"}
1: (762) ->(gdb)
--> E (output): {"event":"output","body":{"category":"console","output":"1: (762) 1006: elapsed time 0\r\n"},"seq":102,"type":"event"}
1: (762) 1006: elapsed time 0
--> E (output): {"event":"output","body":{"category":"console","output":"1: (762) <-1007-environment-cd /mnt/c/Users/Vítor/Desktop/Programação/Cpp\r\n"},"seq":104,"type":"event"}
1: (762) <-1007-environment-cd /mnt/c/Users/Vítor/Desktop/Programação/Cpp
--> E (output): {"event":"output","body":{"category":"console","output":"1: (763) ->1007^error,msg=\"/mnt/c/Users/V\\241tor/Desktop/Programa\\207\\306o/Cpp: No such file or directory.\"\r\n"},"seq":106,"type":"event"}
1: (763) ->1007^error,msg="/mnt/c/Users/V\241tor/Desktop/Programa\207\306o/Cpp: No such file or directory."
--> E (output): {"event":"output","body":{"category":"console","output":"1: (764) ->(gdb)\r\n"},"seq":108,"type":"event"}
1: (764) ->(gdb)
--> E (output): {"event":"output","body":{"category":"console","output":"1: (769) 1007: elapsed time 6\r\n"},"seq":110,"type":"event"}
1: (769) 1007: elapsed time 6
--> E (output): {"event":"output","body":{"category":"console","output":"1: (781) Send Event AD7MessageEvent\r\n"},"seq":112,"type":"event"}
1: (781) Send Event AD7MessageEvent
--> E (output): {"event":"output","body":{"category":"console","output":"1: (781) <--gdb-exit\r\n"},"seq":114,"type":"event"}
1: (781) <--gdb-exit
--> E (output): {"event":"output","body":{"category":"console","output":"1: (783) ->^exit\r\n"},"seq":116,"type":"event"}
1: (783) ->^exit
--> E (output): {"event":"output","body":{"category":"console","output":"1: (788) <-logout\r\n"},"seq":118,"type":"event"}
1: (788) <-logout
--> E (output): {"event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/Launch","data":{"VS.Diagnostics.Debugger.ImplementationName":"Microsoft.MIDebugEngine","VS.Diagnostics.Debugger.EngineVersion":"14.0.60206.1","VS.Diagnostics.Debugger.HostVersion":"14.0.60206.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.Launch.ErrorCode":1005,"VS.Diagnostics.Debugger.Launch.IsError":true}},"seq":120,"type":"event"}
--> R (launch-2): {"request_seq":2,"success":false,"command":"launch","message":"Unable to start debugging. Unexpected GDB output from command \"-environment-cd /mnt/c/Users/Vítor/Desktop/Programação/Cpp\". /mnt/c/Users/V�tor/Desktop/Programa�o/Cpp: No such file or directory.","body":{"error":{"id":1005,"format":"Unable to start debugging. Unexpected GDB output from command \"-environment-cd /mnt/c/Users/Vítor/Desktop/Programação/Cpp\". /mnt/c/Users/V�tor/Desktop/Programa�o/Cpp: No such file or directory."}},"seq":122,"type":"response"}
@ImP-Gamer The problem is with gdb running in the MI interface mode does not understand any unicode characters. For example, we send
<-1007-environment-cd /mnt/c/Users/Vítor/Desktop/Programação/Cpp
and gdb fails to interpret it, returning the following error:
->1007^error,msg=\"/mnt/c/Users/V\\241tor/Desktop/Programa\\207\\306o/Cpp: No such file or directory.\"\r\n"}
The only workaround is to not include unicode in your path. We have had other reports of it too and until gdb fixes the issue, there isn't anything we can do.
@pieandcakes, I tested this and gdb --interface=mi works fine as long as one passes the filenames in the ANSI codepage, instead of using the OEM codepage or a Unicode encoding.
For example, the Greek OEM code page is 737 (the one used by DOS applications), and the Greek ANSI code page is 1253. See a failed and a successful example:
C:\> chcp
Active code page: 737
C:\> mkdir ά
C:\> gdb --interpreter=mi
(gdb)
1-environment-cd ά
1^error,msg="\341: No such file or directory."
(gdb)
quit
C:\> chcp 1253
Active code page: 1253
C:\> gdb --interpreter=mi
(gdb)
1-environment-cd ά
1^done
(gdb)
1-environment-pwd
1^done,cwd="C:\\\334"
So, if you're willing to use the ANSI codepage for gdb communication, then all ANSI filenames should work. If not, maybe we can make a "unicode-to-ANSI-stdio-wrapper.exe" and run gdb.exe via that wrapper.
Thanks!
As a test, I configured Windows to use UTF-8 as their ANSI codepage (instead of the default Greek 1253), and then vscode was able to properly communicate with mingw gdb.exe.
Specifically:
intl.cpl to open the "Region" control panel appletI reported it to the mingw mailing list, and they replied it cannot be fixed there without extensive changes:
https://osdn.net/projects/mingw/lists/archive/users/2020-May/000502.html
So, it's up to vscode to treat gdb as an ANSI program and not a Unicode program, i.e. to use the ANSI codepage in its stdio. In winapi this is doable with just a few lines of code, but I don't know the electron framework to propose a patch...
@WardenGnaw This might be an easy change. @alkisg is proposing to only support ANSI on windows for communication to/from gdb.
@alkisg Thank you for investigating. When we have a private build, would you be able to validate the fix also?
@pieandcakes thank you for replying, yes of course, I'm able to test private builds with ANSI Greek directories/filenames and mingw/gdb, ping me whenever I should do so.
Most helpful comment
The only workaround is to not include unicode in your path. We have had other reports of it too and until
gdbfixes the issue, there isn't anything we can do.