Skip to content

Commit 0f5b753

Browse files
authored
[mono][debugger] Fix watch of local variable values (#57771)
* Fix xamarin-android 6161 * Fixing leak. * Adding wasm debugger test. Fixing using protocol version. * only get locals in older protocol versions.
1 parent 887106b commit 0f5b753

File tree

6 files changed

+87
-29
lines changed

6 files changed

+87
-29
lines changed

src/mono/mono/component/debugger-agent.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8513,7 +8513,7 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
85138513
return ERR_INVALID_ARGUMENT;
85148514
}
85158515

8516-
locals = mono_debug_lookup_locals (method, FALSE);
8516+
locals = mono_debug_lookup_locals (method);
85178517
if (!locals) {
85188518
if (CHECK_PROTOCOL_VERSION (2, 43)) {
85198519
/* Scopes */
@@ -9230,13 +9230,14 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
92309230
pos = - pos - 1;
92319231
cmd_stack_frame_get_parameter (frame, sig, pos, buf, jit);
92329232
} else {
9233-
MonoDebugLocalsInfo *locals;
9234-
9235-
locals = mono_debug_lookup_locals (frame->de.method, TRUE);
9236-
if (locals) {
9237-
g_assert (pos < locals->num_locals);
9238-
pos = locals->locals [pos].index;
9239-
mono_debug_free_locals (locals);
9233+
if (!CHECK_PROTOCOL_VERSION (2, 59)) { //from newer protocol versions it's sent the pdb index
9234+
MonoDebugLocalsInfo *locals;
9235+
locals = mono_debug_lookup_locals (frame->de.method);
9236+
if (locals) {
9237+
g_assert (pos < locals->num_locals);
9238+
pos = locals->locals [pos].index;
9239+
mono_debug_free_locals (locals);
9240+
}
92409241
}
92419242

92429243
PRINT_DEBUG_MSG (4, "[dbg] send local %d.\n", pos);
@@ -9284,13 +9285,14 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
92849285
var = &jit->params [pos];
92859286
is_arg = TRUE;
92869287
} else {
9287-
MonoDebugLocalsInfo *locals;
9288-
9289-
locals = mono_debug_lookup_locals (frame->de.method, TRUE);
9290-
if (locals) {
9291-
g_assert (pos < locals->num_locals);
9292-
pos = locals->locals [pos].index;
9293-
mono_debug_free_locals (locals);
9288+
if (!CHECK_PROTOCOL_VERSION (2, 59)) { //from newer protocol versions it's sent the pdb index
9289+
MonoDebugLocalsInfo *locals;
9290+
locals = mono_debug_lookup_locals (frame->de.method);
9291+
if (locals) {
9292+
g_assert (pos < locals->num_locals);
9293+
pos = locals->locals [pos].index;
9294+
mono_debug_free_locals (locals);
9295+
}
92949296
}
92959297
g_assert (pos >= 0 && pos < jit->num_locals);
92969298

src/mono/mono/metadata/mono-debug.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ mono_debug_method_lookup_location (MonoDebugMethodInfo *minfo, int il_offset)
867867
* The result should be freed using mono_debug_free_locals ().
868868
*/
869869
MonoDebugLocalsInfo*
870-
mono_debug_lookup_locals (MonoMethod *method, mono_bool ignore_pdb)
870+
mono_debug_lookup_locals (MonoMethod *method)
871871
{
872872
MonoDebugMethodInfo *minfo;
873873
MonoDebugLocalsInfo *res;
@@ -893,18 +893,16 @@ mono_debug_lookup_locals (MonoMethod *method, mono_bool ignore_pdb)
893893
return NULL;
894894
}
895895

896-
if (ignore_pdb)
897-
res = mono_debug_symfile_lookup_locals (minfo);
898-
else {
899-
if (minfo->handle->ppdb) {
900-
res = mono_ppdb_lookup_locals (minfo);
901-
} else {
902-
if (!minfo->handle->symfile || !mono_debug_symfile_is_loaded (minfo->handle->symfile))
903-
res = NULL;
904-
else
905-
res = mono_debug_symfile_lookup_locals (minfo);
906-
}
896+
897+
if (minfo->handle->ppdb) {
898+
res = mono_ppdb_lookup_locals (minfo);
899+
} else {
900+
if (!minfo->handle->symfile || !mono_debug_symfile_is_loaded (minfo->handle->symfile))
901+
res = NULL;
902+
else
903+
res = mono_debug_symfile_lookup_locals (minfo);
907904
}
905+
908906
mono_debugger_unlock ();
909907

910908
return res;

src/mono/mono/metadata/mono-debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ MONO_API void
189189
mono_debug_add_delegate_trampoline (void* code, int size);
190190

191191
MONO_API MonoDebugLocalsInfo*
192-
mono_debug_lookup_locals (MonoMethod *method, mono_bool ignore_pdb);
192+
mono_debug_lookup_locals (MonoMethod *method);
193193

194194
MONO_API MonoDebugMethodAsyncInfo*
195195
mono_debug_lookup_method_async_debug_info (MonoMethod *method);

src/mono/mono/mini/dwarfwriter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,7 @@ mono_dwarf_writer_emit_method (MonoDwarfWriter *w, MonoCompile *cfg, MonoMethod
18991899
g_free (names);
19001900

19011901
/* Locals */
1902-
locals_info = mono_debug_lookup_locals (method, FALSE);
1902+
locals_info = mono_debug_lookup_locals (method);
19031903

19041904
for (i = 0; i < header->num_locals; ++i) {
19051905
MonoInst *ins = locals [i];

src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,21 @@ public async Task InspectTaskAtLocals() => await CheckInspectLocalsAtBreakpointS
845845
}, "t_props", num_fields: 53);
846846
});
847847

848+
849+
[Fact]
850+
public async Task InspectLocalsWithIndexAndPositionWithDifferentValues() //https://github.com/xamarin/xamarin-android/issues/6161
851+
{
852+
await EvaluateAndCheck(
853+
"window.setTimeout(function() { invoke_static_method('[debugger-test] MainPage:CallSetValue'); }, 1);",
854+
"dotnet://debugger-test.dll/debugger-test.cs", 758, 16,
855+
"set_SomeValue",
856+
locals_fn: (locals) =>
857+
{
858+
CheckNumber(locals, "view", 150);
859+
}
860+
);
861+
}
862+
848863
//TODO add tests covering basic stepping behavior as step in/out/over
849864
}
850865
}

src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,5 +725,48 @@ public async System.Threading.Tasks.Task<bool> AsyncMethod()
725725
Console.WriteLine($"time for await");
726726
return true;
727727
}
728+
729+
}
730+
731+
public class MainPage
732+
{
733+
public MainPage()
734+
{
735+
}
736+
737+
int count = 0;
738+
private int someValue;
739+
740+
public int SomeValue
741+
{
742+
get
743+
{
744+
return someValue;
745+
}
746+
set
747+
{
748+
someValue = value;
749+
count++;
750+
751+
if (count == 10)
752+
{
753+
var view = 150;
754+
755+
if (view != 50)
756+
{
757+
758+
}
759+
System.Diagnostics.Debugger.Break();
760+
}
761+
762+
SomeValue = count;
763+
}
764+
}
765+
766+
public static void CallSetValue()
767+
{
768+
var mainPage = new MainPage();
769+
mainPage.SomeValue = 10;
770+
}
728771
}
729772

0 commit comments

Comments
 (0)