Skip to content

Commit 70bc520

Browse files
authored
Revert "[wasm][debugger] Implement get bytes from loaded_files using debugger protocol. (#69072)"
This reverts commit 56e58d3.
1 parent 2f0a796 commit 70bc520

9 files changed

Lines changed: 26 additions & 150 deletions

File tree

src/mono/mono/component/debugger-protocol.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
#define MAJOR_VERSION 2
14-
#define MINOR_VERSION 61
14+
#define MINOR_VERSION 60
1515

1616
typedef enum {
1717
MDBGPROT_CMD_COMPOSITE = 100
@@ -36,8 +36,7 @@ typedef enum {
3636
MDBGPROT_CMD_VM_READ_MEMORY = 16,
3737
MDBGPROT_CMD_VM_WRITE_MEMORY = 17,
3838
MDBGPROT_CMD_GET_ASSEMBLY_BY_NAME = 18,
39-
MDBGPROT_CMD_GET_MODULE_BY_GUID = 19,
40-
MDBGPROT_CMD_GET_ASSEMBLY_BYTES = 20, //wasm specific
39+
MDBGPROT_CMD_GET_MODULE_BY_GUID = 19
4140
} MdbgProtCmdVM;
4241

4342
typedef enum {

src/mono/mono/component/mini-wasm-debugger.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -418,24 +418,6 @@ mono_wasm_send_dbg_command (int id, MdbgProtCommandSet command_set, int command,
418418
invoke_data.endp = data + size;
419419
error = mono_do_invoke_method (tls, &buf, &invoke_data, data, &data);
420420
}
421-
else if (command_set == MDBGPROT_CMD_SET_VM && (command == MDBGPROT_CMD_GET_ASSEMBLY_BYTES))
422-
{
423-
char* assembly_name = m_dbgprot_decode_string (data, &data, data + size);
424-
if (assembly_name == NULL)
425-
{
426-
m_dbgprot_buffer_add_int (&buf, 0);
427-
m_dbgprot_buffer_add_int (&buf, 0);
428-
}
429-
else
430-
{
431-
unsigned int assembly_size = 0;
432-
int symfile_size = 0;
433-
const unsigned char* assembly_bytes = mono_wasm_get_assembly_bytes (assembly_name, &assembly_size);
434-
const unsigned char* pdb_bytes = mono_get_symfile_bytes_from_bundle (assembly_name, &symfile_size);
435-
m_dbgprot_buffer_add_byte_array (&buf, (uint8_t *) assembly_bytes, assembly_size);
436-
m_dbgprot_buffer_add_byte_array (&buf, (uint8_t *) pdb_bytes, symfile_size);
437-
}
438-
}
439421
else
440422
error = mono_process_dbg_packet (id, command_set, command, &no_reply, data, data + size, &buf);
441423

src/mono/mono/metadata/mono-debug.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,19 +1112,6 @@ open_symfile_from_bundle (MonoImage *image)
11121112
return NULL;
11131113
}
11141114

1115-
const mono_byte *
1116-
mono_get_symfile_bytes_from_bundle (const char *assembly_name, int *size)
1117-
{
1118-
BundledSymfile *bsymfile;
1119-
for (bsymfile = bundled_symfiles; bsymfile; bsymfile = bsymfile->next) {
1120-
if (strcmp (bsymfile->aname, assembly_name))
1121-
continue;
1122-
*size = bsymfile->size;
1123-
return bsymfile->raw_contents;
1124-
}
1125-
return NULL;
1126-
}
1127-
11281115
void
11291116
mono_debugger_lock (void)
11301117
{

src/mono/mono/mini/mini-wasm.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ G_EXTERN_C void mono_wasm_enable_debugging (int log_level);
103103
void mono_wasm_set_timeout (int timeout);
104104

105105
int mono_wasm_assembly_already_added (const char *assembly_name);
106-
const unsigned char *mono_wasm_get_assembly_bytes (const char *name, unsigned int *size);
107-
108106
void mono_wasm_print_stack_trace (void);
109107

110108
gboolean

src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,61 +1366,36 @@ public IEnumerable<SourceFile> Add(SessionId id, string name, byte[] assembly_da
13661366
}
13671367
}
13681368

1369-
public async IAsyncEnumerable<SourceFile> Load(SessionId id, string[] loaded_files, ExecutionContext context, bool useDebuggerProtocol, [EnumeratorCancellation] CancellationToken token)
1369+
public async IAsyncEnumerable<SourceFile> Load(SessionId id, string[] loaded_files, [EnumeratorCancellation] CancellationToken token)
13701370
{
13711371
var asm_files = new List<string>();
1372-
List<DebugItem> steps = new List<DebugItem>();
1373-
1374-
if (!useDebuggerProtocol)
1372+
var pdb_files = new List<string>();
1373+
foreach (string file_name in loaded_files)
13751374
{
1376-
var pdb_files = new List<string>();
1377-
foreach (string file_name in loaded_files)
1378-
{
1379-
if (file_name.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase))
1380-
pdb_files.Add(file_name);
1381-
else
1382-
asm_files.Add(file_name);
1383-
}
1375+
if (file_name.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase))
1376+
pdb_files.Add(file_name);
1377+
else
1378+
asm_files.Add(file_name);
1379+
}
13841380

