Fix #78673
[mono.git] / libgc / pthread_support.c
index 58a662e773be9cd2bc16c2075e925f3a9dc1f4fb..e2fef71968d8ede640ccf7b900fb6dc7c5a63882 100644 (file)
@@ -191,6 +191,10 @@ static __thread MONO_TLS_FAST void* GC_thread_tls;
 
 static GC_bool keys_initialized;
 
+#ifdef MONO_DEBUGGER_SUPPORTED
+#include "include/libgc-mono-debugger.h"
+#endif
+
 /* Recover the contents of the freelist array fl into the global one gfl.*/
 /* Note that the indexing scheme differs, in that gfl has finer size   */
 /* resolution, even if not all entries are used.                       */
@@ -692,6 +696,10 @@ void GC_delete_thread(pthread_t id)
     } else {
         prev -> next = p -> next;
     }
+#ifdef MONO_DEBUGGER_SUPPORTED
+    if (gc_thread_vtable && gc_thread_vtable->thread_exited)
+       gc_thread_vtable->thread_exited (id, &p->stop_info.stack_ptr);
+#endif
     GC_INTERNAL_FREE(p);
 }
 
@@ -767,11 +775,12 @@ void GC_remove_all_threads_but_me(void)
              GC_destroy_thread_local(p);
            }
 #        endif /* THREAD_LOCAL_ALLOC */
-         if (p != &first_thread) GC_INTERNAL_FREE(p);
+           if (p != &first_thread) GC_INTERNAL_FREE(p);
        }
       }
       GC_threads[hv] = me;
     }
+    GC_INTERNAL_FREE(p);
 }
 #endif /* HANDLE_FORK */
 
@@ -969,6 +978,10 @@ void GC_thr_init()
          t -> stop_info.stack_ptr = (ptr_t)(&dummy);
 #     endif
       t -> flags = DETACHED | MAIN_THREAD;
+#ifdef MONO_DEBUGGER_SUPPORTED
+      if (gc_thread_vtable && gc_thread_vtable->thread_created)
+        gc_thread_vtable->thread_created (pthread_self (), &t->stop_info.stack_ptr);
+#endif
 
     GC_stop_init();
 
@@ -1274,6 +1287,10 @@ void * GC_start_routine_head(void * arg, void *base_addr,
       /* This is also < 100% convincing.  We should also read this     */
       /* from /proc, but the hook to do so isn't there yet.            */
 #   endif /* IA64 */
+#ifdef MONO_DEBUGGER_SUPPORTED
+    if (gc_thread_vtable && gc_thread_vtable->thread_created)
+       gc_thread_vtable->thread_created (my_pthread, &me->stop_info.stack_ptr);
+#endif
     UNLOCK();
 
     if (start) *start = si -> start_routine;