Prototype complete InterpreterEntry serialization

This commit is contained in:
Yoshi Askharoun
2023-05-24 10:14:07 -05:00
parent 141a2200dd
commit bcf9b83f54
6 changed files with 117 additions and 62 deletions
+4 -2
View File
@@ -8,7 +8,7 @@ internal class Program
{ {
static IDebuggerClient? Debugger { get; set; } static IDebuggerClient? Debugger { get; set; }
static void Main(string[] args) static int Main(string[] args)
{ {
string connectionString = args.Length >= 2 string connectionString = args.Length >= 2
? args[1] : "tcp://127.0.0.1:5556"; ? args[1] : "tcp://127.0.0.1:5556";
@@ -17,10 +17,12 @@ internal class Program
Debugger = new ZmqDebuggerClient(connectionString); Debugger = new ZmqDebuggerClient(connectionString);
Debugger.DispatcherStep += Debugger_DispatcherStep; Debugger.DispatcherStep += Debugger_DispatcherStep;
//Debugger.InterpreterStep += Debugger_InterpreterStep; Debugger.InterpreterStep += Debugger_InterpreterStep;
Console.WriteLine("Listening for debug messages. Press Ctrl-C to exit."); Console.WriteLine("Listening for debug messages. Press Ctrl-C to exit.");
Console.ReadLine(); Console.ReadLine();
return 0;
} }
private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
@@ -1,11 +1,15 @@
using System; using Microsoft.Iris.Markup;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
namespace Microsoft.Iris.Debug.Data; namespace Microsoft.Iris.Debug.Data;
[Serializable]
public class InterpreterEntry public class InterpreterEntry
{ {
public InterpreterEntry(object opCode, params OpCodeArgument[] args) public InterpreterEntry(OpCode opCode, params OpCodeArgument[] args)
{ {
OpCode = opCode; OpCode = opCode;
@@ -15,22 +19,25 @@ public class InterpreterEntry
Arguments = new List<OpCodeArgument>(); Arguments = new List<OpCodeArgument>();
} }
public object OpCode { get; } public OpCode OpCode { get; }
public IList<OpCodeArgument> Arguments { get; } public IList<OpCodeArgument> Arguments { get; }
public IList<object> ReturnValues { get; } = new List<object>(); public IList<object> ReturnValues { get; } = new List<object>();
public override string ToString() public override string ToString()
{ {
return $"{OpCode}({string.Join(", ", Arguments)}) -> [{ReturnValues}]"; return $"{OpCode}({string.Join(", ", Arguments)}) -> [{string.Join(", ", ReturnValues)}]";
} }
} }
public class OpCodeArgument [Serializable]
public class OpCodeArgument : ISerializable
{ {
public string Name { get; set; } public string Name { get; set; }
public Type Type { get; set; } public Type Type { get; set; }
public object Value { get; set; } public object Value { get; set; }
protected bool CanSerializeValue => Value is ISerializable;
public OpCodeArgument(string name, Type type, object value) public OpCodeArgument(string name, Type type, object value)
{ {
Name = name; Name = name;
@@ -38,5 +45,23 @@ public class OpCodeArgument
Value = value; Value = value;
} }
protected OpCodeArgument(SerializationInfo info, StreamingContext context)
{
Name = info.GetString(nameof(Name));
Type = Type.GetType(info.GetString(nameof(Type)), false);
bool canSerializeValue = info.GetBoolean(nameof(CanSerializeValue));
Type valueSerializeType = canSerializeValue ? Type : typeof(string);
Value = info.GetValue(nameof(Value), valueSerializeType);
}
public override string ToString() => $"{Type} {Value}"; public override string ToString() => $"{Type} {Value}";
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(nameof(Name), Name);
info.AddValue(nameof(Type), Type.FullName);
info.AddValue(nameof(CanSerializeValue), CanSerializeValue);
info.AddValue(nameof(Value), CanSerializeValue ? Value : Value.ToString());
}
} }
@@ -2,6 +2,8 @@
using NetMQ; using NetMQ;
using NetMQ.Sockets; using NetMQ.Sockets;
using System; using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text; using System.Text;
namespace Microsoft.Iris.Debug; namespace Microsoft.Iris.Debug;
@@ -34,8 +36,11 @@ public class ZmqDebuggerClient : IDebuggerClient, IDisposable
switch (type) switch (type)
{ {
case DebuggerMessageType.InterpreterOpCode: case DebuggerMessageType.InterpreterOpCode:
string entry = Encoding.Unicode.GetString(bytes); {
InterpreterStep?.Invoke(this, null); using MemoryStream stream = new(bytes);
var entry = (InterpreterEntry)new BinaryFormatter().Deserialize(stream);
InterpreterStep?.Invoke(this, entry);
}
break; break;
case DebuggerMessageType.DispatcherStep: case DebuggerMessageType.DispatcherStep:
@@ -46,7 +51,7 @@ public class ZmqDebuggerClient : IDebuggerClient, IDisposable
} }
} }
private DebuggerMessageType RecieveDebuggerMessage(SubscriberSocket socket, out byte[] bytes) private static DebuggerMessageType RecieveDebuggerMessage(SubscriberSocket socket, out byte[] bytes)
{ {
var frames = socket.ReceiveMultipartBytes(2); var frames = socket.ReceiveMultipartBytes(2);
@@ -1,6 +1,8 @@
using NetMQ; using NetMQ;
using NetMQ.Sockets; using NetMQ.Sockets;
using System; using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text; using System.Text;
namespace Microsoft.Iris.Debug; namespace Microsoft.Iris.Debug;
@@ -22,7 +24,10 @@ internal class ZmqDebuggerServer : IDebuggerServer, IDisposable
public void LogInterpreterOpCode(object context, Data.InterpreterEntry entry) public void LogInterpreterOpCode(object context, Data.InterpreterEntry entry)
{ {
SendDebuggerMessage(DebuggerMessageType.InterpreterOpCode, entry.ToString()); using MemoryStream entryStream = new();
new BinaryFormatter().Serialize(entryStream, entry);
SendDebuggerMessage(DebuggerMessageType.InterpreterOpCode, entryStream.ToArray());
} }
public void LogDispatcher(string message) public void LogDispatcher(string message)
+16
View File
@@ -90,6 +90,10 @@ namespace Microsoft.Iris.Markup
int num = reader.ReadUInt16(); int num = reader.ReadUInt16();
TypeSchema typeSchema = importTables.TypeImports[num]; TypeSchema typeSchema = importTables.TypeImports[num];
object obj = typeSchema.ConstructDefault(); object obj = typeSchema.ConstructDefault();
entry.Arguments.Add(new Debug.Data.OpCodeArgument(
"type", typeof(TypeSchema), typeSchema));
ReportErrorOnNull(obj, "Construction", typeSchema.Name); ReportErrorOnNull(obj, "Construction", typeSchema.Name);
if (!ErrorsDetected(watermark, ref result, ref errorsDetected)) if (!ErrorsDetected(watermark, ref result, ref errorsDetected))
{ {
@@ -210,7 +214,12 @@ namespace Microsoft.Iris.Markup
int num8 = reader.ReadUInt16(); int num8 = reader.ReadUInt16();
SymbolReference symbolRef = symbolReferenceTable[num8]; SymbolReference symbolRef = symbolReferenceTable[num8];
object obj8 = context.ReadSymbol(symbolRef); object obj8 = context.ReadSymbol(symbolRef);
entry.Arguments.Add(new Debug.Data.OpCodeArgument(
"symbolRef", typeof(SymbolReference), symbolRef));
stack.Push(obj8); stack.Push(obj8);
if (Trace.IsCategoryEnabled(TraceCategory.Markup)) if (Trace.IsCategoryEnabled(TraceCategory.Markup))
{ {
} }
@@ -222,7 +231,14 @@ namespace Microsoft.Iris.Markup
object value = (opCode == OpCode.WriteSymbolPeek) ? stack.Peek() : stack.Pop(); object value = (opCode == OpCode.WriteSymbolPeek) ? stack.Peek() : stack.Pop();
int num9 = reader.ReadUInt16(); int num9 = reader.ReadUInt16();
SymbolReference symbolRef2 = symbolReferenceTable[num9]; 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); context.WriteSymbol(symbolRef2, value);
if (Trace.IsCategoryEnabled(TraceCategory.Markup)) if (Trace.IsCategoryEnabled(TraceCategory.Markup))
{ {
} }
+53 -51
View File
@@ -4,56 +4,58 @@
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11 // MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
// Assembly location: C:\Program Files\Zune\UIX.dll // Assembly location: C:\Program Files\Zune\UIX.dll
namespace Microsoft.Iris.Markup using System;
namespace Microsoft.Iris.Markup;
[Serializable]
public enum OpCode : byte
{ {
public enum OpCode : byte ConstructObject = 1,
{ ConstructObjectIndirect = 2,
ConstructObject = 1, ConstructObjectParam = 3,
ConstructObjectIndirect = 2, ConstructFromString = 4,
ConstructObjectParam = 3, ConstructFromBinary = 5,
ConstructFromString = 4, InitializeInstance = 6,
ConstructFromBinary = 5, InitializeInstanceIndirect = 7,
InitializeInstance = 6, LookupSymbol = 8,
InitializeInstanceIndirect = 7, WriteSymbol = 9,
LookupSymbol = 8, WriteSymbolPeek = 10, // 0x0A
WriteSymbol = 9, ClearSymbol = 11, // 0x0B
WriteSymbolPeek = 10, // 0x0A PropertyInitialize = 12, // 0x0C
ClearSymbol = 11, // 0x0B PropertyInitializeIndirect = 13, // 0x0D
PropertyInitialize = 12, // 0x0C PropertyListAdd = 14, // 0x0E
PropertyInitializeIndirect = 13, // 0x0D PropertyDictionaryAdd = 15, // 0x0F
PropertyListAdd = 14, // 0x0E PropertyAssign = 16, // 0x10
PropertyDictionaryAdd = 15, // 0x0F PropertyAssignStatic = 17, // 0x11
PropertyAssign = 16, // 0x10 PropertyGet = 18, // 0x12
PropertyAssignStatic = 17, // 0x11 PropertyGetPeek = 19, // 0x13
PropertyGet = 18, // 0x12 PropertyGetStatic = 20, // 0x14
PropertyGetPeek = 19, // 0x13 MethodInvoke = 21, // 0x15
PropertyGetStatic = 20, // 0x14 MethodInvokePeek = 22, // 0x16
MethodInvoke = 21, // 0x15 MethodInvokeStatic = 23, // 0x17
MethodInvokePeek = 22, // 0x16 MethodInvokePushLastParam = 24, // 0x18
MethodInvokeStatic = 23, // 0x17 MethodInvokeStaticPushLastParam = 25, // 0x19
MethodInvokePushLastParam = 24, // 0x18 VerifyTypeCast = 26, // 0x1A
MethodInvokeStaticPushLastParam = 25, // 0x19 ConvertType = 27, // 0x1B
VerifyTypeCast = 26, // 0x1A Operation = 28, // 0x1C
ConvertType = 27, // 0x1B IsCheck = 29, // 0x1D
Operation = 28, // 0x1C As = 30, // 0x1E
IsCheck = 29, // 0x1D TypeOf = 31, // 0x1F
As = 30, // 0x1E PushNull = 32, // 0x20
TypeOf = 31, // 0x1F PushConstant = 33, // 0x21
PushNull = 32, // 0x20 PushThis = 34, // 0x22
PushConstant = 33, // 0x21 DiscardValue = 35, // 0x23
PushThis = 34, // 0x22 ReturnValue = 36, // 0x24
DiscardValue = 35, // 0x23 ReturnVoid = 37, // 0x25
ReturnValue = 36, // 0x24 JumpIfFalse = 38, // 0x26
ReturnVoid = 37, // 0x25 JumpIfFalsePeek = 39, // 0x27
JumpIfFalse = 38, // 0x26 JumpIfTruePeek = 40, // 0x28
JumpIfFalsePeek = 39, // 0x27 JumpIfDictionaryContains = 41, // 0x29
JumpIfTruePeek = 40, // 0x28 JumpIfNullPeek = 42, // 0x2A
JumpIfDictionaryContains = 41, // 0x29 Jump = 43, // 0x2B
JumpIfNullPeek = 42, // 0x2A ConstructListenerStorage = 44, // 0x2C
Jump = 43, // 0x2B Listen = 45, // 0x2D
ConstructListenerStorage = 44, // 0x2C DestructiveListen = 46, // 0x2E
Listen = 45, // 0x2D EnterDebugState = 47, // 0x2F
DestructiveListen = 46, // 0x2E
EnterDebugState = 47, // 0x2F
}
} }