1385-
foreach (string url in asm_files)
1381+
List<DebugItem> steps = new List<DebugItem>();
1382+
foreach (string url in asm_files)
1383+
{
1384+
try
13861385
{
1387-
try
1388-
{
1389-
string candidate_pdb = Path.ChangeExtension(url, "pdb");
1390-
string pdb = pdb_files.FirstOrDefault(n => n == candidate_pdb);
1386+
string candidate_pdb = Path.ChangeExtension(url, "pdb");
1387+
string pdb = pdb_files.FirstOrDefault(n => n == candidate_pdb);
13911388

1392-
steps.Add(
1393-
new DebugItem
1394-
{
1395-
Url = url,
1396-
Data = Task.WhenAll(MonoProxy.HttpClient.GetByteArrayAsync(url, token), pdb != null ? MonoProxy.HttpClient.GetByteArrayAsync(pdb, token) : Task.FromResult<byte[]>(null))
1397-
});
1398-
}
1399-
catch (Exception e)
1400-
{
1401-
logger.LogDebug($"Failed to read {url} ({e.Message})");
1402-
}
1389+
steps.Add(
1390+
new DebugItem
1391+
{
1392+
Url = url,
1393+
Data = Task.WhenAll(MonoProxy.HttpClient.GetByteArrayAsync(url, token), pdb != null ? MonoProxy.HttpClient.GetByteArrayAsync(pdb, token) : Task.FromResult<byte[]>(null))
1394+
});
14031395
}
1404-
}
1405-
else
1406-
{
1407-
foreach (string file_name in loaded_files)
1396+
catch (Exception e)
14081397
{
1409-
if (file_name.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase))
1410-
continue;
1411-
try
1412-
{
1413-
steps.Add(
1414-
new DebugItem
1415-
{
1416-
Url = file_name,
1417-
Data = context.SdbAgent.GetBytesFromAssemblyAndPdb(Path.GetFileName(file_name), token)
1418-
});
1419-
}
1420-
catch (Exception e)
1421-
{
1422-
logger.LogDebug($"Failed to read {file_name} ({e.Message})");
1423-
}
1398+
logger.LogDebug($"Failed to read {url} ({e.Message})");
14241399
}
14251400
}
14261401

