Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/6.0-rc1] [mono][debugger] Fix watch of local variable values #57787

Merged
merged 4 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/mono/mono/component/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -8572,7 +8572,7 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
return ERR_INVALID_ARGUMENT;
}

locals = mono_debug_lookup_locals (method, FALSE);
locals = mono_debug_lookup_locals (method);
if (!locals) {
if (CHECK_PROTOCOL_VERSION (2, 43)) {
/* Scopes */
Expand Down Expand Up @@ -9289,13 +9289,14 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
pos = - pos - 1;
cmd_stack_frame_get_parameter (frame, sig, pos, buf, jit);
} else {
MonoDebugLocalsInfo *locals;

locals = mono_debug_lookup_locals (frame->de.method, TRUE);
if (locals) {
g_assert (pos < locals->num_locals);
pos = locals->locals [pos].index;
mono_debug_free_locals (locals);
if (!CHECK_PROTOCOL_VERSION (2, 59)) { //from newer protocol versions it's sent the pdb index
MonoDebugLocalsInfo *locals;
locals = mono_debug_lookup_locals (frame->de.method);
if (locals) {
g_assert (pos < locals->num_locals);
pos = locals->locals [pos].index;
mono_debug_free_locals (locals);
}
}

PRINT_DEBUG_MSG (4, "[dbg] send local %d.\n", pos);
Expand Down Expand Up @@ -9343,13 +9344,14 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
var = &jit->params [pos];
is_arg = TRUE;
} else {
MonoDebugLocalsInfo *locals;

locals = mono_debug_lookup_locals (frame->de.method, TRUE);
if (locals) {
g_assert (pos < locals->num_locals);
pos = locals->locals [pos].index;
mono_debug_free_locals (locals);
if (!CHECK_PROTOCOL_VERSION (2, 59)) { //from newer protocol versions it's sent the pdb index
MonoDebugLocalsInfo *locals;
locals = mono_debug_lookup_locals (frame->de.method);
if (locals) {
g_assert (pos < locals->num_locals);
pos = locals->locals [pos].index;
mono_debug_free_locals (locals);
}
}
g_assert (pos >= 0 && pos < jit->num_locals);

Expand Down
22 changes: 10 additions & 12 deletions src/mono/mono/metadata/mono-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ mono_debug_method_lookup_location (MonoDebugMethodInfo *minfo, int il_offset)
* The result should be freed using mono_debug_free_locals ().
*/
MonoDebugLocalsInfo*
mono_debug_lookup_locals (MonoMethod *method, mono_bool ignore_pdb)
mono_debug_lookup_locals (MonoMethod *method)
{
MonoDebugMethodInfo *minfo;
MonoDebugLocalsInfo *res;
Expand All @@ -893,18 +893,16 @@ mono_debug_lookup_locals (MonoMethod *method, mono_bool ignore_pdb)
return NULL;
}

if (ignore_pdb)
res = mono_debug_symfile_lookup_locals (minfo);
else {
if (minfo->handle->ppdb) {
res = mono_ppdb_lookup_locals (minfo);
} else {
if (!minfo->handle->symfile || !mono_debug_symfile_is_loaded (minfo->handle->symfile))
res = NULL;
else
res = mono_debug_symfile_lookup_locals (minfo);
}

if (minfo->handle->ppdb) {
res = mono_ppdb_lookup_locals (minfo);
} else {
if (!minfo->handle->symfile || !mono_debug_symfile_is_loaded (minfo->handle->symfile))
res = NULL;
else
res = mono_debug_symfile_lookup_locals (minfo);
}

mono_debugger_unlock ();

return res;
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/mono-debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ MONO_API void
mono_debug_add_delegate_trampoline (void* code, int size);

MONO_API MonoDebugLocalsInfo*
mono_debug_lookup_locals (MonoMethod *method, mono_bool ignore_pdb);
mono_debug_lookup_locals (MonoMethod *method);

MONO_API MonoDebugMethodAsyncInfo*
mono_debug_lookup_method_async_debug_info (MonoMethod *method);
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/dwarfwriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,7 @@ mono_dwarf_writer_emit_method (MonoDwarfWriter *w, MonoCompile *cfg, MonoMethod
g_free (names);

/* Locals */
locals_info = mono_debug_lookup_locals (method, FALSE);
locals_info = mono_debug_lookup_locals (method);

for (i = 0; i < header->num_locals; ++i) {
MonoInst *ins = locals [i];
Expand Down
15 changes: 15 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,21 @@ public async Task InspectTaskAtLocals() => await CheckInspectLocalsAtBreakpointS
}, "t_props", num_fields: 53);
});


[Fact]
public async Task InspectLocalsWithIndexAndPositionWithDifferentValues() //https://github.com/xamarin/xamarin-android/issues/6161
{
await EvaluateAndCheck(
"window.setTimeout(function() { invoke_static_method('[debugger-test] MainPage:CallSetValue'); }, 1);",
"dotnet://debugger-test.dll/debugger-test.cs", 758, 16,
"set_SomeValue",
locals_fn: (locals) =>
{
CheckNumber(locals, "view", 150);
}
);
}

//TODO add tests covering basic stepping behavior as step in/out/over
}
}
43 changes: 43 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 @@ -725,5 +725,48 @@ public async System.Threading.Tasks.Task<bool> AsyncMethod()
Console.WriteLine($"time for await");
return true;
}

}

public class MainPage
{
public MainPage()
{
}

int count = 0;
private int someValue;

public int SomeValue
{
get
{
return someValue;
}
set
{
someValue = value;
count++;

if (count == 10)
{
var view = 150;

if (view != 50)
{

}
System.Diagnostics.Debugger.Break();
}

SomeValue = count;
}
}

public static void CallSetValue()
{
var mainPage = new MainPage();
mainPage.SomeValue = 10;
}
}