Skip to content

Commit

Permalink
[mono][debugger] fix exception while decoding value that has a byref …
Browse files Browse the repository at this point in the history
…field (#75774)

* fix exception while decoding value that has a byref field

* Apply suggestions from code review

Co-authored-by: Larry Ewing <lewing@microsoft.com>

Co-authored-by: Larry Ewing <lewing@microsoft.com>
  • Loading branch information
thaystg and lewing committed Sep 26, 2022
1 parent 5024a64 commit fec8aeb
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/mono/mono/component/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -5078,6 +5078,8 @@ buffer_add_value_full (Buffer *buf, MonoType *t, void *addr, MonoDomain *domain,
/* This can happen with compiler generated locals */
//PRINT_MSG ("%s\n", mono_type_full_name (t));
buffer_add_byte (buf, VALUE_TYPE_ID_NULL);
if (CHECK_PROTOCOL_VERSION (2, 59))
buffer_add_info_for_null_value (buf, t, domain);
return;
}
g_assert (*(void**)addr);
Expand Down Expand Up @@ -5231,6 +5233,8 @@ buffer_add_value_full (Buffer *buf, MonoType *t, void *addr, MonoDomain *domain,
} else {
/* The client can't handle PARENT_VTYPE */
buffer_add_byte (buf, VALUE_TYPE_ID_NULL);
if (CHECK_PROTOCOL_VERSION (2, 59))
buffer_add_info_for_null_value (buf, t, domain);
}
break;
} else {
Expand Down Expand Up @@ -5613,6 +5617,11 @@ decode_value (MonoType *t, MonoDomain *domain, gpointer void_addr, gpointer void
ErrorCode err;
int type = decode_byte (buf, &buf, limit);

if (m_type_is_byref (t)) {
*(guint8**)addr = (guint8 *)g_malloc (sizeof (void*)); //when the object will be deleted it will delete this memory allocated here together?
addr = *(guint8**)addr;
}

if (t->type == MONO_TYPE_GENERICINST && mono_class_is_nullable (mono_class_from_mono_type_internal (t))) {
MonoType *targ = t->data.generic_class->context.class_inst->type_argv [0];
guint8 *nullable_buf;
Expand Down Expand Up @@ -6082,7 +6091,7 @@ mono_do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, gu
}
} else {
if (!(m->flags & METHOD_ATTRIBUTE_STATIC) || (m->flags & METHOD_ATTRIBUTE_STATIC && !CHECK_PROTOCOL_VERSION (2, 59))) { //on icordbg I couldn't find an object when invoking a static method maybe I can change this later
err = decode_value(m_class_get_byval_arg(m->klass), domain, this_buf, p, &p, end, FALSE);
err = decode_value (m_class_get_byval_arg (m->klass), domain, this_buf, p, &p, end, FALSE);
if (err != ERR_NONE)
return err;
}
Expand Down
8 changes: 8 additions & 0 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,14 @@ public async Task<string> GetValueFromDebuggerDisplayAttribute(DotnetObjectId do
{
dispAttrStr = dispAttrStr.Replace(",nq", "");
}
if (dispAttrStr.Contains(", raw"))
{
dispAttrStr = dispAttrStr.Replace(", raw", "");
}
if (dispAttrStr.Contains(",raw"))
{
dispAttrStr = dispAttrStr.Replace(",raw", "");
}
expr = "$\"" + dispAttrStr + "\"";
JObject retValue = await resolver.Resolve(expr, token);
retValue ??= await ExpressionEvaluator.CompileAndRunTheExpression(expr, resolver, logger, token);
Expand Down
25 changes: 25 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,5 +1104,30 @@ public async Task SetBreakpointInProjectWithChineseCharactereInPath()
bp.Value["locations"][0]["columnNumber"].Value<int>(),
$"DebuggerTests.CheckChineseCharacterInPath.Evaluate");
}

[Fact]
public async Task InspectReadOnlySpan()
{
var expression = $"{{ invoke_static_method('[debugger-test] ReadOnlySpanTest:Run'); }}";

await EvaluateAndCheck(
"window.setTimeout(function() {" + expression + "; }, 1);",
"dotnet://debugger-test.dll/debugger-test.cs", 1371, 8,
"ReadOnlySpanTest.CheckArguments",
wait_for_event_fn: async (pause_location) =>
{
var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();
await EvaluateOnCallFrameAndCheck(id,
("parameters.ToString()", TString("System.ReadOnlySpan<Object>[1]"))
);
}
);
await StepAndCheck(StepKind.Resume, "dotnet://debugger-test.dll/debugger-test.cs", 1363, 8, "ReadOnlySpanTest.Run",
locals_fn: async (locals) =>
{
await CheckValueType(locals, "var1", "System.ReadOnlySpan<object>", description: "System.ReadOnlySpan<Object>[0]");
}
);
}
}
}
17 changes: 17 additions & 0 deletions src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1354,4 +1354,21 @@ public void CallMethod()
}

public int myField;
}
public class ReadOnlySpanTest
{
public static void Run()
{
Invoke(new string[] {"TEST"});
ReadOnlySpan<object> var1 = new ReadOnlySpan<object>();
System.Diagnostics.Debugger.Break();
}
public static void Invoke(object[] parameters)
{
CheckArguments(parameters);
}
public static void CheckArguments(ReadOnlySpan<object> parameters)
{
System.Diagnostics.Debugger.Break();
}
}

0 comments on commit fec8aeb

Please sign in to comment.