@@ -1430,11 +1405,6 @@ public async IAsyncEnumerable<SourceFile> Load(SessionId id, string[] loaded_fil
14301405
try
14311406
{
14321407
byte[][] bytes = await step.Data.ConfigureAwait(false);
1433-
if (bytes[0] == null)
1434-
{
1435-
logger.LogDebug($"Bytes from assembly {step.Url} is NULL");
1436-
continue;
1437-
}
14381408
assembly = new AssemblyInfo(monoProxy, id, step.Url, bytes[0], bytes[1], logger, token);
14391409
}
14401410
catch (Exception e)

src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,12 +1509,7 @@ internal async Task<DebugStore> LoadStore(SessionId sessionId, CancellationToken
15091509
}
15101510
else
15111511
{
1512-
var useDebuggerProtocol = false;
1513-
(int MajorVersion, int MinorVersion) = await context.SdbAgent.GetVMVersion(token);
1514-
if (MajorVersion == 2 && MinorVersion >= 61)
1515-
useDebuggerProtocol = true;
1516-
1517-
await foreach (SourceFile source in context.store.Load(sessionId, loaded_files, context, useDebuggerProtocol, token))
1512+
await foreach (SourceFile source in context.store.Load(sessionId, loaded_files, token).WithCancellation(token))
15181513
{
15191514
await OnSourceFileAdded(sessionId, source, context, token);
15201515
}

src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ internal enum CmdVM {
140140
VmReadMemory = 16,
141141
VmWriteMemory = 17,
142142
GetAssemblyByName = 18,
143-
GetModuleByGUID = 19,
144-
GetAssemblyAndPdbBytes = 20
143+
GetModuleByGUID = 19
145144
}
146145

147146
internal enum CmdFrame {
@@ -751,9 +750,6 @@ internal sealed class MonoSDBHelper
751750
private static int MINOR_VERSION = 61;
752751
private static int MAJOR_VERSION = 2;
753752

754-
private int VmMinorVersion { get; set; }
755-
private int VmMajorVersion { get; set; }
756-
757753
private Dictionary<int, MethodInfoWithDebugInformation> methods;
758754
private Dictionary<int, AssemblyInfo> assemblies;
759755
private Dictionary<int, TypeInfoWithDebugInformation> types;
@@ -774,8 +770,6 @@ public MonoSDBHelper(MonoProxy proxy, ILogger logger, SessionId sessionId)
774770
this.proxy = proxy;
775771
this.logger = logger;
776772
this.sessionId = sessionId;
777-
this.VmMajorVersion = -1;
778-
this.VmMinorVersion = -1;
779773
ValueCreator = new(this, logger);
780774
ResetStore(null);
781775
}
@@ -889,18 +883,6 @@ public async Task<TypeInfoWithDebugInformation> GetTypeInfo(int typeId, Cancella
889883

890884
public void ClearCache() => ValueCreator.ClearCache();
891885

892-
public async Task<(int, int)> GetVMVersion(CancellationToken token)
893-
{
894-
if (VmMajorVersion != -1)
895-
return (VmMajorVersion, VmMinorVersion);
896-
using var commandParamsWriter = new MonoBinaryWriter();
897-
using var retDebuggerCmdReader = await SendDebuggerAgentCommand(CmdVM.Version, commandParamsWriter, token);
898-
retDebuggerCmdReader.ReadString(); //vm version
899-
VmMajorVersion = retDebuggerCmdReader.ReadInt32();
900-
VmMinorVersion = retDebuggerCmdReader.ReadInt32();
901-
return (VmMajorVersion, VmMinorVersion);
902-
}
903-
904886
public async Task<bool> SetProtocolVersion(CancellationToken token)
905887
{
906888
using var commandParamsWriter = new MonoBinaryWriter();
@@ -2146,24 +2128,6 @@ public async Task<bool> ApplyUpdates(int moduleId, string dmeta, string dil, str
21462128
return true;
21472129
}
21482130

2149-
public async Task<byte[][]> GetBytesFromAssemblyAndPdb(string assemblyName, CancellationToken token)
2150-
{
2151-
using var commandParamsWriter = new MonoBinaryWriter();
2152-
byte[] assembly_buf = null;
2153-
byte[] pdb_buf = null;
2154-
commandParamsWriter.Write(assemblyName);
2155-
var retDebuggerCmdReader = await SendDebuggerAgentCommand(CmdVM.GetAssemblyAndPdbBytes, commandParamsWriter, token);
2156-
int assembly_size = retDebuggerCmdReader.ReadInt32();
2157-
if (assembly_size > 0)
2158-
assembly_buf = retDebuggerCmdReader.ReadBytes(assembly_size);
2159-
int pdb_size = retDebuggerCmdReader.ReadInt32();
2160-
if (pdb_size > 0)
2161-
pdb_buf = retDebuggerCmdReader.ReadBytes(pdb_size);
2162-
byte[][] ret = new byte[2][];
2163-
ret[0] = assembly_buf;
2164-
ret[1] = pdb_buf;
2165-
return ret;
2166-
}
21672131
private static readonly string[] s_primitiveTypeNames = new[]
21682132
{
21692133
"bool",

src/mono/wasm/runtime/driver.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -238,24 +238,6 @@ mono_wasm_assembly_already_added (const char *assembly_name)
238238
return 0;
239239
}
240240

241-
const unsigned char *
242-
mono_wasm_get_assembly_bytes (const char *assembly_name, unsigned int *size)
243-
{
244-
if (assembly_count == 0)
245-
return 0;
246-
247-
WasmAssembly *entry = assemblies;
248-
while (entry != NULL) {
249-
if (strcmp (entry->assembly.name, assembly_name) == 0)
250-
{
251-
*size = entry->assembly.size;
252-
return entry->assembly.data;
253-
}
254-
entry = entry->next;
255-
}
256-
return NULL;
257-
}
258-
259241
typedef struct WasmSatelliteAssembly_ WasmSatelliteAssembly;
260242

261243
struct WasmSatelliteAssembly_ {

src/native/public/mono/metadata/details/assembly-functions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ MONO_API_FUNCTION(MONO_RT_EXTERNAL_ONLY void, mono_assembly_name_free, (MonoAsse
6464

6565
MONO_API_FUNCTION(void, mono_register_bundled_assemblies, (const MonoBundledAssembly **assemblies))
6666
MONO_API_FUNCTION(void, mono_register_symfile_for_assembly, (const char* assembly_name, const mono_byte *raw_contents, int size))
67-
MONO_API_FUNCTION(const mono_byte *, mono_get_symfile_bytes_from_bundle, (const char* assembly_name, int *size))
6867

6968
MONO_API_FUNCTION(void, mono_set_assemblies_path, (const char* path))
7069

0 commit comments

Comments
 (0)