Skip to content

Commit

Permalink
[debugger] Fixing two crashes while debugging an Android app.
Browse files Browse the repository at this point in the history
-> Doing stepping into in VSM in some situation the frame saved in TLS is not synchronised with what is really been executed in the main thread. This makes the debugger-agent crashes because it tries to get variable info in some memory that is not available anymore.
	-> To fix it I forced the update of stack when CMD_THREAD_GET_FRAME_INFO is called.

-> Doing step over in Visual Studio for Windows, if you have the threads debugger window enabled, VSW calls frame_commands for each thread that is showed, and if the thread is not really_suspended it tries to get variable info from a memory that is not available anymore because the thread is not suspended yet.
	-> To fix it I don't send variable info of a frame if the thread is not really_suspended and doesn't have an async_state valid.

#Fixes 12843
  • Loading branch information
thaystg authored and marek-safar committed Mar 22, 2019
1 parent 6a81d1d commit 484ce49
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions mono/mini/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -3232,7 +3232,7 @@ compute_frame_info_from (MonoInternalThread *thread, DebuggerTlsData *tls, MonoT
}

static void
compute_frame_info (MonoInternalThread *thread, DebuggerTlsData *tls)
compute_frame_info (MonoInternalThread *thread, DebuggerTlsData *tls, gboolean force_update)
{
ComputeFramesUserData user_data;
GSList *tmp;
Expand All @@ -3241,7 +3241,7 @@ compute_frame_info (MonoInternalThread *thread, DebuggerTlsData *tls)
MonoUnwindOptions opts = (MonoUnwindOptions)(MONO_UNWIND_DEFAULT | MONO_UNWIND_REG_LOCATIONS);

// FIXME: Locking on tls
if (tls->frames && tls->frames_up_to_date)
if (tls->frames && tls->frames_up_to_date && !force_update)
return;

DEBUG_PRINTF (1, "Frames for %p(tid=%lx):\n", thread, (glong)thread->tid);
Expand Down Expand Up @@ -4220,7 +4220,7 @@ ss_calculate_framecount (void *the_tls, MonoContext *ctx, gboolean force_use_ctx

if (force_use_ctx || !tls->context.valid)
mono_thread_state_init_from_monoctx (&tls->context, ctx);
compute_frame_info (tls->thread, tls);
compute_frame_info (tls->thread, tls, FALSE);
if (frames)
*frames = (DbgEngineStackFrame**)tls->frames;
if (nframes)
Expand Down Expand Up @@ -4780,7 +4780,7 @@ ss_create_init_args (SingleStepReq *ss_req, SingleStepArgs *args)
if (frames && nframes)
frame = frames [0];
} else {
compute_frame_info (ss_req->thread, tls);
compute_frame_info (ss_req->thread, tls, FALSE);

if (tls->frame_count)
frame = tls->frames [0];
Expand Down Expand Up @@ -8510,7 +8510,7 @@ thread_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
mono_loader_unlock ();
g_assert (tls);

compute_frame_info (thread, tls);
compute_frame_info (thread, tls, TRUE);

buffer_add_int (buf, tls->frame_count);
for (i = 0; i < tls->frame_count; ++i) {
Expand Down Expand Up @@ -8564,7 +8564,7 @@ thread_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
mono_loader_unlock ();
g_assert (tls);

compute_frame_info (thread, tls);
compute_frame_info (thread, tls, FALSE);
if (tls->frame_count == 0 || tls->frames [0]->actual_method != method)
return ERR_INVALID_ARGUMENT;

Expand Down Expand Up @@ -8630,6 +8630,9 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
if (i == tls->frame_count)
return ERR_INVALID_FRAMEID;

/* The thread is still running native code, can't get frame variables info */
if (!tls->really_suspended && !tls->async_state.valid)
return ERR_NOT_SUSPENDED;
frame_idx = i;
frame = tls->frames [frame_idx];

Expand Down

0 comments on commit 484ce49

Please sign in to comment.