Skip to content

Commit 4438f33

Browse files
Update ws-proxy to match runtime in use (from Mono commit cc6d4bf6cfce33ae3b41f74ac14ac2cb770603d5)
1 parent 9cb92db commit 4438f33

File tree

2 files changed

+37
-34
lines changed

2 files changed

+37
-34
lines changed

src/Components/WebAssembly/DebugProxy/src/MonoDebugProxy/ws-proxy/DevToolsHelper.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,8 @@ public static MonoCommands GetLoadedFiles ()
187187
public static MonoCommands ClearAllBreakpoints ()
188188
=> new MonoCommands ("MONO.mono_wasm_clear_all_breakpoints()");
189189

190-
public static MonoCommands GetObjectProperties (DotnetObjectId objectId, bool expandValueTypes)
191-
=> new MonoCommands ($"MONO.mono_wasm_get_object_properties({int.Parse (objectId.Value)}, { (expandValueTypes ? "true" : "false") })");
192-
193-
public static MonoCommands GetArrayValues (int objectId)
194-
=> new MonoCommands ($"MONO.mono_wasm_get_array_values({objectId})");
195-
196-
public static MonoCommands GetArrayValueExpanded (int objectId, int idx)
197-
=> new MonoCommands ($"MONO.mono_wasm_get_array_value_expanded({objectId}, {idx})");
190+
public static MonoCommands GetDetails (DotnetObjectId objectId, JToken args = null)
191+
=> new MonoCommands ($"MONO.mono_wasm_get_details ('{objectId}', {(args ?? "{}")})");
198192

199193
public static MonoCommands GetScopeVariables (int scopeId, params int[] vars)
200194
=> new MonoCommands ($"MONO.mono_wasm_get_variables({scopeId}, [ {string.Join (",", vars)} ])");
@@ -204,6 +198,12 @@ public static MonoCommands SetBreakpoint (string assemblyName, uint methodToken,
204198

205199
public static MonoCommands RemoveBreakpoint (int breakpointId)
206200
=> new MonoCommands ($"MONO.mono_wasm_remove_breakpoint({breakpointId})");
201+
202+
public static MonoCommands ReleaseObject (DotnetObjectId objectId)
203+
=> new MonoCommands ($"MONO.mono_wasm_release_object('{objectId}')");
204+
205+
public static MonoCommands CallFunctionOn (JToken args)
206+
=> new MonoCommands ($"MONO.mono_wasm_call_function_on ({args.ToString ()})");
207207
}
208208

