Skip to content

Commit 34959e6

Browse files
author
Brian Raderman
committed
Increasing sync for i2cpp debugger stack frames (case 1064723)
The thread local storage of sequence points and method execution contexts between IL2CPP and the mono debugger code was only being synchronized at certain times, mainly when breakpoints were processed. This could lead to a loss of synchronization after functions are exited and debugger frame commands accessing invalid stack data. This change adds synchronization for these data structures right before any managed method exit, when the method execution context for that method is destroyed. Also optimizing memory allocations by only allocating when the stack grows and just reusing the memory otherwise.
1 parent 8ecb87c commit 34959e6

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

mono/mini/debugger-agent.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,8 @@ mono_debugger_run_debugger_thread_func(void* arg)
11491149
}
11501150

11511151
typedef struct {
1152-
void(*il2cpp_debugger_save_thread_context)(Il2CppThreadUnwindState* context);
1152+
void(*il2cpp_debugger_save_thread_context)(Il2CppThreadUnwindState* context, int frameCountAdjust);
1153+
void(*il2cpp_debugger_free_thread_context)(Il2CppThreadUnwindState* context);
11531154
} MonoDebuggerRuntimeCallbacks;
11541155

11551156
static MonoDebuggerRuntimeCallbacks callbacks;
@@ -2679,7 +2680,7 @@ save_thread_context (MonoContext *ctx)
26792680
else
26802681
mono_thread_state_init_from_current (&tls->context);
26812682
#else
2682-
callbacks.il2cpp_debugger_save_thread_context(&tls->il2cpp_context);
2683+
callbacks.il2cpp_debugger_save_thread_context(&tls->il2cpp_context, 0);
26832684
#endif // !RUNTIME_IL2CPP
26842685
}
26852686

@@ -4213,6 +4214,8 @@ thread_end (MonoProfiler *prof, uintptr_t tid)
42134214
/* Can't remove from tid_to_thread, as that would defeat the check in thread_start () */
42144215
#ifndef RUNTIME_IL2CPP
42154216
MONO_GC_UNREGISTER_ROOT (tls->thread);
4217+
#else
4218+
callbacks.il2cpp_debugger_free_thread_context(&tls->il2cpp_context);
42164219
#endif
42174220
tls->thread = NULL;
42184221
}
@@ -12321,6 +12324,19 @@ gboolean unity_sequence_point_active(Il2CppSequencePoint *seqPoint)
1232112324
return FALSE;
1232212325
}
1232312326

12327+
void il2cpp_save_current_thread_context_func_exit()
12328+
{
12329+
DebuggerTlsData *tls;
12330+
12331+
MonoInternalThread *thread = mono_thread_internal_current();
12332+
12333+
mono_loader_lock();
12334+
tls = (DebuggerTlsData *)mono_g_hash_table_lookup(thread_to_tls, thread);
12335+
mono_loader_unlock();
12336+
12337+
callbacks.il2cpp_debugger_save_thread_context(&tls->il2cpp_context, -1);
12338+
}
12339+
1232412340
#endif // RUNTIME_IL2CPP
1232512341

1232612342
#else /* DISABLE_DEBUGGER_AGENT */

0 commit comments

Comments
 (0)