Debugger UI Updates (#39)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using SharpIDE.Application.Features.SolutionDiscovery;
|
||||
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||
|
||||
namespace SharpIDE.Application.Features.Debugging;
|
||||
@@ -15,5 +16,7 @@ public class Debugger
|
||||
}
|
||||
|
||||
public async Task StepOver(int threadId, CancellationToken cancellationToken = default) => await _debuggingService.StepOver(threadId, cancellationToken);
|
||||
public async Task<ThreadsStackTraceModel> GetInfoAtStopPoint() => await _debuggingService.GetInfoAtStopPoint();
|
||||
public async Task<List<ThreadModel>> GetThreadsAtStopPoint() => await _debuggingService.GetThreadsAtStopPoint();
|
||||
public async Task<List<StackFrameModel>> GetStackFramesForThread(int threadId) => await _debuggingService.GetStackFramesForThread(threadId);
|
||||
public async Task<List<Variable>> GetVariablesForStackFrame(int frameId) => await _debuggingService.GetVariablesForStackFrame(frameId);
|
||||
}
|
||||
|
||||
@@ -163,57 +163,72 @@ public class DebuggingService
|
||||
_debugProtocolHost.SendRequestSync(nextRequest);
|
||||
}
|
||||
|
||||
public async Task<ThreadsStackTraceModel> GetInfoAtStopPoint()
|
||||
public async Task<List<ThreadModel>> GetThreadsAtStopPoint()
|
||||
{
|
||||
var model = new ThreadsStackTraceModel();
|
||||
try
|
||||
var threadsRequest = new ThreadsRequest();
|
||||
var threadsResponse = _debugProtocolHost.SendRequestSync(threadsRequest);
|
||||
var mappedThreads = threadsResponse.Threads.Select(s => new ThreadModel
|
||||
{
|
||||
var threads = _debugProtocolHost.SendRequestSync(new ThreadsRequest());
|
||||
foreach (var thread in threads.Threads)
|
||||
Id = s.Id,
|
||||
Name = s.Name
|
||||
}).ToList();
|
||||
return mappedThreads;
|
||||
}
|
||||
|
||||
public async Task<List<StackFrameModel>> GetStackFramesForThread(int threadId)
|
||||
{
|
||||
var stackTraceRequest = new StackTraceRequest { ThreadId = threadId };
|
||||
var stackTraceResponse = _debugProtocolHost.SendRequestSync(stackTraceRequest);
|
||||
var stackFrames = stackTraceResponse.StackFrames;
|
||||
|
||||
var mappedStackFrames = stackFrames!.Select(frame =>
|
||||
{
|
||||
var isExternalCode = frame.Name == "[External Code]";
|
||||
ManagedStackFrameInfo? managedStackFrameInfo = isExternalCode ? null : ParseStackFrameName(frame.Name);
|
||||
return new StackFrameModel
|
||||
{
|
||||
var threadModel = new ThreadModel { Id = thread.Id, Name = thread.Name };
|
||||
model.Threads.Add(threadModel);
|
||||
var stackTrace = _debugProtocolHost.SendRequestSync(new StackTraceRequest { ThreadId = thread.Id });
|
||||
var frame = stackTrace.StackFrames!.FirstOrDefault();
|
||||
if (frame == null) continue;
|
||||
var name = frame.Name;
|
||||
if (name == "[External Code]") continue; // TODO: handle this case
|
||||
Id = frame.Id,
|
||||
Name = frame.Name,
|
||||
Line = frame.Line,
|
||||
Column = frame.Column,
|
||||
Source = frame.Source?.Path,
|
||||
IsExternalCode = isExternalCode,
|
||||
ManagedInfo = managedStackFrameInfo,
|
||||
};
|
||||
}).ToList();
|
||||
return mappedStackFrames;
|
||||
}
|
||||
|
||||
// Infrastructure.dll!Infrastructure.DependencyInjection.AddInfrastructure(Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.Extensions.Configuration.IConfiguration configuration) Line 23
|
||||
// need to parse out the class name, method name, namespace, assembly name
|
||||
var methodName = name.Split('!')[1].Split('(')[0];
|
||||
var className = methodName.Split('.').Reverse().Skip(1).First();
|
||||
var namespaceName = string.Join('.', methodName.Split('.').Reverse().Skip(2).Reverse());
|
||||
var assemblyName = name.Split('!')[0];
|
||||
methodName = methodName.Split('.').Reverse().First();
|
||||
var frameModel = new StackFrameModel
|
||||
{
|
||||
Id = frame.Id,
|
||||
Name = frame.Name,
|
||||
Line = frame.Line,
|
||||
Column = frame.Column,
|
||||
Source = frame.Source?.Path,
|
||||
ClassName = className,
|
||||
MethodName = methodName,
|
||||
Namespace = namespaceName,
|
||||
AssemblyName = assemblyName
|
||||
};
|
||||
threadModel.StackFrames.Add(frameModel);
|
||||
var scopes = _debugProtocolHost.SendRequestSync(new ScopesRequest { FrameId = frame.Id });
|
||||
foreach (var scope in scopes.Scopes)
|
||||
{
|
||||
var scopeModel = new ScopeModel { Name = scope.Name };
|
||||
frameModel.Scopes.Add(scopeModel);
|
||||
var variablesResponse = _debugProtocolHost.SendRequestSync(new VariablesRequest { VariablesReference = scope.VariablesReference });
|
||||
scopeModel.Variables = variablesResponse.Variables;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
public async Task<List<Variable>> GetVariablesForStackFrame(int frameId)
|
||||
{
|
||||
var scopesRequest = new ScopesRequest { FrameId = frameId };
|
||||
var scopesResponse = _debugProtocolHost.SendRequestSync(scopesRequest);
|
||||
var allVariables = new List<Variable>();
|
||||
foreach (var scope in scopesResponse.Scopes)
|
||||
{
|
||||
throw;
|
||||
var variablesRequest = new VariablesRequest { VariablesReference = scope.VariablesReference };
|
||||
var variablesResponse = _debugProtocolHost.SendRequestSync(variablesRequest);
|
||||
allVariables.AddRange(variablesResponse.Variables);
|
||||
}
|
||||
return allVariables;
|
||||
}
|
||||
|
||||
return model;
|
||||
// netcoredbg does not provide the stack frame name in this format, so don't use this if using netcoredbg
|
||||
private static ManagedStackFrameInfo? ParseStackFrameName(string name)
|
||||
{
|
||||
return null;
|
||||
var methodName = name.Split('!')[1].Split('(')[0];
|
||||
var className = methodName.Split('.').Reverse().Skip(1).First();
|
||||
var namespaceName = string.Join('.', methodName.Split('.').Reverse().Skip(2).Reverse());
|
||||
var assemblyName = name.Split('!')[0];
|
||||
methodName = methodName.Split('.').Reverse().First();
|
||||
var managedStackFrameInfo = new ManagedStackFrameInfo
|
||||
{
|
||||
MethodName = methodName,
|
||||
ClassName = className,
|
||||
Namespace = namespaceName,
|
||||
AssemblyName = assemblyName
|
||||
};
|
||||
return managedStackFrameInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,26 @@
|
||||
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages;
|
||||
namespace SharpIDE.Application.Features.Debugging;
|
||||
|
||||
namespace SharpIDE.Application.Features.Debugging;
|
||||
|
||||
public class ThreadsStackTraceModel
|
||||
public class StackFrameModel
|
||||
{
|
||||
public List<ThreadModel> Threads { get; set; } = [];
|
||||
public required int Id { get; set; }
|
||||
public required string Name { get; set; }
|
||||
public required int? Line { get; set; }
|
||||
public required int? Column { get; set; }
|
||||
public required string? Source { get; set; }
|
||||
public required bool IsExternalCode { get; set; }
|
||||
public required ManagedStackFrameInfo? ManagedInfo { get; set; }
|
||||
}
|
||||
|
||||
public record struct ManagedStackFrameInfo
|
||||
{
|
||||
public required string ClassName { get; set; }
|
||||
public required string MethodName { get; set; }
|
||||
public required string Namespace { get; set; }
|
||||
public required string AssemblyName { get; set; }
|
||||
}
|
||||
|
||||
public class ThreadModel
|
||||
{
|
||||
public required int Id { get; set; }
|
||||
public required string Name { get; set; }
|
||||
public List<StackFrameModel> StackFrames { get; set; } = [];
|
||||
}
|
||||
|
||||
public class StackFrameModel
|
||||
{
|
||||
public required string ClassName { get; set; }
|
||||
public required string MethodName { get; set; }
|
||||
public required string Namespace { get; set; }
|
||||
public required string AssemblyName { get; set; }
|
||||
|
||||
public required int Id { get; set; }
|
||||
public required string Name { get; set; }
|
||||
public required int? Line { get; set; }
|
||||
public required int? Column { get; set; }
|
||||
public required string? Source { get; set; }
|
||||
public List<ScopeModel> Scopes { get; set; } = [];
|
||||
}
|
||||
|
||||
public class ScopeModel
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public List<Variable> Variables { get; set; } = [];
|
||||
}
|
||||
|
||||
@@ -3,12 +3,14 @@ using System.Threading.Channels;
|
||||
using Ardalis.GuardClauses;
|
||||
using AsyncReadProcess;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages;
|
||||
using SharpIDE.Application.Features.Analysis;
|
||||
using SharpIDE.Application.Features.Debugging;
|
||||
using SharpIDE.Application.Features.Evaluation;
|
||||
using SharpIDE.Application.Features.Events;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||
using Breakpoint = SharpIDE.Application.Features.Debugging.Breakpoint;
|
||||
|
||||
namespace SharpIDE.Application.Features.Run;
|
||||
|
||||
@@ -153,9 +155,17 @@ public class RunService(ILogger<RunService> logger, RoslynAnalysis roslynAnalysi
|
||||
await _debugger!.StepOver(threadId);
|
||||
}
|
||||
|
||||
public async Task<ThreadsStackTraceModel> GetInfoAtStopPoint()
|
||||
public async Task<List<ThreadModel>> GetThreadsAtStopPoint()
|
||||
{
|
||||
return await _debugger!.GetInfoAtStopPoint();
|
||||
return await _debugger!.GetThreadsAtStopPoint();
|
||||
}
|
||||
public async Task<List<StackFrameModel>> GetStackFrames(int threadId)
|
||||
{
|
||||
return await _debugger!.GetStackFramesForThread(threadId);
|
||||
}
|
||||
public async Task<List<Variable>> GetVariablesForStackFrame(int frameId)
|
||||
{
|
||||
return await _debugger!.GetVariablesForStackFrame(frameId);
|
||||
}
|
||||
|
||||
private async Task<string> GetRunArguments(SharpIdeProjectModel project)
|
||||
|
||||
@@ -10,9 +10,11 @@ namespace SharpIDE.Godot.Features.Debug_.Tab.SubTabs;
|
||||
public partial class ThreadsVariablesSubTab : Control
|
||||
{
|
||||
private PackedScene _threadListItemScene = GD.Load<PackedScene>("res://Features/Debug_/Tab/SubTabs/ThreadListItem.tscn");
|
||||
private VBoxContainer _threadsVboxContainer = null!;
|
||||
private VBoxContainer _stackFramesVboxContainer = null!;
|
||||
private VBoxContainer _variablesVboxContainer = null!;
|
||||
|
||||
private Tree _threadsTree = null!;
|
||||
private Tree _stackFramesTree = null!;
|
||||
private Tree _variablesTree = null!;
|
||||
|
||||
public SharpIdeProjectModel Project { get; set; } = null!;
|
||||
// private ThreadModel? _selectedThread = null!; // null when not at a stop point
|
||||
|
||||
@@ -20,63 +22,77 @@ public partial class ThreadsVariablesSubTab : Control
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_threadsVboxContainer = GetNode<VBoxContainer>("%ThreadsVBoxContainer");
|
||||
_stackFramesVboxContainer = GetNode<VBoxContainer>("%StackFramesVBoxContainer");
|
||||
_variablesVboxContainer = GetNode<VBoxContainer>("%VariablesVBoxContainer");
|
||||
GlobalEvents.Instance.DebuggerExecutionStopped.Subscribe(OnDebuggerExecutionStopped);
|
||||
|
||||
_threadsTree = GetNode<Tree>("%ThreadsTree");
|
||||
_stackFramesTree = GetNode<Tree>("%StackFramesTree");
|
||||
_variablesTree = GetNode<Tree>("%VariablesTree");
|
||||
GlobalEvents.Instance.DebuggerExecutionStopped.Subscribe(OnDebuggerExecutionStopped2);
|
||||
_threadsTree.ItemSelected += OnThreadSelected;
|
||||
_stackFramesTree.ItemSelected += OnStackFrameSelected;
|
||||
}
|
||||
|
||||
private async void OnThreadSelected()
|
||||
{
|
||||
var selectedItem = _threadsTree.GetSelected();
|
||||
Guard.Against.Null(selectedItem);
|
||||
var threadId = selectedItem.GetMetadata(0).AsInt32();
|
||||
var stackFrames = await _runService.GetStackFrames(threadId);
|
||||
await this.InvokeAsync(() =>
|
||||
{
|
||||
_variablesTree.Clear(); // If we select a thread that does not have stack frames, the variables would not be cleared otherwise
|
||||
_stackFramesTree.Clear();
|
||||
var root = _stackFramesTree.CreateItem();
|
||||
foreach (var (index, s) in stackFrames.Index())
|
||||
{
|
||||
var stackFrameItem = _stackFramesTree.CreateItem(root);
|
||||
if (s.IsExternalCode)
|
||||
{
|
||||
stackFrameItem.SetText(0, "[External Code]");
|
||||
}
|
||||
else
|
||||
{
|
||||
// for now, just use the raw name
|
||||
stackFrameItem.SetText(0, s.Name);
|
||||
//var managedFrameInfo = s.ManagedInfo!.Value;
|
||||
//stackFrameItem.SetText(0, $"{managedFrameInfo.ClassName}.{managedFrameInfo.MethodName}() in {managedFrameInfo.Namespace}, {managedFrameInfo.AssemblyName}");
|
||||
}
|
||||
stackFrameItem.SetMetadata(0, s.Id);
|
||||
if (index is 0) _stackFramesTree.SetSelected(stackFrameItem, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async void OnStackFrameSelected()
|
||||
{
|
||||
var selectedItem = _stackFramesTree.GetSelected();
|
||||
Guard.Against.Null(selectedItem);
|
||||
var frameId = selectedItem.GetMetadata(0).AsInt32();
|
||||
var variables = await _runService.GetVariablesForStackFrame(frameId);
|
||||
await this.InvokeAsync(() =>
|
||||
{
|
||||
_variablesTree.Clear();
|
||||
var root = _variablesTree.CreateItem();
|
||||
foreach (var variable in variables)
|
||||
{
|
||||
var variableItem = _variablesTree.CreateItem(root);
|
||||
variableItem.SetText(0, $$"""{{variable.Name}} = {{{variable.Type}}} {{variable.Value}}""");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task OnDebuggerExecutionStopped(ExecutionStopInfo stopInfo)
|
||||
{
|
||||
var result = await _runService.GetInfoAtStopPoint();
|
||||
var threadScenes = result.Threads.Select(s =>
|
||||
{
|
||||
var threadListItem = _threadListItemScene.Instantiate<Control>();
|
||||
threadListItem.GetNode<Label>("Label").Text = $"{s.Id}: {s.Name}";
|
||||
return threadListItem;
|
||||
}).ToList();
|
||||
await this.InvokeAsync(() =>
|
||||
{
|
||||
_threadsVboxContainer.QueueFreeChildren();
|
||||
foreach (var scene in threadScenes)
|
||||
{
|
||||
_threadsVboxContainer.AddChild(scene);
|
||||
}
|
||||
});
|
||||
|
||||
var stoppedThreadId = stopInfo.ThreadId;
|
||||
var stoppedThread = result.Threads.SingleOrDefault(t => t.Id == stoppedThreadId);
|
||||
Guard.Against.Null(stoppedThread, nameof(stoppedThread));
|
||||
var stackFrameScenes = stoppedThread!.StackFrames.Select(s =>
|
||||
{
|
||||
var stackFrameItem = _threadListItemScene.Instantiate<Control>();
|
||||
stackFrameItem.GetNode<Label>("Label").Text = $"{s.ClassName}.{s.MethodName}() in {s.Namespace}, {s.AssemblyName}";
|
||||
return stackFrameItem;
|
||||
}).ToList();
|
||||
private async Task OnDebuggerExecutionStopped2(ExecutionStopInfo stopInfo)
|
||||
{
|
||||
var threads = await _runService.GetThreadsAtStopPoint();
|
||||
await this.InvokeAsync(() =>
|
||||
{
|
||||
_stackFramesVboxContainer.QueueFreeChildren();
|
||||
foreach (var scene in stackFrameScenes)
|
||||
_threadsTree.Clear();
|
||||
var root = _threadsTree.CreateItem();
|
||||
foreach (var thread in threads)
|
||||
{
|
||||
_stackFramesVboxContainer.AddChild(scene);
|
||||
}
|
||||
});
|
||||
|
||||
var currentFrame = stoppedThread.StackFrames.First();
|
||||
var variableScenes = currentFrame.Scopes.SelectMany(s => s.Variables).Select(v =>
|
||||
{
|
||||
var variableListItem = _threadListItemScene.Instantiate<Control>();
|
||||
variableListItem.GetNode<Label>("Label").Text = $$"""{{v.Name}} = {{{v.Type}}} {{v.Value}}""";
|
||||
return variableListItem;
|
||||
}).ToList();
|
||||
|
||||
await this.InvokeAsync(() =>
|
||||
{
|
||||
_variablesVboxContainer.QueueFreeChildren();
|
||||
foreach (var scene in variableScenes)
|
||||
{
|
||||
_variablesVboxContainer.AddChild(scene);
|
||||
var threadItem = _threadsTree.CreateItem(root);
|
||||
threadItem.SetText(0, $"@{thread.Id}: {thread.Name}");
|
||||
threadItem.SetMetadata(0, thread.Id);
|
||||
if (thread.Id == stopInfo.ThreadId) _threadsTree.SetSelected(threadItem, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bdu08nd7si641"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://bdu08nd7si641"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dpc4fvj40e5il" path="res://Features/Debug_/Tab/SubTabs/ThreadsVariablesSubTab.cs" id="1_e3p3b"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_hwpe6"]
|
||||
|
||||
[node name="ThreadsVariablesSubTab" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
@@ -28,52 +30,46 @@ split_offset = 370
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="HSplitContainer/HSplitContainer/ThreadsPanel"]
|
||||
[node name="ThreadsTree" type="Tree" parent="HSplitContainer/HSplitContainer/ThreadsPanel"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="ThreadsVBoxContainer" type="VBoxContainer" parent="HSplitContainer/HSplitContainer/ThreadsPanel/ScrollContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/draw_guides = 0
|
||||
theme_override_styles/panel = SubResource("StyleBoxEmpty_hwpe6")
|
||||
hide_root = true
|
||||
|
||||
[node name="StackFramesPanel" type="Panel" parent="HSplitContainer/HSplitContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="HSplitContainer/HSplitContainer/StackFramesPanel"]
|
||||
[node name="StackFramesTree" type="Tree" parent="HSplitContainer/HSplitContainer/StackFramesPanel"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="StackFramesVBoxContainer" type="VBoxContainer" parent="HSplitContainer/HSplitContainer/StackFramesPanel/ScrollContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/draw_guides = 0
|
||||
theme_override_styles/panel = SubResource("StyleBoxEmpty_hwpe6")
|
||||
hide_root = true
|
||||
|
||||
[node name="VariablesPanel" type="Panel" parent="HSplitContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="HSplitContainer/VariablesPanel"]
|
||||
[node name="VariablesTree" type="Tree" parent="HSplitContainer/VariablesPanel"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="VariablesVBoxContainer" type="VBoxContainer" parent="HSplitContainer/VariablesPanel/ScrollContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/draw_guides = 0
|
||||
theme_override_styles/panel = SubResource("StyleBoxEmpty_hwpe6")
|
||||
hide_root = true
|
||||
|
||||
Reference in New Issue
Block a user