`EnsureProperPathSeparators()` causes wrong paths with Cygwin

Open
#1,418 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
csharp

Research direction

Start with EnsureProperPathSeparators() in src/MIDebugEngine/Engine.Impl/SourceLine.cs and trace its Cygwin path through MapWindowsToCygwin() and UnixPathToWindowsPath() in CygwinFileMapper.cs and PlatformUtilities.cs. Reproduce the breakpoint or GetBoundBreakpoint() case with Cygwin gdb; done means /c/src/a.cpp remains /c/src/a.cpp rather than becoming /c/c/src/a.cpp.

Written by the indexing model from the issue text.

Description

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

Dominant language
C#
Stars
859
Forks
233
Avg merge
1d 6h
Merged PRs (30d)
3

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/MIEngine

All issues in microsoft/MIEngine

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.