Add source and stack trace handlers

This commit is contained in:
Joshua "Yoshi" Askharoun
2025-12-06 13:32:14 -06:00
parent 1668c3c2ec
commit b227c32b87
4 changed files with 108 additions and 19 deletions
@@ -31,6 +31,7 @@ internal class BreakpointHandler(DebugSymbolResolver symbolResolver)
{
Id = irisBreakpoint.GetHashCode(),
InstructionReference = requestedBreakpoint.InstructionReference,
Verified = true,
};
dapBreakpoints.Add(dapBreakpoint);
}
@@ -45,7 +46,7 @@ internal class BreakpointHandler(DebugSymbolResolver symbolResolver)
public Task<SetBreakpointsResponse> Handle(SetBreakpointsArguments request, CancellationToken cancellationToken)
{
// Debug symbols are required for setting source (line:column) breakpoints
var fsym = symbolResolver?.GetForFile(request.Source.Path);
var fsym = symbolResolver?.GetForFile(request.Source.Name);
if (fsym is null)
return Task.FromResult(new SetBreakpointsResponse());
@@ -77,6 +78,7 @@ internal class BreakpointHandler(DebugSymbolResolver symbolResolver)
Column = location.Span.Start.Column,
EndLine = location.Span.End.Line,
EndColumn = location.Span.End.Column,
Verified = true,
};
dapBreakpoints.Add(dapBreakpoint);
}
@@ -0,0 +1,55 @@
using OmniSharp.Extensions.DebugAdapter.Protocol.Requests;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.Iris.DebugAdapter.Server.Handlers;
internal class SourceHandler(DebugSymbolResolver symbolResolver) : ISourceHandler, ILoadedSourcesHandler
{
private const string MIME_IRIS_UIX_XML = "application/vnd.microsoft.iris.uix+xml";
public async Task<SourceResponse> Handle(SourceArguments request, CancellationToken cancellationToken)
{
Debugger.Launch();
Debugger.Break();
var fsym = symbolResolver.GetForFile(request.Source?.Name);
if (fsym is null)
return new SourceResponse();
if (fsym.SourceFileName is not null && File.Exists(fsym.SourceFileName))
{
string text =
#if NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
await File.ReadAllTextAsync(fsym.SourceFileName, cancellationToken);
#else
File.ReadAllText(fsym.SourceFileName);
#endif
return new()
{
Content = text,
MimeType = MIME_IRIS_UIX_XML
};
}
return new()
{
Content = "<UIX>TEST SOURCE</UIX>",
MimeType = MIME_IRIS_UIX_XML
};
}
public async Task<LoadedSourcesResponse> Handle(LoadedSourcesArguments request, CancellationToken cancellationToken)
{
Debugger.Launch();
Debugger.Break();
return new()
{
Sources = []
};
}
}
@@ -0,0 +1,32 @@
using OmniSharp.Extensions.DebugAdapter.Protocol.Requests;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using DapStackFrame = OmniSharp.Extensions.DebugAdapter.Protocol.Models.StackFrame;
namespace Microsoft.Iris.DebugAdapter.Server.Handlers;
internal class StackTraceHandler : StackTraceHandlerBase
{
public override async Task<StackTraceResponse> Handle(StackTraceArguments request, CancellationToken cancellationToken)
{
Debugger.Launch();
Debugger.Break();
List<DapStackFrame> stackFrames = [
new()
{
Source = new()
{
Path = "NowPlayingMusicBackground.uix"
}
}
];
return new StackTraceResponse
{
StackFrames = stackFrames
};
}
}
@@ -2,6 +2,7 @@
using Microsoft.Iris.Debug;
using Microsoft.Iris.Debug.Data;
using Microsoft.Iris.DebugAdapter.Server.Handlers;
using Newtonsoft.Json.Linq;
using OmniSharp.Extensions.DebugAdapter.Protocol.Events;
using OmniSharp.Extensions.DebugAdapter.Server;
using System;
@@ -38,22 +39,6 @@ public class IrisDebugAdapterServer : IDebuggerServer, IRemoteDebuggerState, IDi
if (Server is null)
return;
if (value is InterpreterCommand.Continue)
{
Server.SendContinued(new()
{
ThreadId = 0,
});
}
else if (value is InterpreterCommand.Break)
{
Server.SendStopped(new()
{
Reason = new("unknown"),
ThreadId = 0,
});
}
}
}
@@ -86,7 +71,7 @@ public class IrisDebugAdapterServer : IDebuggerServer, IRemoteDebuggerState, IDi
.WithHandler<BreakpointHandler>()
//.WithHandler<ConfigurationDoneHandler>()
.WithHandler<ThreadsHandler>()
//.WithHandler<StackTraceHandler>()
.WithHandler<StackTraceHandler>()
//.WithHandler<ScopesHandler>()
//.WithHandler<VariablesHandler>()
.WithHandler<ContinueHandler>()
@@ -94,7 +79,7 @@ public class IrisDebugAdapterServer : IDebuggerServer, IRemoteDebuggerState, IDi
.WithHandler<PauseHandler>()
.WithHandler<StepInHandler>()
//.WithHandler<StepOutHandler>()
//.WithHandler<SourceHandler>()
.WithHandler<SourceHandler>()
//.WithHandler<SetVariableHandler>()
//.WithHandler<DebugEvaluateHandler>()
// The OnInitialize delegate gets run when we first receive the _Initialize_ request:
@@ -158,7 +143,22 @@ public class IrisDebugAdapterServer : IDebuggerServer, IRemoteDebuggerState, IDi
public void WaitForContinue()
{
System.Diagnostics.Debugger.Launch();
if (DebuggerCommand is InterpreterCommand.Break)
{
Server?.SendStopped(new()
{
Reason = new("unknown"),
ThreadId = 0,
});
}
while (DebuggerCommand is InterpreterCommand.Break) ;
Server?.SendContinued(new()
{
ThreadId = 0,
});
}
public void Start()