/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
v1.9.3
src/OneScript.DebugServices/DefaultDebugController.cs
103 строки
4 KB
EvilBeaver
Реализация команды disconnect отладчика
16 сен 2023, 11:00
16 сен 2023, 11:00
cdd29d1
Код
Авторство
О чём код?
/*---------------------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ using System; using OneScript.DebugProtocol; using OneScript.DebugProtocol.Abstractions; using OneScript.DebugProtocol.TcpServer; using ScriptEngine.Machine; namespace OneScript.DebugServices { /// <summary> /// Простой односессионный контроллер отладки. Поддерживает только один сеанс отладки на процесс. /// Также поддерживает только один BSL-процесс на приложение. При получении NotifyProcessExited отключает отладчик /// и к нему нельзя подключиться еще раз. /// </summary> public class DefaultDebugController : IDebugController { private readonly ICommunicationServer _server; private readonly IDebuggerService _debugger; private readonly IDebugEventListener _callbackService; private readonly ThreadManager _threadManager; public DefaultDebugController(ICommunicationServer ipcServer, IDebuggerService debugger, IDebugEventListener callbackService, ThreadManager threadManager, IBreakpointManager breakpointManager) { _server = ipcServer; _debugger = debugger; _callbackService = callbackService; _threadManager = threadManager; BreakpointManager = breakpointManager; } public void Dispose() { _server.Stop(); _threadManager.Dispose(); } public void Init() { _threadManager.ThreadStopped += ThreadManagerOnThreadStopped; var dispatcher = new DispatchingService<IDebuggerService>(_server, _debugger); dispatcher.Start(); } private void ThreadManagerOnThreadStopped(object sender, ThreadStoppedEventArgs e) { var token = _threadManager.GetTokenForThread(e.ThreadId); token.Reset(); _callbackService.ThreadStopped(e.ThreadId, ConvertStopReason(e.StopReason)); token.Wait(); } public void Wait() { _threadManager.GetTokenForCurrentThread().Wait(); } public void NotifyProcessExit(int exitCode) { _threadManager.DetachFromCurrentThread(); _callbackService.ProcessExited(exitCode); _server.Stop(); } public void AttachToThread() { MachineInstance.Current.SetDebugMode(BreakpointManager); _threadManager.AttachToCurrentThread(); } public void DetachFromThread() { _threadManager.DetachFromCurrentThread(); } public IBreakpointManager BreakpointManager { get; } private ThreadStopReason ConvertStopReason(MachineStopReason reason) { switch(reason) { case MachineStopReason.Breakpoint: return ThreadStopReason.Breakpoint; case MachineStopReason.Step: return ThreadStopReason.Step; case MachineStopReason.Exception: return ThreadStopReason.Exception; default: throw new NotImplementedException(); } } } }