From a2032bde21e5443ec680ef233bbabb0872ab3f28 Mon Sep 17 00:00:00 2001 From: Nikita Romanov Date: Sun, 18 Feb 2024 00:53:14 +0400 Subject: [PATCH] Update breakpoint status change notifications to DAP way --- src/DotNet.Meteor.Debug/DebugSession.cs | 9 +++++++-- .../Extensions/MonoExtensions.cs | 7 ------- .../Extensions/ServerExtensions.cs | 14 ++++++++++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/DotNet.Meteor.Debug/DebugSession.cs b/src/DotNet.Meteor.Debug/DebugSession.cs index c617054..39c9593 100644 --- a/src/DotNet.Meteor.Debug/DebugSession.cs +++ b/src/DotNet.Meteor.Debug/DebugSession.cs @@ -37,6 +37,8 @@ public class DebugSession : Session { session.TargetExited += TargetExited; session.TargetThreadStarted += TargetThreadStarted; session.TargetThreadStopped += TargetThreadStopped; + + session.Breakpoints.BreakpointStatusChanged += BreakpointStatusChanged; } protected override MonoClient.ICustomLogger GetLogger() => MonoClient.DebuggerLoggingService.CustomLogger; @@ -196,9 +198,9 @@ public class DebugSession : Session { breakpoint.TraceExpression = $"[LogPoint]: {breakpointInfo.LogMessage}"; } - var verified = breakpoint.WaitForBound(session); breakpoints.Add(new DebugProtocol.Breakpoint() { - Verified = verified, + Id = breakpoint.GetHashCode(), + Verified = false, // updated by event Line = breakpoint.Line, Column = breakpoint.Column }); @@ -502,6 +504,9 @@ public class DebugSession : Session { GetLogger().LogError($"[Handled] {ex.Message}", ex); return true; } + private void BreakpointStatusChanged(object sender, MonoClient.BreakpointEventArgs e) { + Protocol.SendEvent(new BreakpointEvent(BreakpointEvent.ReasonValue.Changed, e.Breakpoint.ToBreakpoint(session))); + } private void OnSessionLog(bool isError, string message) { if (isError) GetLogger().LogError($"[Error] {message.Trim()}", null); else GetLogger().LogMessage($"[Info] {message.Trim()}"); diff --git a/src/DotNet.Meteor.Debug/Extensions/MonoExtensions.cs b/src/DotNet.Meteor.Debug/Extensions/MonoExtensions.cs index 4c03005..1d23562 100644 --- a/src/DotNet.Meteor.Debug/Extensions/MonoExtensions.cs +++ b/src/DotNet.Meteor.Debug/Extensions/MonoExtensions.cs @@ -53,11 +53,4 @@ public static class MonoExtensions { options.UseExternalTypeResolver = useExternalTypeResolver; return frame.GetExpressionValue(expression, options); } - public static bool WaitForBound(this BreakEvent breakEvent, SoftDebuggerSession session, int millisecondsTimeout = 150) { - return Task.Run(async() => { - while (breakEvent.GetStatus(session) == BreakEventStatus.NotBound) - await Task.Delay(millisecondsTimeout/3); - return breakEvent.GetStatus(session) == BreakEventStatus.Bound; - }).Wait(millisecondsTimeout); - } } \ No newline at end of file diff --git a/src/DotNet.Meteor.Debug/Extensions/ServerExtensions.cs b/src/DotNet.Meteor.Debug/Extensions/ServerExtensions.cs index d54e9f7..9854d9d 100644 --- a/src/DotNet.Meteor.Debug/Extensions/ServerExtensions.cs +++ b/src/DotNet.Meteor.Debug/Extensions/ServerExtensions.cs @@ -5,11 +5,11 @@ using System.Text.Json.Serialization.Metadata; using Newtonsoft.Json.Linq; using NewtonConverter = Newtonsoft.Json.JsonConvert; -using DebugProtocol = Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages; +using DebugProtocol = Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages; using System.IO; using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol; using DotNet.Meteor.Shared; -using System.Collections.Generic; +using Mono.Debugging.Soft; namespace DotNet.Meteor.Debug.Extensions; @@ -85,4 +85,14 @@ public static class ServerExtensions { return DebugProtocol.CompletionItemType.Text; } + + public static DebugProtocol.Breakpoint ToBreakpoint(this Breakpoint breakpoint, SoftDebuggerSession session) { + return new DebugProtocol.Breakpoint() { + Id = breakpoint.GetHashCode(), + Verified = breakpoint.GetStatus(session) == BreakEventStatus.Bound, + Message = breakpoint.GetStatusMessage(session), + Line = breakpoint.Line, + Column = breakpoint.Column, + }; + } } \ No newline at end of file