/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
v2.0.0-rc.8
src/OneScript.DebugServices/DefaultDebugController.cs
95 строк
3 KB
EvilBeaver
Уведомление отладчика о начале/конце bsl-потока
13 мар 2025, 13:40
13 мар 2025, 13:40
410ec6f
Код
Авторство
О чём код?
/*---------------------------------------------------------- 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 DefaultDebugService _debugger; private readonly IDebugEventListener _callbackService; private readonly ThreadManager _threadManager; public DefaultDebugController(ICommunicationServer ipcServer, DefaultDebugService 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) { MachineWaitToken token; try { token = _threadManager.GetTokenForThread(e.ThreadId); } catch (ArgumentOutOfRangeException) { return; } token.Reset(); _callbackService.ThreadStoppedEx(e.ThreadId, ConvertStopReason(e.StopReason), e.ErrorMessage); token.Wait(); } public void Wait() => _debugger.WaitForExecution(); public void NotifyProcessExit(int exitCode) { _threadManager.ReleaseAllThreads(); _callbackService.ProcessExited(exitCode); _server.Stop(); } public IBreakpointManager BreakpointManager { get; } public IThreadManager ThreadManager => _threadManager; private static ThreadStopReason ConvertStopReason(MachineStopReason reason) => reason switch { MachineStopReason.Breakpoint => ThreadStopReason.Breakpoint, MachineStopReason.BreakpointConditionError => ThreadStopReason.Breakpoint, MachineStopReason.Step => ThreadStopReason.Step, MachineStopReason.Exception => ThreadStopReason.Exception, _ => throw new NotImplementedException(), }; } }