Begin construction of UIB disassembly

This commit is contained in:
Yoshi Askharoun
2023-06-05 22:08:18 -05:00
parent f769834398
commit 474172326e
+38 -4
View File
@@ -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<string, ConcurrentBag<InterpreterEntry>> _entriesByFile = new();
private IDebuggerClient _client;
public event Action Stopped;
@@ -24,25 +31,52 @@ public class DebuggerService
public IDebuggerClient Client => _client;
public IReadOnlyDictionary<string, ConcurrentBag<InterpreterEntry>> 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<InterpreterEntry>());
if (entries.Any(e => e.Offset == currentEntry.Offset))
return;
entries.Add(currentEntry);
}
}