From 1070187000bead58fe6687f01ac3d8fbdc01ae4c Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Mon, 20 Jun 2022 16:45:04 -0300 Subject: [PATCH] [wasm][debugger] Fix side effect on Firefox of getting bytes from loaded_files using debugger protocol (#70990) * Fix 70983 * fix typo * Fix compilation --- .../BrowserDebugProxy/Firefox/FirefoxMonoProxy.cs | 4 ++-- .../BrowserDebugProxy/MemberReferenceResolver.cs | 2 +- .../wasm/debugger/BrowserDebugProxy/MonoProxy.cs | 23 ++++++++++++---------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/Firefox/FirefoxMonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/Firefox/FirefoxMonoProxy.cs index ba8cdf7..50a2502 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/Firefox/FirefoxMonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/Firefox/FirefoxMonoProxy.cs @@ -960,7 +960,7 @@ internal sealed class FirefoxMonoProxy : MonoProxy if (!SourceId.TryParse(script_id, out SourceId id)) return false; - SourceFile src_file = (await LoadStore(msg_id, token)).GetFileById(id); + SourceFile src_file = (await LoadStore(msg_id, false, token)).GetFileById(id); await SendEvent(msg_id, "", JObject.FromObject(new { lines = src_file.BreakableLines.ToArray(), from = script_id }), token); return true; @@ -971,7 +971,7 @@ internal sealed class FirefoxMonoProxy : MonoProxy if (!SourceId.TryParse(script_id, out SourceId id)) return false; - SourceFile src_file = (await LoadStore(msg_id, token)).GetFileById(id); + SourceFile src_file = (await LoadStore(msg_id, false, token)).GetFileById(id); try { diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MemberReferenceResolver.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MemberReferenceResolver.cs index 89089fc..aa67403 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MemberReferenceResolver.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MemberReferenceResolver.cs @@ -80,7 +80,7 @@ namespace Microsoft.WebAssembly.Diagnostics public async Task<(JObject containerObject, ArraySegment remaining)> ResolveStaticMembersInStaticTypes(ArraySegment parts, CancellationToken token) { string classNameToFind = ""; - var store = await proxy.LoadStore(sessionId, token); + var store = await proxy.LoadStore(sessionId, false, token); var methodInfo = context.CallStack.FirstOrDefault(s => s.Id == scopeId)?.Method?.Info; if (methodInfo == null) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index 1d2b77c..9a0d105 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -844,7 +844,7 @@ namespace Microsoft.WebAssembly.Diagnostics byte[] pdb_buf = retDebuggerCmdReader.ReadBytes(pdb_size); var assemblyName = await context.SdbAgent.GetAssemblyNameFromModule(moduleId, token); - DebugStore store = await LoadStore(sessionId, token); + DebugStore store = await LoadStore(sessionId, true, token); AssemblyInfo asm = store.GetAssemblyByName(assemblyName); var methods = DebugStore.EnC(asm, meta_buf, pdb_buf); foreach (var method in methods) @@ -953,7 +953,7 @@ namespace Microsoft.WebAssembly.Diagnostics var methodId = retDebuggerCmdReader.ReadInt32(); var il_pos = retDebuggerCmdReader.ReadInt32(); var flags = retDebuggerCmdReader.ReadByte(); - DebugStore store = await LoadStore(sessionId, token); + DebugStore store = await LoadStore(sessionId, true, token); var method = await context.SdbAgent.GetMethodInfo(methodId, token); if (await ShouldSkipMethod(sessionId, context, event_kind, j, method, token)) @@ -1252,7 +1252,7 @@ namespace Microsoft.WebAssembly.Diagnostics { try { - var store = await LoadStore(sessionId, token); + var store = await LoadStore(sessionId, true, token); var assembly_name = eventArgs?["assembly_name"]?.Value(); if (store.GetAssemblyByName(assembly_name) != null) @@ -1311,7 +1311,7 @@ namespace Microsoft.WebAssembly.Diagnostics var assemblyName = assemblyAndMethodTokenArr[0]; var methodToken = Convert.ToInt32(assemblyAndMethodTokenArr[1]) & 0xffffff; //token - var store = await LoadStore(sessionId, token); + var store = await LoadStore(sessionId, true, token); AssemblyInfo assembly = store.GetAssemblyByName(assemblyName); if (assembly == null) { @@ -1469,7 +1469,7 @@ namespace Microsoft.WebAssembly.Diagnostics } } - internal async Task LoadStore(SessionId sessionId, CancellationToken token) + internal async Task LoadStore(SessionId sessionId, bool tryUseDebuggerProtocol, CancellationToken token) { ExecutionContext context = GetContext(sessionId); @@ -1486,9 +1486,12 @@ namespace Microsoft.WebAssembly.Diagnostics else { var useDebuggerProtocol = false; - (int MajorVersion, int MinorVersion) = await context.SdbAgent.GetVMVersion(token); - if (MajorVersion == 2 && MinorVersion >= 61) - useDebuggerProtocol = true; + if (tryUseDebuggerProtocol) + { + (int MajorVersion, int MinorVersion) = await context.SdbAgent.GetVMVersion(token); + if (MajorVersion == 2 && MinorVersion >= 61) + useDebuggerProtocol = true; + } await foreach (SourceFile source in context.store.Load(sessionId, loaded_files, context, useDebuggerProtocol, token)) { @@ -1541,7 +1544,7 @@ namespace Microsoft.WebAssembly.Diagnostics await context.SdbAgent.EnableReceiveRequests(EventKind.EnC, token); await context.SdbAgent.EnableReceiveRequests(EventKind.MethodUpdate, token); - DebugStore store = await LoadStore(sessionId, token); + DebugStore store = await LoadStore(sessionId, true, token); context.ready.SetResult(store); await SendEvent(sessionId, "Mono.runtimeReady", new JObject(), token); await SendMonoCommand(sessionId, MonoCommands.SetDebuggerAttached(RuntimeId), token); @@ -1724,7 +1727,7 @@ namespace Microsoft.WebAssembly.Diagnostics if (!SourceId.TryParse(script_id, out SourceId id)) return false; - SourceFile src_file = (await LoadStore(msg_id, token)).GetFileById(id); + SourceFile src_file = (await LoadStore(msg_id, true, token)).GetFileById(id); try { -- 2.7.4