209209
internal enum MonoErrorCodes {

src/Components/WebAssembly/DebugProxy/src/MonoDebugProxy/ws-proxy/MonoProxy.cs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ protected override async Task<bool> AcceptCommand (MessageId id, string method,
246246
if (!(DotnetObjectId.TryParse (args ["objectId"], out var objectId) && objectId.Scheme == "cfo_res"))
247247
break;
248248

249-
await SendMonoCommand (id, new MonoCommands ($"MONO.mono_wasm_release_object('{objectId}')"), token);
249+
await SendMonoCommand (id, MonoCommands.ReleaseObject (objectId), token);
250250
SendResponse (id, Result.OkFromObject (new{}), token);
251251
return true;
252252
}
@@ -325,9 +325,8 @@ protected override async Task<bool> AcceptCommand (MessageId id, string method,
325325
}
326326

327327
var returnByValue = args ["returnByValue"]?.Value<bool> () ?? false;
328-
var cmd = new MonoCommands ($"MONO.mono_wasm_call_function_on ({args.ToString ()}, {(returnByValue ? "true" : "false")})");
328+
var res = await SendMonoCommand (id, MonoCommands.CallFunctionOn (args), token);
329329

330-
var res = await SendMonoCommand (id, cmd, token);
331330
if (!returnByValue &&
332331
DotnetObjectId.TryParse (res.Value?["result"]?["value"]?["objectId"], out var resultObjectId) &&
333332
resultObjectId.Scheme == "cfo_res")
@@ -349,7 +348,7 @@ async Task<Result> RuntimeGetProperties (MessageId id, DotnetObjectId objectId,
349348
if (objectId.Scheme == "scope")
350349
return await GetScopeProperties (id, int.Parse (objectId.Value), token);
351350

352-
var res = await SendMonoCommand (id, new MonoCommands ($"MONO.mono_wasm_get_details ('{objectId}', {args})"), token);
351+
var res = await SendMonoCommand (id, MonoCommands.GetDetails (objectId, args), token);
353352
if (res.IsErr)
354353
return res;
355354

@@ -415,6 +414,9 @@ async Task<bool> OnBreakpointHit (SessionId sessionId, JObject args, Cancellatio
415414
var method_token = mono_frame ["method_token"].Value<uint> ();
416415
var assembly_name = mono_frame ["assembly_name"].Value<string> ();
417416

417+
// This can be different than `method.Name`, like in case of generic methods
418+
var method_name = mono_frame ["method_name"]?.Value<string> ();
419+
418420
var store = await LoadStore (sessionId, token);
419421
var asm = store.GetAssemblyByName (assembly_name);
420422
if (asm == null) {
@@ -440,11 +442,11 @@ async Task<bool> OnBreakpointHit (SessionId sessionId, JObject args, Cancellatio
440442
}
441443

442444
Log ("info", $"frame il offset: {il_pos} method token: {method_token} assembly name: {assembly_name}");
443-
Log ("info", $"\tmethod {method.Name} location: {location}");
445+
Log ("info", $"\tmethod {method_name} location: {location}");
444446
frames.Add (new Frame (method, location, frame_id-1));
445447

446448
callFrames.Add (new {
447-
functionName = method.Name,
449+
functionName = method_name,
448450
callFrameId = $"dotnet:scope:{frame_id-1}",
449451
functionLocation = method.StartLocation.AsLocation (),
450452

@@ -461,7 +463,7 @@ async Task<bool> OnBreakpointHit (SessionId sessionId, JObject args, Cancellatio
461463
description = "Object",
462464
objectId = $"dotnet:scope:{frame_id-1}",
463465
},
464-
name = method.Name,
466+
name = method_name,
465467
startLocation = method.StartLocation.AsLocation (),
466468
endLocation = method.EndLocation.AsLocation (),
467469
}}
@@ -558,34 +560,30 @@ internal async Task<JToken> TryGetVariableValue (MessageId msg_id, int scope_id,
558560
return obj;
559561

560562
var scope = context.CallStack.FirstOrDefault (s => s.Id == scope_id);
561-
var vars = scope.Method.GetLiveVarsAt (scope.Location.CliLocation.Offset);
563+
var live_vars = scope.Method.GetLiveVarsAt (scope.Location.CliLocation.Offset);
562564
//get_this
563-
int [] var_ids = { };
564-
var res = await SendMonoCommand (msg_id, MonoCommands.GetScopeVariables (scope.Id, var_ids), token);
565-
var values = res.Value? ["result"]? ["value"]?.Values<JObject> ().ToArray ();
566-
thisValue = values.FirstOrDefault (v => v ["name"].Value<string> () == "this");
565+
var res = await SendMonoCommand (msg_id, MonoCommands.GetScopeVariables (scope.Id, live_vars.Select (lv => lv.Index).ToArray ()), token);
566+
567+
var scope_values = res.Value? ["result"]? ["value"]?.Values<JObject> ()?.ToArray ();
568+
thisValue = scope_values?.FirstOrDefault (v => v ["name"]?.Value<string> () == "this");
567569

568570
if (!only_search_on_this) {
569-
if (thisValue != null && expression == "this") {
571+
if (thisValue != null && expression == "this")
570572
return thisValue;
571-
}
572-
//search in locals
573-
var var_id = vars.SingleOrDefault (v => v.Name == expression);
574-
if (var_id != null) {
575-
res = await SendMonoCommand (msg_id, MonoCommands.GetScopeVariables (scope.Id, new int [] { var_id.Index }), token);
576-
values = res.Value? ["result"]? ["value"]?.Values<JObject> ().ToArray ();
577-
return values [0];
578-
}
573+
574+
var value = scope_values.SingleOrDefault (sv => sv ["name"]?.Value<string> () == expression);
575+
if (value != null)
576+
return value;
579577
}
580578

581579
//search in scope
582580
if (thisValue != null) {
583581
if (!DotnetObjectId.TryParse (thisValue ["value"] ["objectId"], out var objectId))
584582
return null;
585583

586-
res = await SendMonoCommand (msg_id, MonoCommands.GetObjectProperties (objectId, expandValueTypes: false), token);
587-
values = res.Value? ["result"]? ["value"]?.Values<JObject> ().ToArray ();
588-
var foundValue = values.FirstOrDefault (v => v ["name"].Value<string> () == expression);
584+
res = await SendMonoCommand (msg_id, MonoCommands.GetDetails (objectId), token);
585+
scope_values = res.Value? ["result"]? ["value"]?.Values<JObject> ().ToArray ();
586+
var foundValue = scope_values.FirstOrDefault (v => v ["name"].Value<string> () == expression);
589587
if (foundValue != null) {
590588
foundValue["fromThis"] = true;
591589
context.LocalsCache[foundValue ["name"].Value<string> ()] = foundValue;
@@ -605,7 +603,6 @@ async Task<bool> OnEvaluateOnCallFrame (MessageId msg_id, int scope_id, string e
605603
var varValue = await TryGetVariableValue (msg_id, scope_id, expression, false, token);
606604

607605
if (varValue != null) {
608-
varValue ["value"] ["description"] = varValue ["value"] ["className"];
609606
SendResponse (msg_id, Result.OkFromObject (new {
610607
result = varValue ["value"]
611608
}), token);
@@ -650,11 +647,17 @@ async Task<Result> GetScopeProperties (MessageId msg_id, int scope_id, Cancellat
650647
var var_list = new List<object> ();
651648
int i = 0;
652649
for (; i < vars.Length && i < values.Length; i ++) {
650+
// For async methods, we get locals with names, unlike non-async methods
651+
// and the order may not match the var_ids, so, use the names that they
652+
// come with
653+
if (values [i]["name"] != null)
654+
continue;
655+
653656
ctx.LocalsCache[vars [i].Name] = values [i];
654657
var_list.Add (new { name = vars [i].Name, value = values [i]["value"] });
655658
}
656659
for (; i < values.Length; i ++) {
657-
ctx.LocalsCache[values [i]["name"].ToString()] = values [i]["value"];
660+
ctx.LocalsCache[values [i]["name"].ToString()] = values [i];
658661
var_list.Add (values [i]);
659662
}
660663

0 commit comments

Comments
 (0)