Allow debugger instaces to be passed at runtime; Create in-processes debugger

This commit is contained in:
Yoshi Askharoun
2025-07-20 02:13:45 -05:00
parent 1667d353c2
commit 13d2fc640b
9 changed files with 86 additions and 19 deletions
+11 -7
View File
@@ -142,7 +142,9 @@ namespace Microsoft.Iris
public static event EventHandler DebuggerServerReady;
public static void Initialize()
public static void Initialize() => Initialize(null);
public static void Initialize(Func<IDebuggerServer> debuggerFactory)
{
if (IsInitialized)
throw new InvalidOperationException("Application already initialized");
@@ -178,7 +180,15 @@ namespace Microsoft.Iris
}
s_session.InitializeRenderingDevices(graphicsType, (GraphicsRenderingQuality)s_renderingQuality, soundType);
s_renderingQuality = (RenderingQuality)s_session.RenderSession.GraphicsDevice.RenderingQuality;
InitializeCommon(true);
if (debuggerFactory != null)
{
Debugger = debuggerFactory();
DebuggerServerReady?.Invoke(Debugger, EventArgs.Empty);
}
if (!s_EnableAnimations)
AnimationSystem.OverrideAnimationState(true);
UIForm uiForm = new UIForm(s_session);
@@ -193,12 +203,6 @@ namespace Microsoft.Iris
Debug.Trace.Initialize();
if (DebugSettings.DebugConnectionUri != null)
{
Debugger = new Debug.SystemNet.NetDebuggerServer(DebugSettings.DebugConnectionUri);
DebuggerServerReady?.Invoke(Debugger, EventArgs.Empty);
}
MarkupSystem.Startup(!fullInitialization);
StaticServices.Initialize();
}
@@ -15,6 +15,4 @@ public class DebugSettings
public ObservableCollection<DataMappingModel> DataMappingModels { get; } = new();
public HashSet<Breakpoint> Breakpoints { get; } = new();
public string DebugConnectionUri { get; set; }
}
+6 -1
View File
@@ -2,7 +2,7 @@
namespace Microsoft.Iris.Debug;
internal interface IDebuggerServer : IDebuggerState
public interface IDebuggerServer : IDebuggerState
{
/// <summary>
/// Sends the requested line number table.
@@ -26,4 +26,9 @@ internal interface IDebuggerServer : IDebuggerState
/// </summary>
/// <param name="message"></param>
void LogDispatcher(string message);
/// <summary>
/// Waits for the debugger to continue execution. Will block the current thread.
/// </summary>
void WaitForContinue();
}
+5 -2
View File
@@ -4,14 +4,17 @@ using System;
namespace Microsoft.Iris.Debug;
public interface IDebuggerState
{
InterpreterCommand DebuggerCommand { get; set; }
}
public interface IRemoteDebuggerState : IDebuggerState
{
/// <summary>
/// The URI the client is connected to.
/// </summary>
public Uri ConnectionUri { get; }
InterpreterCommand DebuggerCommand { get; set; }
/// <summary>
/// Fired when a connection is established.
/// </summary>
@@ -0,0 +1,50 @@
using Microsoft.Iris.Debug.Data;
using Microsoft.Iris.Markup;
using System;
using System.Diagnostics;
namespace Microsoft.Iris.Debug;
public class InProcDebugger : IDebuggerClient, IDebuggerServer
{
public InterpreterCommand DebuggerCommand { get; set; } = InterpreterCommand.Continue;
public event Action<InterpreterCommand> InterpreterStateChanged;
public event EventHandler<InterpreterInstruction> InterpreterDecode;
public event EventHandler<InterpreterEntry> InterpreterExecute;
public event Action<string> DispatcherStep;
public void RequestLineNumberTable(string uri, Action<MarkupLineNumberEntry[]> callback)
{
var lineNumberTable = ((IDebuggerServer)this).OnLineNumberTableRequested(uri);
callback(lineNumberTable);
}
public void UpdateBreakpoint(Breakpoint breakpoint)
{
if (breakpoint.Enabled)
Application.DebugSettings.Breakpoints.Add(breakpoint);
else
Application.DebugSettings.Breakpoints.Remove(breakpoint);
}
void IDebuggerServer.LogDispatcher(string message) => DispatcherStep?.Invoke(message);
void IDebuggerServer.LogInterpreterDecode(object context, InterpreterInstruction instruction) => InterpreterDecode?.Invoke(context, instruction);
void IDebuggerServer.LogInterpreterExecute(object context, InterpreterEntry entry) => InterpreterExecute?.Invoke(context, entry);
MarkupLineNumberEntry[] IDebuggerServer.OnLineNumberTableRequested(string uri)
{
var loadResult = (MarkupLoadResult)LoadResultCache.Read(uri);
var lineNumberTable = loadResult.LineNumberTable.DumpTable();
return lineNumberTable;
}
void IDebuggerServer.WaitForContinue()
{
if (DebuggerCommand is InterpreterCommand.Break)
Debugger.Break();
}
}
@@ -7,7 +7,7 @@ using System.Runtime.Serialization;
namespace Microsoft.Iris.Debug.SystemNet;
public class NetDebuggerClient : IDebuggerClient, IDisposable
public class NetDebuggerClient : IDebuggerClient, IRemoteDebuggerState, IDisposable
{
private readonly Socket _socket;
private readonly ConcurrentQueue<byte[]> _outQueue = new();
@@ -7,7 +7,7 @@ using System.Runtime.Serialization;
namespace Microsoft.Iris.Debug.SystemNet;
internal class NetDebuggerServer : IDebuggerServer, IDisposable
public class NetDebuggerServer : IDebuggerServer, IRemoteDebuggerState, IDisposable
{
public static IDebuggerServer Current { get; private set; }
@@ -53,7 +53,7 @@ internal class NetDebuggerServer : IDebuggerServer, IDisposable
public MarkupLineNumberEntry[] OnLineNumberTableRequested(string uri)
{
var loadResult = LoadResultCache.Read(uri) as MarkupLoadResult;
var loadResult = (MarkupLoadResult)LoadResultCache.Read(uri);
var lineNumberTable = loadResult.LineNumberTable.DumpTable();
return lineNumberTable;
@@ -121,7 +121,7 @@ internal class NetDebuggerServer : IDebuggerServer, IDisposable
break;
default:
Trace.WriteLine(TraceCategory.MarkupDebug, "Recieved unknown debugger message of type '{0}'.", frame.Type);
Trace.WriteLine(TraceCategory.MarkupDebug, "Received unknown debugger message of type '{0}'.", frame.Type);
break;
}
}
@@ -156,4 +156,9 @@ internal class NetDebuggerServer : IDebuggerServer, IDisposable
receiveThread.Start();
sendThread.Start();
}
public void WaitForContinue()
{
while (Application.Debugger.DebuggerCommand == InterpreterCommand.Break) ;
}
}
+1 -1
View File
@@ -90,7 +90,7 @@ namespace Microsoft.Iris.Markup
Application.Debugger.DebuggerCommand = InterpreterCommand.Break;
// Stop execution while the debugger is in break mode
while (Application.Debugger.DebuggerCommand == InterpreterCommand.Break) ;
Application.Debugger.WaitForContinue();
// If the debugger requested a single step, immediately set the debugger
// to break again for the next instruction
+3 -1
View File
@@ -111,9 +111,11 @@ namespace Microsoft.Iris.UI
public virtual void SetProperty(string name, object value)
{
if (_storage.ContainsKey(name) && Utility.IsEqual(_storage[name], value))
if (_storage.ContainsKey(name))
return;
_storage[name] = value;
if (Utility.IsEqual(_storage[name], value))
_notifier.Fire(name);
}