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)
|
||||
|
||||
Reference in New Issue
Block a user