Skip to content

Commit

Permalink
[sdb] Avoid stack overflows caused by recursive calls between suspend…
Browse files Browse the repository at this point in the history
…_current () and invoke_method ().

Fixes mono#13261.
  • Loading branch information
vargaz committed Mar 8, 2019
1 parent 8cd69e1 commit 7d0b0d5
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions mono/mini/debugger-agent.c
Expand Up @@ -2950,39 +2950,46 @@ suspend_current (void)
tls = (DebuggerTlsData *)mono_native_tls_get_value (debugger_tls_id);
g_assert (tls);

mono_coop_mutex_lock (&suspend_mutex);
gboolean do_resume = FALSE;
while (!do_resume) {
mono_coop_mutex_lock (&suspend_mutex);

tls->suspending = FALSE;
tls->really_suspended = TRUE;
tls->suspending = FALSE;
tls->really_suspended = TRUE;

if (!tls->suspended) {
tls->suspended = TRUE;
mono_coop_sem_post (&suspend_sem);
}
if (!tls->suspended) {
tls->suspended = TRUE;
mono_coop_sem_post (&suspend_sem);
}

mono_debugger_log_suspend (tls);
DEBUG_PRINTF (1, "[%p] Suspended.\n", (gpointer) (gsize) mono_native_thread_id_get ());
mono_debugger_log_suspend (tls);
DEBUG_PRINTF (1, "[%p] Suspended.\n", (gpointer) (gsize) mono_native_thread_id_get ());

while (suspend_count - tls->resume_count > 0) {
mono_coop_cond_wait (&suspend_cond, &suspend_mutex);
}
while (suspend_count - tls->resume_count > 0) {
mono_coop_cond_wait (&suspend_cond, &suspend_mutex);
}

tls->suspended = FALSE;
tls->really_suspended = FALSE;
tls->suspended = FALSE;
tls->really_suspended = FALSE;

threads_suspend_count --;
threads_suspend_count --;

mono_coop_mutex_unlock (&suspend_mutex);
mono_coop_mutex_unlock (&suspend_mutex);

mono_debugger_log_resume (tls);
DEBUG_PRINTF (1, "[%p] Resumed.\n", (gpointer) (gsize) mono_native_thread_id_get ());
mono_debugger_log_resume (tls);
DEBUG_PRINTF (1, "[%p] Resumed.\n", (gpointer) (gsize) mono_native_thread_id_get ());

if (tls->pending_invoke) {
/* Save the original context */
tls->pending_invoke->has_ctx = TRUE;
tls->pending_invoke->ctx = tls->context.ctx;
if (tls->pending_invoke) {
/* Save the original context */
tls->pending_invoke->has_ctx = TRUE;
tls->pending_invoke->ctx = tls->context.ctx;

invoke_method ();
invoke_method ();

/* Have to suspend again */
} else {
do_resume = TRUE;
}
}

/* The frame info becomes invalid after a resume */
Expand Down Expand Up @@ -6364,8 +6371,6 @@ invoke_method (void)

g_free (invoke->p);
g_free (invoke);

suspend_current ();
}

static gboolean
Expand Down

0 comments on commit 7d0b0d5

Please sign in to comment.