Factor copy/pasted code into mono_gstring_append_thread_name. (mono/mono#15920)
authorJay Krell <jaykrell@microsoft.com>
Wed, 31 Jul 2019 23:25:31 +0000 (16:25 -0700)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 31 Jul 2019 23:25:31 +0000 (01:25 +0200)
Extracted from https://github.com/mono/mono/pull/15859.

Commit migrated from https://github.com/mono/mono/commit/180fcfe1fdbddb22b0c52c6e0b169b427b583ab3

src/mono/mono/metadata/object-internals.h
src/mono/mono/metadata/threads.c
src/mono/mono/mini/mini-exceptions.c

index cb652c2..ce7cb9c 100644 (file)
@@ -555,6 +555,10 @@ typedef enum {
 
 struct _MonoThreadInfo;
 
+void
+mono_gstring_append_thread_name (GString*, MonoInternalThread*);
+
+
 #ifdef ENABLE_NETCORE
 /*
  * There is only one thread object, MonoInternalThread is aliased to MonoThread,
index 398b7e5..9584d05 100644 (file)
@@ -3932,6 +3932,21 @@ collect_thread_ids (MonoNativeThreadId *thread_ids, int max_threads)
        return ud.nthreads;
 }
 
+void
+mono_gstring_append_thread_name (GString* text, MonoInternalThread* thread)
+{
+       // FIXME Conversion here is temporary. thread->name will change to UTF8.
+       char* const name = thread->name
+                               ? g_utf16_to_utf8 (thread->name, thread->name_len, NULL, NULL, NULL)
+                               : NULL;
+       g_string_append (text, "\n\"");
+       g_string_append (text,               name ? name :
+                       thread->threadpool_thread ? "<threadpool thread>" :
+                                                   "<unnamed thread>");
+       g_string_append (text, "\"");
+       g_free (name);
+}
+
 static void
 dump_thread (MonoInternalThread *thread, ThreadDumpUserData *ud, FILE* output_file)
 {
@@ -3953,17 +3968,7 @@ dump_thread (MonoInternalThread *thread, ThreadDumpUserData *ud, FILE* output_fi
        /*
         * Do all the non async-safe work outside of get_thread_dump.
         */
-       if (thread->name) {
-               name = g_utf16_to_utf8 (thread->name, thread->name_len, NULL, NULL, &gerror);
-               g_assert (!gerror);
-               g_string_append_printf (text, "\n\"%s\"", name);
-               g_free (name);
-       }
-       else if (thread->threadpool_thread) {
-               g_string_append (text, "\n\"<threadpool thread>\"");
-       } else {
-               g_string_append (text, "\n\"<unnamed thread>\"");
-       }
+       mono_gstring_append_thread_name (text, thread);
 
        for (i = 0; i < ud->nframes; ++i) {
                MonoStackFrameInfo *frame = &ud->frames [i];
index b41684e..9c51fe9 100644 (file)
@@ -3387,16 +3387,8 @@ mono_print_thread_dump_internal (void *sigctx, MonoContext *start_ctx)
                return;
 
        text = g_string_new (0);
-       if (thread->name) {
-               name = g_utf16_to_utf8 (thread->name, thread->name_len, NULL, NULL, &gerror);
-               g_assert (!gerror);
-               g_string_append_printf (text, "\n\"%s\"", name);
-               g_free (name);
-       }
-       else if (thread->threadpool_thread)
-               g_string_append (text, "\n\"<threadpool thread>\"");
-       else
-               g_string_append (text, "\n\"<unnamed thread>\"");
+
+       mono_gstring_append_thread_name (text, thread);
 
        g_string_append_printf (text, " tid=%p this=%p ", (gpointer)(gsize)thread->tid, thread);
        mono_thread_internal_describe (thread, text);