From 347a41ca6b0f9b065d350ac89f9e9e9f90e3aa13 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GEPIA6N\\Thays" Date: Mon, 9 May 2022 17:23:51 -0300 Subject: [PATCH 1/6] Implement get bytes from loaded_files using debugger protocol. --- src/mono/mono/component/debugger-protocol.h | 5 +- src/mono/mono/component/mini-wasm-debugger.c | 10 +++ src/mono/mono/metadata/mono-debug.c | 13 ++++ src/mono/mono/mini/mini-wasm.h | 2 + .../debugger/BrowserDebugProxy/DebugStore.cs | 63 ++++++++++++------- .../debugger/BrowserDebugProxy/MonoProxy.cs | 7 ++- .../BrowserDebugProxy/MonoSDBHelper.cs | 35 ++++++++++- src/mono/wasm/runtime/driver.c | 18 ++++++ .../metadata/details/assembly-functions.h | 1 + 9 files changed, 128 insertions(+), 26 deletions(-) diff --git a/src/mono/mono/component/debugger-protocol.h b/src/mono/mono/component/debugger-protocol.h index af28674c42d52..70753b7ec7011 100644 --- a/src/mono/mono/component/debugger-protocol.h +++ b/src/mono/mono/component/debugger-protocol.h @@ -11,7 +11,7 @@ */ #define MAJOR_VERSION 2 -#define MINOR_VERSION 60 +#define MINOR_VERSION 61 typedef enum { MDBGPROT_CMD_COMPOSITE = 100 @@ -36,7 +36,8 @@ typedef enum { MDBGPROT_CMD_VM_READ_MEMORY = 16, MDBGPROT_CMD_VM_WRITE_MEMORY = 17, MDBGPROT_CMD_GET_ASSEMBLY_BY_NAME = 18, - MDBGPROT_CMD_GET_MODULE_BY_GUID = 19 + MDBGPROT_CMD_GET_MODULE_BY_GUID = 19, + MDBGPROT_CMD_GET_ASSEMBLY_BYTES = 20, //wasm specific } MdbgProtCmdVM; typedef enum { diff --git a/src/mono/mono/component/mini-wasm-debugger.c b/src/mono/mono/component/mini-wasm-debugger.c index 28b83912a9daa..a4180e150431f 100644 --- a/src/mono/mono/component/mini-wasm-debugger.c +++ b/src/mono/mono/component/mini-wasm-debugger.c @@ -403,6 +403,16 @@ mono_wasm_send_dbg_command (int id, MdbgProtCommandSet command_set, int command, invoke_data.endp = data + size; error = mono_do_invoke_method (tls, &buf, &invoke_data, data, &data); } + else if (command_set == MDBGPROT_CMD_SET_VM && (command == MDBGPROT_CMD_GET_ASSEMBLY_BYTES)) + { + char* assembly_name = m_dbgprot_decode_string (data, &data, data + size); + int assembly_size = 0; + int symfile_size = 0; + const char* assembly_bytes = mono_wasm_get_assembly_bytes (assembly_name, &assembly_size); + const char* pdb_bytes = mono_get_symfile_bytes_from_bundle (assembly_name, &symfile_size); + m_dbgprot_buffer_add_byte_array (&buf, (uint8_t *) assembly_bytes, assembly_size); + m_dbgprot_buffer_add_byte_array (&buf, (uint8_t *) pdb_bytes, symfile_size); + } else error = mono_process_dbg_packet (id, command_set, command, &no_reply, data, data + size, &buf); diff --git a/src/mono/mono/metadata/mono-debug.c b/src/mono/mono/metadata/mono-debug.c index 944a5605532cc..b6ac651945384 100644 --- a/src/mono/mono/metadata/mono-debug.c +++ b/src/mono/mono/metadata/mono-debug.c @@ -1112,6 +1112,19 @@ open_symfile_from_bundle (MonoImage *image) return NULL; } +const mono_byte * +mono_get_symfile_bytes_from_bundle (const char *assembly_name, int *size) +{ + BundledSymfile *bsymfile; + for (bsymfile = bundled_symfiles; bsymfile; bsymfile = bsymfile->next) { + if (strcmp (bsymfile->aname, assembly_name)) + continue; + *size = bsymfile->size; + return bsymfile->raw_contents; + } + return NULL; +} + void mono_debugger_lock (void) { diff --git a/src/mono/mono/mini/mini-wasm.h b/src/mono/mono/mini/mini-wasm.h index d307077de1c33..e83a1baefb193 100644 --- a/src/mono/mono/mini/mini-wasm.h +++ b/src/mono/mono/mini/mini-wasm.h @@ -103,6 +103,8 @@ G_EXTERN_C void mono_wasm_enable_debugging (int log_level); void mono_wasm_set_timeout (int timeout); int mono_wasm_assembly_already_added (const char *assembly_name); +const unsigned char *mono_wasm_get_assembly_bytes (const char *name, unsigned int *size); + void mono_wasm_print_stack_trace (void); gboolean diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs index 47bc311b31905..b4dfde36b279b 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs @@ -1285,36 +1285,55 @@ public IEnumerable Add(SessionId id, string name, byte[] assembly_da } } - public async IAsyncEnumerable Load(SessionId id, string[] loaded_files, [EnumeratorCancellation] CancellationToken token) + public async IAsyncEnumerable Load(SessionId id, string[] loaded_files, MonoSDBHelper sdbAgent, [EnumeratorCancellation] CancellationToken token) { var asm_files = new List(); - var pdb_files = new List(); - foreach (string file_name in loaded_files) - { - if (file_name.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase)) - pdb_files.Add(file_name); - else - asm_files.Add(file_name); - } - List steps = new List(); - foreach (string url in asm_files) + + if (sdbAgent is null) { - try + var pdb_files = new List(); + foreach (string file_name in loaded_files) { - string candidate_pdb = Path.ChangeExtension(url, "pdb"); - string pdb = pdb_files.FirstOrDefault(n => n == candidate_pdb); + if (file_name.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase)) + pdb_files.Add(file_name); + else + asm_files.Add(file_name); + } - steps.Add( - new DebugItem - { - Url = url, - Data = Task.WhenAll(client.GetByteArrayAsync(url, token), pdb != null ? client.GetByteArrayAsync(pdb, token) : Task.FromResult(null)) - }); + foreach (string url in asm_files) + { + try + { + string candidate_pdb = Path.ChangeExtension(url, "pdb"); + string pdb = pdb_files.FirstOrDefault(n => n == candidate_pdb); + + steps.Add( + new DebugItem + { + Url = url, + Data = Task.WhenAll(client.GetByteArrayAsync(url, token), pdb != null ? client.GetByteArrayAsync(pdb, token) : Task.FromResult(null)) + }); + } + catch (Exception e) + { + logger.LogDebug($"Failed to read {url} ({e.Message})"); + } } - catch (Exception e) + } + else + { + foreach (string file_name in loaded_files) { - logger.LogDebug($"Failed to read {url} ({e.Message})"); + if (!file_name.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase)) + { + steps.Add( + new DebugItem + { + Url = file_name, + Data = sdbAgent.GetBytesFromAssemblyAndPdb(System.IO.Path.GetFileName(file_name), token) + }); + } } } diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index 4dc9d03892dca..e0b495dbf3a75 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -1432,7 +1432,12 @@ internal async Task LoadStore(SessionId sessionId, CancellationToken } else { - await foreach (SourceFile source in context.store.Load(sessionId, loaded_files, token).WithCancellation(token)) + var useDebuggerProtocol = false; + (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, useDebuggerProtocol ? context.SdbAgent : null, token).WithCancellation(token)) { await OnSourceFileAdded(sessionId, source, context, token); } diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs index a3e0fb51fafba..3b77e27d3d8bf 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs @@ -140,7 +140,8 @@ internal enum CmdVM { VmReadMemory = 16, VmWriteMemory = 17, GetAssemblyByName = 18, - GetModuleByGUID = 19 + GetModuleByGUID = 19, + GetAssemblyAndPdbBytes = 20 } internal enum CmdFrame { @@ -747,6 +748,9 @@ internal sealed class MonoSDBHelper private static int MINOR_VERSION = 61; private static int MAJOR_VERSION = 2; + private int VmMinorVersion { get; set; } + private int VmMajorVersion { get; set; } + private Dictionary methods; private Dictionary assemblies; private Dictionary types; @@ -769,6 +773,8 @@ public MonoSDBHelper(MonoProxy proxy, ILogger logger, SessionId sessionId) this.proxy = proxy; this.logger = logger; this.sessionId = sessionId; + this.VmMajorVersion = -1; + this.VmMinorVersion = -1; ResetStore(null); } @@ -885,6 +891,18 @@ public void ClearCache() pointerValues = new Dictionary(); } + public async Task<(int, int)> GetVMVersion(CancellationToken token) + { + if (VmMajorVersion != -1) + return (VmMajorVersion, VmMinorVersion); + using var commandParamsWriter = new MonoBinaryWriter(); + using var retDebuggerCmdReader = await SendDebuggerAgentCommand(CmdVM.Version, commandParamsWriter, token); + retDebuggerCmdReader.ReadString(); //vm version + VmMajorVersion = retDebuggerCmdReader.ReadInt32(); + VmMinorVersion = retDebuggerCmdReader.ReadInt32(); + return (VmMajorVersion, VmMinorVersion); + } + public async Task SetProtocolVersion(CancellationToken token) { using var commandParamsWriter = new MonoBinaryWriter(); @@ -2504,6 +2522,21 @@ public async Task ApplyUpdates(int moduleId, string dmeta, string dil, str await SendDebuggerAgentCommand(CmdModule.ApplyChanges, commandParamsWriter, token); return true; } + + public async Task GetBytesFromAssemblyAndPdb(string assemblyName, CancellationToken token) + { + using var commandParamsWriter = new MonoBinaryWriter(); + commandParamsWriter.Write(assemblyName); + var retDebuggerCmdReader = await SendDebuggerAgentCommand(CmdVM.GetAssemblyAndPdbBytes, commandParamsWriter, token); + int assembly_size = retDebuggerCmdReader.ReadInt32(); + byte[] assembly_buf = retDebuggerCmdReader.ReadBytes(assembly_size); + int pdb_size = retDebuggerCmdReader.ReadInt32(); + byte[] pdb_buf = retDebuggerCmdReader.ReadBytes(pdb_size); + byte[][] ret = new byte[2][]; + ret[0] = assembly_buf; + ret[1] = pdb_buf; + return ret; + } } internal static class HelperExtensions diff --git a/src/mono/wasm/runtime/driver.c b/src/mono/wasm/runtime/driver.c index 3a5977ee2c965..eae1024b446be 100644 --- a/src/mono/wasm/runtime/driver.c +++ b/src/mono/wasm/runtime/driver.c @@ -230,6 +230,24 @@ mono_wasm_assembly_already_added (const char *assembly_name) return 0; } +const unsigned char * +mono_wasm_get_assembly_bytes (const char *assembly_name, unsigned int *size) +{ + if (assembly_count == 0) + return 0; + + WasmAssembly *entry = assemblies; + while (entry != NULL) { + if (strcmp (entry->assembly.name, assembly_name) == 0) + { + *size = entry->assembly.size; + return entry->assembly.data; + } + entry = entry->next; + } + return NULL; +} + typedef struct WasmSatelliteAssembly_ WasmSatelliteAssembly; struct WasmSatelliteAssembly_ { diff --git a/src/native/public/mono/metadata/details/assembly-functions.h b/src/native/public/mono/metadata/details/assembly-functions.h index 4634ba4046a0f..df752b6695619 100644 --- a/src/native/public/mono/metadata/details/assembly-functions.h +++ b/src/native/public/mono/metadata/details/assembly-functions.h @@ -64,6 +64,7 @@ MONO_API_FUNCTION(MONO_RT_EXTERNAL_ONLY void, mono_assembly_name_free, (MonoAsse MONO_API_FUNCTION(void, mono_register_bundled_assemblies, (const MonoBundledAssembly **assemblies)) MONO_API_FUNCTION(void, mono_register_symfile_for_assembly, (const char* assembly_name, const mono_byte *raw_contents, int size)) +MONO_API_FUNCTION(const mono_byte *, mono_get_symfile_bytes_from_bundle, (const char* assembly_name, int *size)) MONO_API_FUNCTION(void, mono_set_assemblies_path, (const char* path)) From 1f22eba929df370c013d9e712c73677a05a888df Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Tue, 10 May 2022 12:36:12 -0300 Subject: [PATCH 2/6] fix pdb size == nul --- src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs index 3b77e27d3d8bf..c3df9ab4b96b9 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs @@ -2531,7 +2531,9 @@ public async Task GetBytesFromAssemblyAndPdb(string assemblyName, Canc int assembly_size = retDebuggerCmdReader.ReadInt32(); byte[] assembly_buf = retDebuggerCmdReader.ReadBytes(assembly_size); int pdb_size = retDebuggerCmdReader.ReadInt32(); - byte[] pdb_buf = retDebuggerCmdReader.ReadBytes(pdb_size); + byte[] pdb_buf = null; + if (pdb_size > 0) + pdb_buf = retDebuggerCmdReader.ReadBytes(pdb_size); byte[][] ret = new byte[2][]; ret[0] = assembly_buf; ret[1] = pdb_buf; From 8b2a01c7798be9038dc62a0f6986f4fcf70ecd9f Mon Sep 17 00:00:00 2001 From: "DESKTOP-GEPIA6N\\Thays" Date: Fri, 27 May 2022 16:41:02 -0300 Subject: [PATCH 3/6] Adressing @radical comments. --- src/mono/mono/component/mini-wasm-debugger.c | 20 +++++++++++++------ .../debugger/BrowserDebugProxy/DebugStore.cs | 6 +++--- .../debugger/BrowserDebugProxy/MonoProxy.cs | 2 +- .../BrowserDebugProxy/MonoSDBHelper.cs | 6 ++++-- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/mono/mono/component/mini-wasm-debugger.c b/src/mono/mono/component/mini-wasm-debugger.c index 0c7945d8e7caf..8ee7d724f3edb 100644 --- a/src/mono/mono/component/mini-wasm-debugger.c +++ b/src/mono/mono/component/mini-wasm-debugger.c @@ -421,12 +421,20 @@ mono_wasm_send_dbg_command (int id, MdbgProtCommandSet command_set, int command, else if (command_set == MDBGPROT_CMD_SET_VM && (command == MDBGPROT_CMD_GET_ASSEMBLY_BYTES)) { char* assembly_name = m_dbgprot_decode_string (data, &data, data + size); - int assembly_size = 0; - int symfile_size = 0; - const char* assembly_bytes = mono_wasm_get_assembly_bytes (assembly_name, &assembly_size); - const char* pdb_bytes = mono_get_symfile_bytes_from_bundle (assembly_name, &symfile_size); - m_dbgprot_buffer_add_byte_array (&buf, (uint8_t *) assembly_bytes, assembly_size); - m_dbgprot_buffer_add_byte_array (&buf, (uint8_t *) pdb_bytes, symfile_size); + if (assembly_name == NULL) + { + m_dbgprot_buffer_add_int (&buf, 0); + m_dbgprot_buffer_add_int (&buf, 0); + } + else + { + int assembly_size = 0; + int symfile_size = 0; + const char* assembly_bytes = mono_wasm_get_assembly_bytes (assembly_name, &assembly_size); + const char* pdb_bytes = mono_get_symfile_bytes_from_bundle (assembly_name, &symfile_size); + m_dbgprot_buffer_add_byte_array (&buf, (uint8_t *) assembly_bytes, assembly_size); + m_dbgprot_buffer_add_byte_array (&buf, (uint8_t *) pdb_bytes, symfile_size); + } } else error = mono_process_dbg_packet (id, command_set, command, &no_reply, data, data + size, &buf); diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs index 40a35cab5ac2c..d925b68d5c9ea 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs @@ -1279,12 +1279,12 @@ public IEnumerable Add(SessionId id, string name, byte[] assembly_da } } - public async IAsyncEnumerable Load(SessionId id, string[] loaded_files, MonoSDBHelper sdbAgent, [EnumeratorCancellation] CancellationToken token) + public async IAsyncEnumerable Load(SessionId id, string[] loaded_files, ExecutionContext context, bool useDebuggerProtocol, [EnumeratorCancellation] CancellationToken token) { var asm_files = new List(); List steps = new List(); - if (sdbAgent is null) + if (!useDebuggerProtocol) { var pdb_files = new List(); foreach (string file_name in loaded_files) @@ -1325,7 +1325,7 @@ public async IAsyncEnumerable Load(SessionId id, string[] loaded_fil new DebugItem { Url = file_name, - Data = sdbAgent.GetBytesFromAssemblyAndPdb(System.IO.Path.GetFileName(file_name), token) + Data = context.SdbAgent.GetBytesFromAssemblyAndPdb(System.IO.Path.GetFileName(file_name), token) }); } } diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index 64ac806e382b3..6ae2f7dc917cd 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -1444,7 +1444,7 @@ internal async Task LoadStore(SessionId sessionId, CancellationToken if (MajorVersion == 2 && MinorVersion >= 61) useDebuggerProtocol = true; - await foreach (SourceFile source in context.store.Load(sessionId, loaded_files, useDebuggerProtocol ? context.SdbAgent : null, token).WithCancellation(token)) + await foreach (SourceFile source in context.store.Load(sessionId, loaded_files, context, useDebuggerProtocol, token)) { await OnSourceFileAdded(sessionId, source, context, token); } diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs index 0cfb9042daf94..1d68e9623e15d 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs @@ -2149,12 +2149,14 @@ public async Task ApplyUpdates(int moduleId, string dmeta, string dil, str public async Task GetBytesFromAssemblyAndPdb(string assemblyName, CancellationToken token) { using var commandParamsWriter = new MonoBinaryWriter(); + byte[] assembly_buf = null; + byte[] pdb_buf = null; commandParamsWriter.Write(assemblyName); var retDebuggerCmdReader = await SendDebuggerAgentCommand(CmdVM.GetAssemblyAndPdbBytes, commandParamsWriter, token); int assembly_size = retDebuggerCmdReader.ReadInt32(); - byte[] assembly_buf = retDebuggerCmdReader.ReadBytes(assembly_size); + if (assembly_size > 0) + assembly_buf = retDebuggerCmdReader.ReadBytes(assembly_size); int pdb_size = retDebuggerCmdReader.ReadInt32(); - byte[] pdb_buf = null; if (pdb_size > 0) pdb_buf = retDebuggerCmdReader.ReadBytes(pdb_size); byte[][] ret = new byte[2][]; From a948989b0d09476aa0605a8b23a148fe9ed65378 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GEPIA6N\\Thays" Date: Sun, 29 May 2022 10:53:48 -0300 Subject: [PATCH 4/6] Fix build. --- src/mono/mono/component/mini-wasm-debugger.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mono/mono/component/mini-wasm-debugger.c b/src/mono/mono/component/mini-wasm-debugger.c index 8ee7d724f3edb..082ebf6e66586 100644 --- a/src/mono/mono/component/mini-wasm-debugger.c +++ b/src/mono/mono/component/mini-wasm-debugger.c @@ -428,10 +428,10 @@ mono_wasm_send_dbg_command (int id, MdbgProtCommandSet command_set, int command, } else { - int assembly_size = 0; - int symfile_size = 0; - const char* assembly_bytes = mono_wasm_get_assembly_bytes (assembly_name, &assembly_size); - const char* pdb_bytes = mono_get_symfile_bytes_from_bundle (assembly_name, &symfile_size); + unsigned int assembly_size = 0; + unsigned int symfile_size = 0; + const unsigned char* assembly_bytes = mono_wasm_get_assembly_bytes (assembly_name, &assembly_size); + const unsigned char* pdb_bytes = mono_get_symfile_bytes_from_bundle (assembly_name, &symfile_size); m_dbgprot_buffer_add_byte_array (&buf, (uint8_t *) assembly_bytes, assembly_size); m_dbgprot_buffer_add_byte_array (&buf, (uint8_t *) pdb_bytes, symfile_size); } From b441863663d86e485fb413e7b40cd088fcab2f0e Mon Sep 17 00:00:00 2001 From: "DESKTOP-GEPIA6N\\Thays" Date: Mon, 30 May 2022 08:43:59 -0300 Subject: [PATCH 5/6] fix compilation --- src/mono/mono/component/mini-wasm-debugger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/component/mini-wasm-debugger.c b/src/mono/mono/component/mini-wasm-debugger.c index 082ebf6e66586..5bc3e44a31b0e 100644 --- a/src/mono/mono/component/mini-wasm-debugger.c +++ b/src/mono/mono/component/mini-wasm-debugger.c @@ -429,7 +429,7 @@ mono_wasm_send_dbg_command (int id, MdbgProtCommandSet command_set, int command, else { unsigned int assembly_size = 0; - unsigned int symfile_size = 0; + int symfile_size = 0; const unsigned char* assembly_bytes = mono_wasm_get_assembly_bytes (assembly_name, &assembly_size); const unsigned char* pdb_bytes = mono_get_symfile_bytes_from_bundle (assembly_name, &symfile_size); m_dbgprot_buffer_add_byte_array (&buf, (uint8_t *) assembly_bytes, assembly_size); From e41a8aa904e413206497cdb9c71775609b0d212f Mon Sep 17 00:00:00 2001 From: "DESKTOP-GEPIA6N\\Thays" Date: Thu, 2 Jun 2022 14:03:11 -0300 Subject: [PATCH 6/6] Addressing @radical comments. --- .../wasm/debugger/BrowserDebugProxy/DebugStore.cs | 15 +++++++++++++-- .../debugger/BrowserDebugProxy/MonoSDBHelper.cs | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs index d925b68d5c9ea..0ae8986ed5a20 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs @@ -1319,15 +1319,21 @@ public async IAsyncEnumerable Load(SessionId id, string[] loaded_fil { foreach (string file_name in loaded_files) { - if (!file_name.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase)) + if (file_name.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase)) + continue; + try { steps.Add( new DebugItem { Url = file_name, - Data = context.SdbAgent.GetBytesFromAssemblyAndPdb(System.IO.Path.GetFileName(file_name), token) + Data = context.SdbAgent.GetBytesFromAssemblyAndPdb(Path.GetFileName(file_name), token) }); } + catch (Exception e) + { + logger.LogDebug($"Failed to read {file_name} ({e.Message})"); + } } } @@ -1337,6 +1343,11 @@ public async IAsyncEnumerable Load(SessionId id, string[] loaded_fil try { byte[][] bytes = await step.Data.ConfigureAwait(false); + if (bytes[0] == null) + { + logger.LogDebug($"Bytes from assembly {step.Url} is NULL"); + continue; + } assembly = new AssemblyInfo(monoProxy, id, step.Url, bytes[0], bytes[1], logger, token); } catch (Exception e) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs index 1d68e9623e15d..1ee180fadb73e 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs @@ -2155,7 +2155,7 @@ public async Task GetBytesFromAssemblyAndPdb(string assemblyName, Canc var retDebuggerCmdReader = await SendDebuggerAgentCommand(CmdVM.GetAssemblyAndPdbBytes, commandParamsWriter, token); int assembly_size = retDebuggerCmdReader.ReadInt32(); if (assembly_size > 0) - assembly_buf = retDebuggerCmdReader.ReadBytes(assembly_size); + assembly_buf = retDebuggerCmdReader.ReadBytes(assembly_size); int pdb_size = retDebuggerCmdReader.ReadInt32(); if (pdb_size > 0) pdb_buf = retDebuggerCmdReader.ReadBytes(pdb_size);