From 08ab24ce28d7e3ec5698e41c59b2bb3b5495c5a0 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 5 May 2020 16:14:16 -0700 Subject: [PATCH] Update debugger to https://github.com/mono/mono/commit/1a6e64a9381c61f6bb7042d42e6ee79ef3a4d3fe --- .../src/MonoDebugProxy/ws-proxy/DebugStore.cs | 26 +++++++++++++++++-- .../src/MonoDebugProxy/ws-proxy/MonoProxy.cs | 22 ++++++++++------ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/Components/WebAssembly/DebugProxy/src/MonoDebugProxy/ws-proxy/DebugStore.cs b/src/Components/WebAssembly/DebugProxy/src/MonoDebugProxy/ws-proxy/DebugStore.cs index 8cf41de65fce..1b9568de804a 100644 --- a/src/Components/WebAssembly/DebugProxy/src/MonoDebugProxy/ws-proxy/DebugStore.cs +++ b/src/Components/WebAssembly/DebugProxy/src/MonoDebugProxy/ws-proxy/DebugStore.cs @@ -32,8 +32,8 @@ internal class BreakpointRequest { public override string ToString () => $"BreakpointRequest Assembly: {Assembly} File: {File} Line: {Line} Column: {Column}"; - public object AsSetBreakpointByUrlResponse () - => new { breakpointId = Id, locations = Locations.Select(l => l.Location.AsLocation ()) }; + public object AsSetBreakpointByUrlResponse (IEnumerable jsloc) + => new { breakpointId = Id, locations = Locations.Select(l => l.Location.AsLocation ()).Concat (jsloc) }; public BreakpointRequest () { } @@ -171,6 +171,28 @@ public static SourceLocation Parse (JObject obj) return new SourceLocation (id, line.Value, column.Value); } + + internal class LocationComparer : EqualityComparer + { + public override bool Equals (SourceLocation l1, SourceLocation l2) + { + if (l1 == null && l2 == null) + return true; + else if (l1 == null || l2 == null) + return false; + + return (l1.Line == l2.Line && + l1.Column == l2.Column && + l1.Id == l2.Id); + } + + public override int GetHashCode (SourceLocation loc) + { + int hCode = loc.Line ^ loc.Column; + return loc.Id.GetHashCode () ^ hCode.GetHashCode (); + } + } + internal object AsLocation () => new { scriptId = id.ToString (), diff --git a/src/Components/WebAssembly/DebugProxy/src/MonoDebugProxy/ws-proxy/MonoProxy.cs b/src/Components/WebAssembly/DebugProxy/src/MonoDebugProxy/ws-proxy/MonoProxy.cs index 7f11df13d835..6f73724fdaf0 100644 --- a/src/Components/WebAssembly/DebugProxy/src/MonoDebugProxy/ws-proxy/MonoProxy.cs +++ b/src/Components/WebAssembly/DebugProxy/src/MonoDebugProxy/ws-proxy/MonoProxy.cs @@ -184,6 +184,7 @@ protected override async Task AcceptCommand (MessageId id, string method, } var bpid = resp.Value["breakpointId"]?.ToString (); + var locations = resp.Value["locations"]?.Values(); var request = BreakpointRequest.Parse (bpid, args); context.BreakpointRequests[bpid] = request; if (await IsRuntimeAlreadyReadyAlready (id, token)) { @@ -193,7 +194,8 @@ protected override async Task AcceptCommand (MessageId id, string method, await SetBreakpoint (id, store, request, token); } - SendResponse (id, Result.OkFromObject (request.AsSetBreakpointByUrlResponse()), token); + var result = Result.OkFromObject (request.AsSetBreakpointByUrlResponse (locations)); + SendResponse (id, result, token); return true; } @@ -765,17 +767,21 @@ async Task SetBreakpoint (SessionId sessionId, DebugStore store, BreakpointReque return; } - var locations = store.FindBreakpointLocations (req).ToList (); + var comparer = new SourceLocation.LocationComparer (); + // if column is specified the frontend wants the exact matches + // and will clear the bp if it isn't close enoug + var locations = store.FindBreakpointLocations (req) + .Distinct (comparer) + .Where (l => l.Line == req.Line && (req.Column == 0 || l.Column == req.Column)) + .OrderBy (l => l.Column) + .GroupBy (l => l.Id); + logger.LogDebug ("BP request for '{req}' runtime ready {context.RuntimeReady}", req, GetContext (sessionId).IsRuntimeReady); var breakpoints = new List (); - // if column is specified the frontend wants the exact matches - // and will clear the bp if it isn't close enough - if (req.Column != 0) - locations = locations.Where (l => l.Column == req.Column).ToList (); - - foreach (var loc in locations) { + foreach (var sourceId in locations) { + var loc = sourceId.First (); var bp = await SetMonoBreakpoint (sessionId, req.Id, loc, token); // If we didn't successfully enable the breakpoint