@@ -43,7 +43,7 @@ public DebugeeProcess(PathHandlingStrategy pathHandling)
4343 }
4444
4545 public bool HasExited => _process ? . HasExited ?? true ;
46- public int ExitCode => _process . ExitCode ;
46+ public int ExitCode => _process ? . ExitCode ?? 0 ;
4747
4848 public int DebugPort { get ; set ; }
4949
@@ -59,9 +59,7 @@ public int ProtocolVersion
5959
6060 public bool WaitOnStart { get ; set ; }
6161
62- public string HostWorkspace { get ; set ; }
63-
64- public string RemoteWorkspace { get ; set ; }
62+ public WorkspaceMapper PathsMapper { get ; set ; }
6563
6664 public void Start ( )
6765 {
@@ -95,15 +93,15 @@ public void InitAttached()
9593 try
9694 {
9795 _process = Process . GetProcessById ( pid ) ;
96+ _process . EnableRaisingEvents = true ;
97+ _process . Exited += Process_Exited ;
9898 }
9999 catch
100100 {
101- _process = Process . GetCurrentProcess ( ) ;
101+ _process = null ;
102102 }
103103
104104 _attachMode = true ;
105- _process . EnableRaisingEvents = true ;
106- _process . Exited += Process_Exited ;
107105
108106 }
109107
@@ -198,31 +196,6 @@ private void RaiseOutputReceivedEvent(string category, string data)
198196 OutputReceived ? . Invoke ( this , new DebugeeOutputEventArgs ( category , data ) ) ;
199197 }
200198
201- private string ConvertRemotePath ( string path , string fromPrefix , string toPrefix )
202- {
203- if ( string . IsNullOrWhiteSpace ( path ) ||
204- string . IsNullOrWhiteSpace ( fromPrefix ) ||
205- string . IsNullOrWhiteSpace ( toPrefix ) )
206- return path ;
207-
208- var normalizedPath = path . Replace ( '\\ ' , '/' ) ;
209- var normalizedFrom = fromPrefix . Replace ( '\\ ' , '/' ) . TrimEnd ( '/' ) ;
210-
211- var comparison = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows )
212- ? StringComparison . OrdinalIgnoreCase
213- : StringComparison . Ordinal ;
214-
215- if ( normalizedPath . StartsWith ( toPrefix . Replace ( '\\ ' , '/' ) , comparison ) ||
216- ! normalizedPath . StartsWith ( normalizedFrom , comparison ) )
217- return path ;
218-
219- var relativePath = normalizedPath . Substring ( normalizedFrom . Length ) . TrimStart ( '/' ) ;
220-
221- var result = toPrefix . TrimEnd ( '/' , '\\ ' ) + "/" + relativePath ;
222-
223- return result ;
224- }
225-
226199 private void Terminate ( )
227200 {
228201 if ( ! _terminated )
@@ -270,6 +243,9 @@ public void HandleDisconnect(bool terminate)
270243
271244 public void Kill ( )
272245 {
246+ if ( _process == null )
247+ return ;
248+
273249 _process . Kill ( ) ;
274250 _process . WaitForExit ( 1500 ) ;
275251 }
@@ -302,7 +278,7 @@ public Breakpoint[] SetBreakpoints(IEnumerable<Breakpoint> breakpoints)
302278
303279 for ( int i = 0 ; i < breakpointsArray . Length ; i ++ )
304280 {
305- breakpointsArray [ i ] . Source = ConvertRemotePath ( breakpointsArray [ i ] . Source , HostWorkspace , RemoteWorkspace ) ;
281+ breakpointsArray [ i ] . Source = PathsMapper . LocalToRemote ( breakpointsArray [ i ] . Source ) ;
306282 }
307283
308284 var confirmedBreaks = _debugger . SetMachineBreakpoints ( breakpointsArray ) ;
@@ -329,7 +305,7 @@ public StackFrame[] GetStackTrace(int threadId, int firstFrameIdx, int limit)
329305 for ( int i = firstFrameIdx ; i < limit && i < allFrames . Length ; i ++ )
330306 {
331307 allFrames [ i ] . ThreadId = threadId ;
332- allFrames [ i ] . Source = ConvertRemotePath ( allFrames [ i ] . Source , RemoteWorkspace , HostWorkspace ) ;
308+ allFrames [ i ] . Source = PathsMapper . RemoteToLocal ( allFrames [ i ] . Source ) ;
333309 result . Add ( allFrames [ i ] ) ;
334310 }
335311
0 commit comments