[coop] Make coop suspend crashes have names that can be correlated to an Apple crash...
authorRodrigo Kumpera <kumpera@gmail.com>
Thu, 24 Sep 2015 21:02:42 +0000 (17:02 -0400)
committerRodrigo Kumpera <kumpera@gmail.com>
Thu, 24 Sep 2015 21:59:13 +0000 (17:59 -0400)
Use pthread_setname_np on attach to ensure every thread has a name that Apple's crash dump recognize.

The use pthread_getname_np when doing a thread dump to ensure we get the current thread name.

This cosmetic change will allow us to use Apple crash dumps when troubleshooting suspend issues.

mono/utils/mono-threads-coop.c
mono/utils/mono-threads.c

index 3817a925fab7d992e905cbb9287b480612dcc372..c1a8cad7473ff0f75dfe914d9570e7c7afdea5e5 100644 (file)
@@ -7,6 +7,13 @@
  * Copyright 2015 Xamarin, Inc (http://www.xamarin.com)
  */
 
+#include <config.h>
+
+/* enable pthread extensions */
+#ifdef TARGET_MACH
+#define _DARWIN_C_SOURCE
+#endif
+
 #include <mono/utils/mono-compiler.h>
 #include <mono/utils/mono-semaphore.h>
 #include <mono/utils/mono-threads.h>
@@ -230,7 +237,7 @@ mono_threads_init_platform (void)
 void
 mono_threads_platform_free (MonoThreadInfo *info)
 {
-#ifdef TARGET_OSX
+#ifdef TARGET_MACH
        mach_port_deallocate (current_task (), info->native_handle);
 #endif
 
@@ -240,8 +247,12 @@ mono_threads_platform_free (MonoThreadInfo *info)
 void
 mono_threads_platform_register (MonoThreadInfo *info)
 {
-#ifdef TARGET_OSX
+#ifdef TARGET_MACH
+       char thread_name [64];
+
        info->native_handle = mach_thread_self ();
+       snprintf (thread_name, 64, "tid_%x", (int)info->native_handle);
+       pthread_setname_np (thread_name);
 #endif
 
        //See the above for what's wrong here.
index e2a7239b45db31c253852d41702c9ec7e8ec6a5b..b1d5da9b917e85ca0aeca67f7abf4d2c87214874 100644 (file)
 
 #include <config.h>
 
+/* enable pthread extensions */
+#ifdef TARGET_MACH
+#define _DARWIN_C_SOURCE
+#endif
+
 #include <mono/utils/mono-compiler.h>
 #include <mono/utils/mono-semaphore.h>
 #include <mono/utils/mono-threads.h>
@@ -163,7 +168,15 @@ dump_threads (void)
        MOSTLY_ASYNC_SAFE_PRINTF ("\t0x?08\t- blocking with pending suspend (GOOD)\n");
 
        FOREACH_THREAD_SAFE (info) {
+#ifdef TARGET_MACH
+               char thread_name [256] = { 0 };
+               pthread_getname_np (mono_thread_info_get_tid (info), thread_name, 255);
+
+               MOSTLY_ASYNC_SAFE_PRINTF ("--thread %p id %p [%p] (%s) state %x  %s\n", info, (void *) mono_thread_info_get_tid (info), (void*)(size_t)info->native_handle, thread_name, info->thread_state, info == cur ? "GC INITIATOR" : "" );
+#else
                MOSTLY_ASYNC_SAFE_PRINTF ("--thread %p id %p [%p] state %x  %s\n", info, (void *) mono_thread_info_get_tid (info), (void*)(size_t)info->native_handle, info->thread_state, info == cur ? "GC INITIATOR" : "" );
+#endif
+
        } END_FOREACH_THREAD_SAFE
 }