microsoft / MIEngine

The Visual Studio MI Debug Engine ("MIEngine") provides an open-source Visual Studio Debugger extension that works with MI-enabled debuggers such as gdb and lldb.
MIT License
818 stars 218 forks source link

`EnsureProperPathSeparators()` causes wrong paths with Cygwin #1418

Open oold opened 1 year ago

oold commented 1 year ago

LinesForFile() fails to get the source lines for binaries built with Cygwin tools.

An incorrect path is returned from EnsureProperPathSeparators(): https://github.com/microsoft/MIEngine/blob/ad8e28a50a206ab2beca7c77e6737f6a305f7c12/src/MIDebugEngine/Engine.Impl/SourceLine.cs#L93-L95

This is because EnsureProperPathSeparators() calls MapWindowsToCygwin() when debugging with a Cygwin gdb: https://github.com/microsoft/MIEngine/blob/ad8e28a50a206ab2beca7c77e6737f6a305f7c12/src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs#L1525-L1529

MapWindowsToCygwin() calls UnixPathToWindowsPath() and this is the actual mistake that leads to the incorrect result: https://github.com/microsoft/MIEngine/blob/ad8e28a50a206ab2beca7c77e6737f6a305f7c12/src/MIDebugEngine/Engine.Impl/CygwinFileMapper.cs#L78

UnixPathToWindowsPath() replaces the slashes with backslashes: https://github.com/microsoft/MIEngine/blob/ad8e28a50a206ab2beca7c77e6737f6a305f7c12/src/MICore/PlatformUtilities.cs#L92

When LaunchCygPathAndReadResult() receives the "Windows" path, it doesn't look like an absolute path anymore, so it prepends the current working drive. https://github.com/microsoft/MIEngine/blob/ad8e28a50a206ab2beca7c77e6737f6a305f7c12/src/MIDebugEngine/Engine.Impl/CygwinFileMapper.cs#L80

This fails if, for example, a breakpoint is created, GetBoundBreakpoint() gets called, and the fullname contains a Cygwin path.

Expected result for EnsureProperPathSeparators(): Input: /c/src/a.cpp Conversion: /c/src/a.cpp -> /c/src/a.cpp -> /c/src/a.cpp Output: /c/src/a.cpp

Actual result for EnsureProperPathSeparators(): Input: /c/src/a.cpp Conversion: /c/src/a.cpp -> \c\src\a.cpp -> /c/c/src/a.cpp Output: /c/c/src/a.cpp