lldb-tools / lldb-mi

LLDB's machine interface driver
https://lldb.llvm.org
Other
165 stars 56 forks source link

Hang on startup: MinGW interop failure with MIEngine due to line ending issues #119

Open malsyned opened 2 months ago

malsyned commented 2 months ago

Windows 11 VSCode 1.92.2 mingw-w64-clang-x86_64-lldb-mi r93.a6c8c66-1

When trying to use the MSys2 build of lldb-mi, debug hangs indefinitely when I try to launch it. I get the following errors in the VSCode debug console with "logging": { "engineLogging": true, }:

[Error] 1: (716) MI parsing error: CString not terminated: ""C:\\Users\\VBoxUser\\Documents\\cortex-r-template"
[Error] 1: (716) MI parsing error: Result expected: "path="C:\\Users\\VBoxUser\\Documents\\cortex-r-template"
[Error] 1: (716) MI parsing error: trailing chars: ""C:\\Users\\VBoxUser\\Documents\\cortex-r-template"
# ...
1: (736) Send Event AD7MessageEvent
[Error] 1: (738) MI parsing error: CString not terminated: """

I collected a log file, lldb-mi-20240726131431.log. The main clue in it is that lines representing commands from MIEngine are CRLF-terminated, but lines generated by llvm-mi are only LF-terminated. The MIEngine error happens after this exchange:

F,26/08/24 13:14:31,1003-environment-cd C:\\Users\\VBoxUser\\Documents\\cortex-r-template<CR><LF>
F,26/08/24 13:14:31,1003^done,path="C:\\Users\\VBoxUser\\Documents\\cortex-r-template<CR>"<LF>

What this looks like to me is that llvm-mi is reading the environment-cd command and treating the trailing <CR> as part of the command, not part of the line break. Then it echoes that wrong path back in the done,path= response, and MIEngine interprets that as an end-of-line and complains about "CString not terminated". You can even see it try to parse the closing quote as a separate command at the end after it's done reporting the first error:

[Error] 1: (738) MI parsing error: CString not terminated: """

My guess here is that whatever workarounds the MSys2 runtime has for line ending differences between POSIX and Windows, it's not working correctly (or making things worse) between MIEngine and lldb-mi. I couldn't find much about how the MSys2 runtime handles newlines, except this bit saying that it does something:

msys-2.0.dll includes the following changes to support using native Windows programs ... Conversion of output of native Windown applications from Windows line endings to POSIX line endings by removing trailing '\r' characters (https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin/)