public VMDebugException(VirtualMachine vm, string msg) : base(msg) { this.vm = vm; var temp = new Disassembler(vm.entryScript); var lines = new List <string>(); if (vm.CurrentContext is ScriptContext sc) { lines.Add(Header("CURRENT OFFSET")); lines.Add(sc.InstructionPointer.ToString()); lines.Add(""); } lines.Add(Header("STACK")); var stack = vm.Stack.ToArray(); for (int i = 0; i < stack.Length; i++) { lines.Add(stack[i].ToString()); } lines.Add(""); lines.Add(Header("FRAMES")); int ct = 0; var frames = vm.frames.ToArray(); foreach (var frame in frames) { if (ct > 0) { lines.Add(""); } lines.Add("Active = " + (frame == vm.CurrentFrame).ToString()); lines.Add("Entry Offset = " + frame.Offset.ToString()); lines.Add("Registers:"); int ri = 0; foreach (var reg in frame.Registers) { if (reg.Type != VMType.None) { lines.Add($"\tR{ri} = {reg}"); } ri++; } ct++; } lines.Add(""); var disasm = temp.Instructions.Select(inst => inst.ToString()); lines.Add(Header("DISASM")); lines.AddRange(disasm); lines.Add(""); var path = Directory.GetCurrentDirectory() + "\\" + "vm_dump.txt"; System.Diagnostics.Debug.WriteLine("Dumped VM data: " + path); File.WriteAllLines(path, lines.ToArray()); }
private void DumpToFile(string fileName) { var temp = new Disassembler(vm.entryScript); var lines = new List <string>(); lines.Add("Exception: " + this.Message); if (vm.CurrentContext is ScriptContext sc) { lines.Add(Header("CURRENT OFFSET")); lines.Add(sc.InstructionPointer.ToString()); lines.Add(""); } lines.Add(Header("STACK")); var stack = vm.Stack.ToArray(); for (int i = 0; i < stack.Length; i++) { lines.Add(stack[i].ToString()); } lines.Add(""); lines.Add(Header("FRAMES")); int ct = 0; var frames = vm.frames.ToArray(); foreach (var frame in frames) { if (ct > 0) { lines.Add(""); } lines.Add("Active = " + (frame == vm.CurrentFrame).ToString()); lines.Add("Entry Offset = " + frame.Offset.ToString()); lines.Add("Registers:"); int ri = 0; foreach (var reg in frame.Registers) { if (reg.Type != VMType.None) { lines.Add($"\tR{ri} = {reg}"); } ri++; } ct++; } lines.Add(""); var disasm = temp.Instructions.Select(inst => inst.ToString()); lines.Add(Header("DISASM")); lines.AddRange(disasm); lines.Add(""); vm.DumpData(lines); var dirName = Directory.GetCurrentDirectory() + "/Dumps/"; Directory.CreateDirectory(dirName); var path = dirName + fileName; System.Diagnostics.Debug.WriteLine("Dumped VM data: " + path); File.WriteAllLines(path, lines.ToArray()); }