Skip to content

Commit

Permalink
[debugger] Switch to GC Unsafe in signal handler callbacks
Browse files Browse the repository at this point in the history
If the runtime gets a single step or breakpoint signal while it is already
running native code for a P/Invoke, it will be in GC Safe mode.  Switch back to
GC Unsafe to run the debugger engine steps.

Addresses mono/mono#20490
  • Loading branch information
lambdageek committed Oct 19, 2020
1 parent 466e4b7 commit 84e0cd2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/mono/mono/mini/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -2822,6 +2822,8 @@ process_suspend (DebuggerTlsData *tls, MonoContext *ctx)
static gboolean
try_process_suspend (void *the_tls, MonoContext *ctx, gboolean from_breakpoint)
{
MONO_REQ_GC_UNSAFE_MODE;

DebuggerTlsData *tls = (DebuggerTlsData*)the_tls;
/* if there is a suspend pending that is not executed yes */
if (suspend_count > 0) {
Expand Down Expand Up @@ -4810,7 +4812,13 @@ debugger_agent_single_step_from_context (MonoContext *ctx)
mono_thread_state_init_from_monoctx (&tls->restore_state, ctx);
memcpy (&tls->handler_ctx, ctx, sizeof (MonoContext));

/* We might be called while the thread is already running some native
* code after an native-to-managed transition, so the thread might be
* in GC Safe mode.
*/
MONO_ENTER_GC_UNSAFE;
mono_de_process_single_step (tls, FALSE);
MONO_EXIT_GC_UNSAFE;

memcpy (ctx, &tls->restore_state.ctx, sizeof (MonoContext));
memcpy (&tls->restore_state, &orig_restore_state, sizeof (MonoThreadUnwindState));
Expand Down Expand Up @@ -4840,7 +4848,13 @@ debugger_agent_breakpoint_from_context (MonoContext *ctx)
mono_thread_state_init_from_monoctx (&tls->restore_state, ctx);
memcpy (&tls->handler_ctx, ctx, sizeof (MonoContext));

/* We might be called while the thread is already running some native
* code after an native-to-managed transition, so the thread might be
* in GC Safe mode.
*/
MONO_ENTER_GC_UNSAFE;
mono_de_process_breakpoint (tls, FALSE);
MONO_EXIT_GC_UNSAFE;

memcpy (ctx, &tls->restore_state.ctx, sizeof (MonoContext));
memcpy (&tls->restore_state, &orig_restore_state, sizeof (MonoThreadUnwindState));
Expand Down

0 comments on commit 84e0cd2

Please sign in to comment.