Skip to content

Commit cdd29d1

Browse files
committed
Реализация команды disconnect отладчика
1 parent bf88924 commit cdd29d1

File tree

16 files changed

+80
-6
lines changed

16 files changed

+80
-6
lines changed

src/OneScript.DebugProtocol/Abstractions/ICommunicationServer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ This Source Code Form is subject to the terms of the
99

1010
namespace OneScript.DebugProtocol.Abstractions
1111
{
12+
/// <summary>
13+
/// Сервис прослушивания сетевого канала и отправки в него сообщений
14+
/// </summary>
1215
public interface ICommunicationServer
1316
{
1417
void Start();

src/OneScript.DebugProtocol/IDebugEventListener.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ This Source Code Form is subject to the terms of the
1010

1111
namespace OneScript.DebugProtocol
1212
{
13+
/// <summary>
14+
/// Интерфейс слушателя событий отладки (сообщений, инициируемых со стороны BSL)
15+
/// </summary>
1316
public interface IDebugEventListener
1417
{
1518
#if NETFRAMEWORK

src/OneScript.DebugProtocol/IDebuggerService.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ This Source Code Form is subject to the terms of the
1111

1212
namespace OneScript.DebugProtocol
1313
{
14+
/// <summary>
15+
/// Сервис непосредственной работы с командами отладки, шагами, брейкпоинтами и пр.
16+
/// </summary>
1417
#if NETFRAMEWORK
1518
[ServiceContract(
1619
Namespace = "http://oscript.io/services/debugger",
@@ -95,6 +98,14 @@ public interface IDebuggerService
9598
[OperationContract(IsOneWay = true)]
9699
#endif
97100
void StepOut(int threadId);
101+
102+
/// <summary>
103+
/// Отключение сеанса отладки по инициативе IDE
104+
/// </summary>
105+
#if NETFRAMEWORK
106+
[OperationContract(IsOneWay = true)]
107+
#endif
108+
void Disconnect();
98109

99110
#if NETFRAMEWORK
100111
[OperationContract]

src/OneScript.DebugProtocol/TcpServer/BinaryChannel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ This Source Code Form is subject to the terms of the
55
at http://mozilla.org/MPL/2.0/.
66
----------------------------------------------------------*/
77

8-
using System;
98
using System.IO;
109
using System.Net.Sockets;
1110
using System.Runtime.Serialization;
@@ -14,7 +13,10 @@ This Source Code Form is subject to the terms of the
1413

1514
namespace OneScript.DebugProtocol
1615
{
17-
public class BinaryChannel : ICommunicationChannel, IDisposable
16+
/// <summary>
17+
/// TCP-канал, использующий стандартную Binary-сериализацию .NET
18+
/// </summary>
19+
public class BinaryChannel : ICommunicationChannel
1820
{
1921
private readonly TcpClient _client;
2022
private readonly NetworkStream _clientStream;

src/OneScript.DebugProtocol/TcpServer/DefaultMessageServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private void RunCommandsLoop()
7171
// Считаем, что факап подписчика - его проблемы.
7272
}
7373

74-
// свойство в исключении может быть утановлено в обработчике евента
74+
// свойство в исключении может быть установлено в обработчике евента
7575
_serverStopped = e.StopChannel;
7676
}
7777
catch (Exception)

src/OneScript.DebugServices/BinaryTcpDebugServer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ public IDebugController CreateDebugController()
2424
{
2525
var listener = TcpListener.Create(_port);
2626
var channel = new DelayedConnectionChannel(listener);
27-
var ipcServer = new DefaultMessageServer<RpcCall>(channel);
27+
var ipcServer = new DefaultMessageServer<RpcCall>(channel)
28+
{
29+
ServerThreadName = "debug-server"
30+
};
2831
var callback = new TcpEventCallbackChannel(channel);
2932
var threadManager = new ThreadManager();
3033
var breakpoints = new DefaultBreakpointManager();

src/OneScript.DebugServices/DefaultBreakpointManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@ public bool Find(string module, int line)
3232
var found = _breakpoints.Find(x => x.Module.Equals(module) && x.LineNumber == line);
3333
return found != null;
3434
}
35+
36+
public void Clear()
37+
{
38+
_breakpoints.Clear();
39+
}
3540
}
3641
}

src/OneScript.DebugServices/DefaultDebugController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ This Source Code Form is subject to the terms of the
1313

1414
namespace OneScript.DebugServices
1515
{
16+
/// <summary>
17+
/// Простой односессионный контроллер отладки. Поддерживает только один сеанс отладки на процесс.
18+
/// Также поддерживает только один BSL-процесс на приложение. При получении NotifyProcessExited отключает отладчик
19+
/// и к нему нельзя подключиться еще раз.
20+
/// </summary>
1621
public class DefaultDebugController : IDebugController
1722
{
1823
private readonly ICommunicationServer _server;

src/OneScript.DebugServices/DefaultDebugService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ public virtual void StepOut(int threadId)
184184
t.Set();
185185
}
186186

187+
public void Disconnect()
188+
{
189+
_breakpointManager.Clear();
190+
_threadManager.ReleaseAllThreads();
191+
}
192+
187193
public virtual int[] GetThreads()
188194
{
189195
return _threadManager.GetAllThreadIds();

src/OneScript.DebugServices/ThreadManager.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public int[] GetAllThreadIds()
8080
{
8181
return _machinesOnThreads.Keys.ToArray();
8282
}
83-
84-
public void Dispose()
83+
84+
public void ReleaseAllThreads()
8585
{
8686
var tokens = GetAllTokens();
8787
foreach (var machineWaitToken in tokens)
@@ -92,5 +92,10 @@ public void Dispose()
9292

9393
_machinesOnThreads.Clear();
9494
}
95+
96+
public void Dispose()
97+
{
98+
ReleaseAllThreads();
99+
}
95100
}
96101
}

0 commit comments

Comments
 (0)