Only set the attached flag when a client attaches
authorJosh Peterson <petersonjm1@gmail.com>
Tue, 30 Aug 2016 15:00:32 +0000 (11:00 -0400)
committerJosh Peterson <petersonjm1@gmail.com>
Wed, 31 Aug 2016 00:49:47 +0000 (20:49 -0400)
In defer mode, the debugger thread is started as soon as possible before
any clients are attached, but the debugger is_attached flag was being set
immediately. This would cause the runtime (and the System.Diagnostics.Debugger
class) to wrongly report a client as being attached.

Originally fixed in the Unity fork here: https://github.com/Unity-Technologies/mono/commit/797a210e0f2416d779c448bb9e03bb16933e261f

mono/mini/debugger-agent.c

index ed3bee869a155630c8b1f6256d273db39a8487ff..22f063c59640e9253d58be382839db3c838575e7 100644 (file)
@@ -9833,16 +9833,17 @@ debugger_thread (void *arg)
        thread->internal_thread->state |= ThreadState_Background;
        thread->internal_thread->flags |= MONO_THREAD_FLAG_DONT_MANAGE;
 
-       mono_set_is_debugger_attached (TRUE);
-       
        if (agent_config.defer) {
                if (!wait_for_attach ()) {
                        DEBUG_PRINTF (1, "[dbg] Can't attach, aborting debugger thread.\n");
                        attach_failed = TRUE; // Don't abort process when we can't listen
                } else {
+                       mono_set_is_debugger_attached (TRUE);
                        /* Send start event to client */
                        process_profiler_event (EVENT_KIND_VM_START, mono_thread_get_main ());
                }
+       } else {
+               mono_set_is_debugger_attached (TRUE);
        }
        
        while (!attach_failed) {