Skip to content

Commit 333bda3

Browse files
committed
Backporting dotnet#64394
1 parent 67b110e commit 333bda3

3 files changed

Lines changed: 32 additions & 17 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ static gboolean
426426
receive_debugger_agent_message (void *data, int len)
427427
{
428428
EM_ASM ({
429-
MONO.mono_wasm_add_dbg_command_received (1, -1, $0, $1);
429+
MONO.mono_wasm_add_dbg_command_received (1, 0, $0, $1);
430430
}, data, len);
431431
mono_wasm_save_thread_context();
432432
mono_wasm_fire_debugger_agent_message ();

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,8 @@ public PointerValue(long address, int typeId, string varName)
701701
internal class MonoSDBHelper
702702
{
703703
private static int debuggerObjectId;
704-
private static int cmdId;
705-
private static int GetId() {return cmdId++;}
704+
private static int cmdId = 1; //cmdId == 0 is used by events which come from runtime
705+
private static int GetNewId() {return cmdId++;}
706706
private static int MINOR_VERSION = 61;
707707
private static int MAJOR_VERSION = 2;
708708

@@ -869,7 +869,7 @@ public async Task<bool> EnableReceiveRequests(SessionId sessionId, EventKind eve
869869

870870
internal async Task<MonoBinaryReader> SendDebuggerAgentCommandInternal(SessionId sessionId, int command_set, int command, MemoryStream parms, CancellationToken token)
871871
{
872-
Result res = await proxy.SendMonoCommand(sessionId, MonoCommands.SendDebuggerAgentCommand(GetId(), command_set, command, Convert.ToBase64String(parms.ToArray())), token);
872+
Result res = await proxy.SendMonoCommand(sessionId, MonoCommands.SendDebuggerAgentCommand(GetNewId(), command_set, command, Convert.ToBase64String(parms.ToArray())), token);
873873
byte[] newBytes = Array.Empty<byte>();
874874
if (!res.IsErr) {
875875
newBytes = Convert.FromBase64String(res.Value?["result"]?["value"]?["value"]?.Value<string>());
@@ -907,7 +907,7 @@ internal Task<MonoBinaryReader> SendDebuggerAgentCommandWithParms<T>(SessionId s
907907

908908
internal async Task<MonoBinaryReader> SendDebuggerAgentCommandWithParmsInternal(SessionId sessionId, int command_set, int command, MemoryStream parms, int type, string extraParm, CancellationToken token)
909909
{
910-
Result res = await proxy.SendMonoCommand(sessionId, MonoCommands.SendDebuggerAgentCommandWithParms(GetId(), command_set, command, Convert.ToBase64String(parms.ToArray()), parms.ToArray().Length, type, extraParm), token);
910+
Result res = await proxy.SendMonoCommand(sessionId, MonoCommands.SendDebuggerAgentCommandWithParms(GetNewId(), command_set, command, Convert.ToBase64String(parms.ToArray()), parms.ToArray().Length, type, extraParm), token);
911911
byte[] newBytes = Array.Empty<byte>();
912912
if (!res.IsErr) {
913913
newBytes = Convert.FromBase64String(res.Value?["result"]?["value"]?["value"]?.Value<string>());
@@ -2253,7 +2253,8 @@ public async Task<JArray> GetValueTypeProxy(SessionId sessionId, int valueTypeId
22532253
commandSet = CommandSet.Vm,
22542254
command = CmdVM.InvokeMethod,
22552255
buffer = Convert.ToBase64String(command_params_to_proxy.ToArray()),
2256-
length = command_params_to_proxy.ToArray().Length
2256+
length = command_params_to_proxy.ToArray().Length,
2257+
id = GetNewId()
22572258
}),
22582259
name = propertyNameStr
22592260
}));
@@ -2470,7 +2471,8 @@ public async Task<JArray> GetObjectValues(SessionId sessionId, int objectId, Get
24702471
command = CmdObject.RefSetValues,
24712472
buffer = Convert.ToBase64String(command_params_to_set.ToArray()),
24722473
valtype,
2473-
length = command_params_to_set.ToArray().Length
2474+
length = command_params_to_set.ToArray().Length,
2475+
id = GetNewId()
24742476
}));
24752477
}
24762478
objectFields.Add(fieldValue);
@@ -2564,7 +2566,8 @@ public async Task<JArray> GetObjectProxy(SessionId sessionId, int objectId, Canc
25642566
command = CmdVM.InvokeMethod,
25652567
buffer = Convert.ToBase64String(command_params_to_set.ToArray()),
25662568
valtype = attr["set"]["valtype"],
2567-
length = command_params_to_set.ToArray().Length
2569+
length = command_params_to_set.ToArray().Length,
2570+
id = GetNewId()
25682571
});
25692572
}
25702573
continue;
@@ -2583,7 +2586,8 @@ public async Task<JArray> GetObjectProxy(SessionId sessionId, int objectId, Canc
25832586
commandSet = CommandSet.Vm,
25842587
command = CmdVM.InvokeMethod,
25852588
buffer = Convert.ToBase64String(command_params_to_get.ToArray()),
2586-
length = command_params_to_get.ToArray().Length
2589+
length = command_params_to_get.ToArray().Length,
2590+
id = GetNewId()
25872591
}),
25882592
name = propertyNameStr
25892593
}));

