From 474172326e0df202d61800df785d97726e28b177 Mon Sep 17 00:00:00 2001 From: Yoshi Askharoun Date: Mon, 5 Jun 2023 22:08:18 -0500 Subject: [PATCH] Begin construction of UIB disassembly --- ZuneUIXTools/Modules/UIX/DebuggerService.cs | 42 +++++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/ZuneUIXTools/Modules/UIX/DebuggerService.cs b/ZuneUIXTools/Modules/UIX/DebuggerService.cs index 5cdad3a..151cbdc 100644 --- a/ZuneUIXTools/Modules/UIX/DebuggerService.cs +++ b/ZuneUIXTools/Modules/UIX/DebuggerService.cs @@ -1,8 +1,14 @@ using Gemini.Modules.Output; using Microsoft.Iris.Debug; +using Microsoft.Iris.Debug.Data; using Microsoft.Iris.Debug.SystemNet; using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Collections.Immutable; using System.ComponentModel.Composition; +using System.Linq; +using System.Text; namespace ZuneUIXTools.Modules.UIX; @@ -10,6 +16,7 @@ namespace ZuneUIXTools.Modules.UIX; public class DebuggerService { private readonly IOutput _output; + private readonly ConcurrentDictionary> _entriesByFile = new(); private IDebuggerClient _client; public event Action Stopped; @@ -24,25 +31,52 @@ public class DebuggerService public IDebuggerClient Client => _client; + public IReadOnlyDictionary> ConstructedFiles => _entriesByFile; + public void Start(string connectionUri = null) { Stop(); _client = new NetDebuggerClient(connectionUri); + _client.InterpreterStep += Client_InterpreterStep; _output.AppendLine($"Debugger connected to {_client.ConnectionUri}"); } public void Stop() { - if (_client == null) - return; + _entriesByFile.Clear(); - if (_client is IDisposable disposable) + if (_client is null) + return; + else if (_client is IDisposable disposable) disposable.Dispose(); - Stopped?.Invoke(); + _client.InterpreterStep -= Client_InterpreterStep; _client = null; + + Stopped?.Invoke(); _output.AppendLine("Debugger disconnected"); } + + public string PrintDisassembly(string uri) + { + if (!_entriesByFile.TryGetValue(uri, out var entries)) + throw new ArgumentException(); + + var sortedEntries = entries.ToImmutableSortedSet(); + + StringBuilder sb = new(); + sb.AppendJoin(Environment.NewLine, sortedEntries.Select(e => e.ToInstructionString())); + return sb.ToString(); + } + + private void Client_InterpreterStep(object sender, InterpreterEntry currentEntry) + { + var entries = _entriesByFile.GetOrAdd(currentEntry.LoadUri, _ => new ConcurrentBag()); + + if (entries.Any(e => e.Offset == currentEntry.Offset)) + return; + entries.Add(currentEntry); + } }