Skip to content

Commit

Permalink
[mono][debugger] Fix evaluate method in a struct that doesn't need ex…
Browse files Browse the repository at this point in the history
…tra_space (#106351)

* Fix evaluate method in a struct that doesn't need extra_space.

* Adding test case
  • Loading branch information
thaystg authored Aug 14, 2024
1 parent b500820 commit dcf9814
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -841,5 +841,16 @@ public async Task EvaluateValueTypeWithObjectValueType() => await CheckInspectLo
await RuntimeEvaluateAndCheck(
("myVar.MyMethod()", TNumber(10)));
});

// https://github.com/dotnet/runtime/issues/106311
[ConditionalFact(nameof(RunningOnChrome))]
public async Task EvaluateOnValueTypeWithoutExtraSpace() => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTests.EvaluateOnValueTypeWithoutExtraSpace", "run", 3, "DebuggerTests.EvaluateOnValueTypeWithoutExtraSpace.run",
"window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateOnValueTypeWithoutExtraSpace:run'); })",
wait_for_event_fn: async (pause_location) =>
{
await RuntimeEvaluateAndCheck(
("f1.DistSquaredXY(f2)", TNumber(2)));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2291,4 +2291,27 @@ public static void run()
myVar.MyMethod();
}
}

public struct EvaluateOnValueTypeWithoutExtraSpace
{
public double X;
public double Y;
public double Z;
public EvaluateOnValueTypeWithoutExtraSpace(float InX, float InY, float InZ)
{
X = InX; Y = InY; Z = InZ;
}
public double DistSquaredXY(in EvaluateOnValueTypeWithoutExtraSpace B) // the keyword "in" here is crucial, with it the crash produced
{
double DX = X - B.X;
double DY = Y - B.Y;
return DX * DX + DY * DY;
}
public static void run()
{
EvaluateOnValueTypeWithoutExtraSpace f1 = new EvaluateOnValueTypeWithoutExtraSpace(1, 1, 1);
EvaluateOnValueTypeWithoutExtraSpace f2 = new EvaluateOnValueTypeWithoutExtraSpace(2, 2, 2);
Console.WriteLine("pause here");
}
}
}
3 changes: 1 addition & 2 deletions src/mono/mono/component/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -5696,8 +5696,7 @@ decode_value_internal (MonoType *t, int type, MonoDomain *domain, guint8 *addr,
{
ErrorCode err;

if (m_type_is_byref (t)) {
g_assert (extra_space != NULL && *extra_space != NULL);
if (m_type_is_byref (t) && extra_space != NULL && *extra_space != NULL) {
*(guint8**)addr = *extra_space; //assign the extra_space allocated for byref fields to the addr
guint8 *buf_int = buf;
addr = *(guint8**)addr; //dereference the pointer as it's a byref field
Expand Down

0 comments on commit dcf9814

Please sign in to comment.