src/mono/wasm/runtime/library_mono.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,8 @@ var MonoSupportLib = {
568568
},
569569
},
570570

571-
mono_wasm_add_dbg_command_received: function(res_ok, id, buffer, buffer_len) {
571+
mono_wasm_add_dbg_command_received: function(res_ok, id, buffer, buffer_len)
572+
{
572573
const assembly_data = new Uint8Array(Module.HEAPU8.buffer, buffer, buffer_len);
573574
const base64String = MONO._base64Converter.toBase64StringImpl(assembly_data);
574575
const buffer_obj = {
@@ -578,7 +579,9 @@ var MonoSupportLib = {
578579
value: base64String
579580
}
580581
}
581-
MONO.commands_received = buffer_obj;
582+
if (MONO.commands_received.has(id))
583+
console.warn("Addind an id that already exists in commands_received");
584+
MONO.commands_received.set(id, buffer_obj);
582585
},
583586

584587
mono_wasm_malloc_and_set_debug_buffer: function (command_parameters)
@@ -594,11 +597,18 @@ var MonoSupportLib = {
594597
this._debugger_heap_bytes.set(this._base64_to_uint8 (command_parameters));
595598
},
596599

600+
mono_get_and_delete_from_commands_received: function (id)
601+
{
602+
const res = MONO.commands_received.get(id);
603+
MONO.commands_received.delete(id);
604+
return res;
605+
},
606+
597607
mono_wasm_send_dbg_command_with_parms: function (id, command_set, command, command_parameters, length, valtype, newvalue)
598608
{
599609
this.mono_wasm_malloc_and_set_debug_buffer(command_parameters);
600610
this._c_fn_table.mono_wasm_send_dbg_command_with_parms_wrapper (id, command_set, command, this._debugger_buffer, length, valtype, newvalue.toString());
601-
let { res_ok, res } = MONO.commands_received;
611+
let { res_ok, res } = this.mono_get_and_delete_from_commands_received(id);
602612
if (!res_ok)
603613
throw new Error (`Failed on mono_wasm_invoke_method_debugger_agent_with_parms`);
604614
return res;
@@ -608,7 +618,7 @@ var MonoSupportLib = {
608618
{
609619
this.mono_wasm_malloc_and_set_debug_buffer(command_parameters);
610620
this._c_fn_table.mono_wasm_send_dbg_command_wrapper (id, command_set, command, this._debugger_buffer, command_parameters.length);
611-
let { res_ok, res } = MONO.commands_received;
621+
let { res_ok, res } = this.mono_get_and_delete_from_commands_received(id);
612622
if (!res_ok)
613623
throw new Error (`Failed on mono_wasm_send_dbg_command`);
614624
return res;
@@ -617,7 +627,7 @@ var MonoSupportLib = {
617627

618628
mono_wasm_get_dbg_command_info: function ()
619629
{
620-
let { res_ok, res } = MONO.commands_received;
630+
let { res_ok, res } = this.mono_get_and_delete_from_commands_received(0);
621631
if (!res_ok)
622632
throw new Error (`Failed on mono_wasm_get_dbg_command_info`);
623633
return res;
@@ -712,14 +722,14 @@ var MonoSupportLib = {
712722
if (prop.get !== undefined) {
713723
Object.defineProperty (proxy,
714724
prop.name,
715-
{ get () { return MONO.mono_wasm_send_dbg_command(-1, prop.get.commandSet, prop.get.command, prop.get.buffer, prop.get.length); },
716-
set: function (newValue) { MONO.mono_wasm_send_dbg_command_with_parms(-1, prop.set.commandSet, prop.set.command, prop.set.buffer, prop.set.length, prop.set.valtype, newValue); return MONO.commands_received.res_ok;}}
725+
{ get () { return MONO.mono_wasm_send_dbg_command(prop.get.id, prop.get.commandSet, prop.get.command, prop.get.buffer, prop.get.length); },
726+
set: function (newValue) { MONO.mono_wasm_send_dbg_command_with_parms(prop.set.id, prop.set.commandSet, prop.set.command, prop.set.buffer, prop.set.length, prop.set.valtype, newValue); return true;}}
717727
);
718728
} else if (prop.set !== undefined ){
719729
Object.defineProperty (proxy,
720730
prop.name,
721731
{ get () { return prop.value; },
722-
set: function (newValue) { MONO.mono_wasm_send_dbg_command_with_parms(-1, prop.set.commandSet, prop.set.command, prop.set.buffer, prop.set.length, prop.set.valtype, newValue); return MONO.commands_received.res_ok;}}
732+
set: function (newValue) { MONO.mono_wasm_send_dbg_command_with_parms(prop.set.id, prop.set.commandSet, prop.set.command, prop.set.buffer, prop.set.length, prop.set.valtype, newValue); return true;}}
723733
);
724734
} else {
725735
proxy [prop.name] = prop.value;
@@ -835,6 +845,7 @@ var MonoSupportLib = {
835845
},
836846

837847
mono_wasm_runtime_ready: function () {
848+
MONO.commands_received = new Map();
838849
this.mono_wasm_runtime_is_ready = true;
839850
this._clear_per_step_state ();
840851

0 commit comments

Comments
 (0)