// Copyright (C) 2026 SharpEmu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later using System.Net; using SharpEmu.Core.Cpu.Debugging; using SharpEmu.Debugger.Server; using SharpEmu.Debugger.Session; namespace SharpEmu.Debugger; /// /// One-call wiring of the live debugger: it owns a /// and a , exposes the to attach /// to SharpEmuRuntimeOptions.DebugHook, and starts/stops the network /// front-end. A host constructs one, hands to the runtime, /// calls , and calls once the /// runtime returns. /// public sealed class DebuggerServerHost : IAsyncDisposable { private readonly DebuggerSession _session; private readonly DebuggerServer _server; public DebuggerServerHost( DebuggerServerOptions? serverOptions = null, DebuggerSessionOptions? sessionOptions = null) { _session = new DebuggerSession(sessionOptions); _server = new DebuggerServer(_session, serverOptions); } /// The session driving the target. public IDebuggerSession Session => _session; /// /// The dispatcher hook to hand to the runtime so guest frames route through /// the debugger. /// public ICpuDebugHook Hook => _session.Hook; /// The endpoint the server bound to, or null before . public IPEndPoint? Endpoint => _server.Endpoint; /// Begins accepting debugger clients. public void Start() => _server.Start(); /// /// Releases a parked emulation thread and marks the target terminated. Call /// after the runtime's run returns so any attached client is notified and the /// guest thread is never left blocked in the debugger. /// public void NotifyRunCompleted() => _session.NotifyTerminated(); public async ValueTask DisposeAsync() { _session.NotifyTerminated(); await _server.DisposeAsync().ConfigureAwait(false); } }