From 3700afad88d624a627324b30cad2330bb886264a Mon Sep 17 00:00:00 2001 From: Yoshi Askharoun Date: Tue, 7 Jun 2022 14:30:29 -0500 Subject: [PATCH] Debug bridge improvements --- UIX.Debug/Bridge.compat.cs | 25 ++++++++++++++++++++++ UIX.Debug/Bridge.cs | 5 +---- UIX.Debug/Data/InterpreterEntry.cs | 26 +++++++++++++++++------ UIX.Debug/IBridge.cs | 15 +++++++++++++ UIX.Debug/UIX.Debug.csproj | 1 + UIX/Microsoft/Iris/Debug/DebugSettings.cs | 7 ++++++ UIX/Microsoft/Iris/Markup/Interpreter.cs | 26 ++++++++++++++++++----- UIX/Microsoft/Iris/Queues/Dispatcher.cs | 6 +----- 8 files changed, 91 insertions(+), 20 deletions(-) create mode 100644 UIX.Debug/Bridge.compat.cs create mode 100644 UIX.Debug/IBridge.cs diff --git a/UIX.Debug/Bridge.compat.cs b/UIX.Debug/Bridge.compat.cs new file mode 100644 index 0000000..28d8558 --- /dev/null +++ b/UIX.Debug/Bridge.compat.cs @@ -0,0 +1,25 @@ +#if !ZUNE5 + +using Microsoft.Iris.Debug.Data; + +namespace Microsoft.Iris.Debug +{ + /// + /// A dummy implementation of , used to avoid conditional + /// code in consuming libraries. + /// + public class Bridge : IBridge + { + public void LogDispatcher(string message) + { + + } + + public void LogInterpreterOpCode(object context, InterpreterEntry entry) + { + + } + } +} + +#endif diff --git a/UIX.Debug/Bridge.cs b/UIX.Debug/Bridge.cs index 2645eb7..cef9cca 100644 --- a/UIX.Debug/Bridge.cs +++ b/UIX.Debug/Bridge.cs @@ -2,16 +2,13 @@ using OwlCore.Remoting; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Microsoft.Iris.Debug { [RemoteProperty] [RemoteMethod] [RemoteOptions(RemotingDirection.Bidirectional)] - public class Bridge : IDisposable + public class Bridge : IBridge, IDisposable { private readonly MemberRemote _memberRemote; diff --git a/UIX.Debug/Data/InterpreterEntry.cs b/UIX.Debug/Data/InterpreterEntry.cs index f30a89c..8fbaeba 100644 --- a/UIX.Debug/Data/InterpreterEntry.cs +++ b/UIX.Debug/Data/InterpreterEntry.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; namespace Microsoft.Iris.Debug.Data @@ -8,17 +9,22 @@ namespace Microsoft.Iris.Debug.Data public InterpreterEntry(object opCode, params OpCodeArgument[] args) { OpCode = opCode; - Arguments = args; + + if (args != null) + Arguments = args; + else + Arguments = new List(); } - public object OpCode { get; private set; } - public OpCodeArgument[] Arguments { get; private set; } + public object OpCode { get; } + public IList Arguments { get; } + public IList ReturnValues { get; } = new List(); public override string ToString() { var args = #if ZUNE5 - (System.Collections.Generic.IEnumerable)Arguments; + Arguments; #else Arguments.Select(a => a.ToString()).ToArray(); #endif @@ -28,8 +34,16 @@ namespace Microsoft.Iris.Debug.Data public class OpCodeArgument { - public Type Type { get; private set; } - public object Value { get; private set; } + public string Name { get; set; } + public Type Type { get; set; } + public object Value { get; set; } + + public OpCodeArgument(string name, Type type, object value) + { + Name = name; + Type = type; + Value = value; + } public override string ToString() => $"{Type} {Value}"; } diff --git a/UIX.Debug/IBridge.cs b/UIX.Debug/IBridge.cs new file mode 100644 index 0000000..d44c7cc --- /dev/null +++ b/UIX.Debug/IBridge.cs @@ -0,0 +1,15 @@ +namespace Microsoft.Iris.Debug +{ + internal interface IBridge + { + /// + /// Logs the context, opcode, and arguments of an instruction + /// executed by Microsoft.Iris.Markup.Interpreter. + /// + /// + /// + public void LogInterpreterOpCode(object context, Data.InterpreterEntry entry); + + public void LogDispatcher(string message); + } +} diff --git a/UIX.Debug/UIX.Debug.csproj b/UIX.Debug/UIX.Debug.csproj index 51ea70c..ae2122b 100644 --- a/UIX.Debug/UIX.Debug.csproj +++ b/UIX.Debug/UIX.Debug.csproj @@ -14,6 +14,7 @@ + diff --git a/UIX/Microsoft/Iris/Debug/DebugSettings.cs b/UIX/Microsoft/Iris/Debug/DebugSettings.cs index cf398d3..6b99e84 100644 --- a/UIX/Microsoft/Iris/Debug/DebugSettings.cs +++ b/UIX/Microsoft/Iris/Debug/DebugSettings.cs @@ -8,5 +8,12 @@ namespace Microsoft.Iris.Debug public bool OpenDebugPipe { get; set; } = false; public List DecompileResults { get; } = new List(); public TraceSettings TraceSettings { get; } = TraceSettings.Current; + + public Bridge Bridge { get; } = +#if ZUNE + new(OwlCore.Remoting.RemotingMode.Host); +#else + new(); +#endif } } diff --git a/UIX/Microsoft/Iris/Markup/Interpreter.cs b/UIX/Microsoft/Iris/Markup/Interpreter.cs index 06e8ab1..b1f6fec 100644 --- a/UIX/Microsoft/Iris/Markup/Interpreter.cs +++ b/UIX/Microsoft/Iris/Markup/Interpreter.cs @@ -840,9 +840,6 @@ namespace Microsoft.Iris.Markup } } - public static System.Collections.Generic.List ExecutedOpCodes { get; set; } - = new System.Collections.Generic.List(); - /// /// Attempts to generate source UIX from a compiled result /// @@ -883,7 +880,8 @@ namespace Microsoft.Iris.Markup while (!flag) { OpCode opCode = (OpCode)reader.ReadByte(); - ExecutedOpCodes.Add(opCode); + var entry = new Debug.Data.InterpreterEntry(opCode); + switch (opCode) { case OpCode.ConstructObject: @@ -898,6 +896,9 @@ namespace Microsoft.Iris.Markup typeName = typeName.Substring(0, idxTilde); var objXml = XmlDoc.CreateElement(typeName); + entry.Arguments.Add(new Debug.Data.OpCodeArgument( + "type", typeof(TypeSchema), typeSchema)); + ReportErrorOnNull(obj, "Construction", typeSchema.Name); if (!ErrorsDetected(watermark, ref result, ref flag)) { @@ -1034,10 +1035,16 @@ namespace Microsoft.Iris.Markup { int num8 = reader.ReadUInt16(); SymbolReference symbolRef = symbolReferenceTable[num8]; + entry.Arguments.Add(new Debug.Data.OpCodeArgument( + "symbolRef", typeof(SymbolReference), symbolRef)); + object obj8 = context.ReadSymbol(symbolRef); var objXml8 = XmlDoc.CreateElement(obj8.GetType().Name); + stack.Push(obj8); xmlStack.Push(objXml8); + entry.ReturnValues.Add(obj8); + if (Trace.IsCategoryEnabled(TraceCategory.Markup)) { } @@ -1049,7 +1056,14 @@ namespace Microsoft.Iris.Markup object value = (opCode == OpCode.WriteSymbolPeek) ? stack.Peek() : stack.Pop(); int num9 = reader.ReadUInt16(); SymbolReference symbolRef2 = symbolReferenceTable[num9]; + + entry.Arguments.Add(new Debug.Data.OpCodeArgument( + "symbolRef", typeof(SymbolReference), symbolRef2)); + entry.Arguments.Add(new Debug.Data.OpCodeArgument( + "value", typeof(object), value)); + context.WriteSymbol(symbolRef2, value); + if (Trace.IsCategoryEnabled(TraceCategory.Markup)) { } @@ -1549,10 +1563,12 @@ namespace Microsoft.Iris.Markup } } + Application.DebugSettings.Bridge.LogInterpreterOpCode(opCode, entry); + if (stack.Count != xmlStack.Count) throw new InvalidOperationException( $"Invalid stacks, stack:{stack.Count} != xmlStack{xmlStack.Count}! " + - $"Check implementations for {opCode} and {ExecutedOpCodes[ExecutedOpCodes.Count - 2]}"); + $"Check implementations for {opCode}"); } while (stack.Count > count) { diff --git a/UIX/Microsoft/Iris/Queues/Dispatcher.cs b/UIX/Microsoft/Iris/Queues/Dispatcher.cs index dcc36fb..11ce9bd 100644 --- a/UIX/Microsoft/Iris/Queues/Dispatcher.cs +++ b/UIX/Microsoft/Iris/Queues/Dispatcher.cs @@ -175,10 +175,6 @@ namespace Microsoft.Iris.Queues } } -#if ZUNE5 - private static Bridge Bridge { get; } = new(OwlCore.Remoting.RemotingMode.Host); -#endif - /// /// Sends a message via /// @@ -186,7 +182,7 @@ namespace Microsoft.Iris.Queues public static void SendDebugMessage(string message) { #if ZUNE5 - Bridge.LogDispatcher(message); + Application.DebugSettings.Bridge.LogDispatcher(message); #else if (Application.DebugSettings.OpenDebugPipe && DebugPipe.IsConnected && DebugPipe.CanWrite) {