Skip to content

Commit 9df5e8f

Browse files
committed
Правильно обрабатывается Disconnect в режиме attach (не завершает процесс)
1 parent 267709c commit 9df5e8f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/VSCode.DebugAdapter/DebugeeProcess.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ internal abstract class DebugeeProcess
2222
private bool _terminated;
2323
private bool _stdoutEOF;
2424
private bool _stderrEOF;
25+
private bool _attachMode;
2526

2627
private IDebuggerService _debugger;
2728

@@ -51,12 +52,21 @@ public void Start()
5152
_process.OutputDataReceived += Process_OutputDataReceived;
5253
_process.ErrorDataReceived += Process_ErrorDataReceived;
5354
_process.Exited += Process_Exited;
54-
55+
_attachMode = false;
5556
_process.Start();
5657
System.Threading.Thread.Sleep(1500);
5758
_process.BeginOutputReadLine();
5859
_process.BeginErrorReadLine();
5960
}
61+
62+
public void InitAttached()
63+
{
64+
var pid = _debugger.GetProcessId();
65+
_process = Process.GetProcessById(pid);
66+
_attachMode = true;
67+
_process.EnableRaisingEvents = true;
68+
_process.Exited += Process_Exited;
69+
}
6070

6171
public void Init(JObject args)
6272
{
@@ -137,9 +147,9 @@ private void Terminate()
137147
}
138148
}
139149

140-
public void Kill()
150+
public void HandleDisconnect()
141151
{
142-
if (_process != null && !_process.HasExited)
152+
if (!_attachMode && _process != null && !_process.HasExited)
143153
{
144154
_process.Kill();
145155
}
@@ -214,13 +224,5 @@ public int[] GetThreads()
214224
{
215225
return _debugger.GetThreads();
216226
}
217-
218-
public void InitAttached()
219-
{
220-
var pid = _debugger.GetProcessId();
221-
_process = Process.GetProcessById(pid);
222-
_process.EnableRaisingEvents = true;
223-
_process.Exited += Process_Exited;
224-
}
225227
}
226228
}

src/VSCode.DebugAdapter/OscriptDebugSession.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public override void Launch(Response response, dynamic args)
105105
}
106106
catch (Exception e)
107107
{
108-
_process.Kill();
108+
_process.HandleDisconnect();
109109
_process = null;
110110
SessionLog.WriteLine(e.ToString());
111111
SendErrorResponse(response, 4550, "Can't connect: " + e.ToString());
@@ -149,7 +149,7 @@ public override void Attach(Response response, dynamic arguments)
149149

150150
public override void Disconnect(Response response, dynamic arguments)
151151
{
152-
_process.Kill();
152+
_process.HandleDisconnect();
153153
SendResponse(response);
154154
}
155155

0 commit comments

Comments
 (0)