[Coop] GetStackTraces.
authorJay Krell <jaykrell@microsoft.com>
Fri, 30 Aug 2019 03:45:59 +0000 (20:45 -0700)
committerLarry Ewing <lewing@microsoft.com>
Wed, 4 Sep 2019 15:31:22 +0000 (10:31 -0500)
Commit migrated from https://github.com/mono/mono/commit/14afe79a0ab064ea769025ded95ae961e8df8247

src/mono/mono/metadata/icall-def.h
src/mono/mono/metadata/threads-types.h
src/mono/mono/metadata/threads.c

index 39bac41..94704a7 100644 (file)
@@ -1039,7 +1039,7 @@ HANDLES(THREAD_60, "GetCurrentThread", ves_icall_System_Threading_Thread_GetCurr
 HANDLES(THREAD_7, "GetDomainID", ves_icall_System_Threading_Thread_GetDomainID, gint32, 0, ())
 HANDLES(THREAD_8, "GetName_internal(System.Threading.InternalThread)", ves_icall_System_Threading_Thread_GetName_internal, MonoString, 1, (MonoInternalThread))
 HANDLES(THREAD_57, "GetPriorityNative", ves_icall_System_Threading_Thread_GetPriority, int, 1, (MonoThreadObject))
-ICALL(THREAD_59, "GetStackTraces", ves_icall_System_Threading_Thread_GetStackTraces)
+HANDLES(THREAD_59, "GetStackTraces", ves_icall_System_Threading_Thread_GetStackTraces, void, 2, (MonoArrayOut, MonoArrayOut))
 HANDLES(THREAD_11, "GetState(System.Threading.InternalThread)", ves_icall_System_Threading_Thread_GetState, guint32, 1, (MonoInternalThread))
 HANDLES(THREAD_53, "InterruptInternal", ves_icall_System_Threading_Thread_Interrupt_internal, void, 1, (MonoThreadObject))
 HANDLES(THREAD_12, "JoinInternal", ves_icall_System_Threading_Thread_Join_internal, MonoBoolean, 2, (MonoThreadObject, int))
index 09188fc..f692e5b 100644 (file)
@@ -410,9 +410,6 @@ void mono_threads_add_joinable_thread (gpointer tid);
 void mono_threads_join_threads (void);
 void mono_thread_join (gpointer tid);
 
-ICALL_EXPORT
-void ves_icall_System_Threading_Thread_GetStackTraces (MonoArray **out_threads, MonoArray **out_stack_traces);
-
 MONO_API gpointer
 mono_threads_attach_coop (MonoDomain *domain, gpointer *dummy);
 
index 188c45e..79dae03 100644 (file)
@@ -4094,20 +4094,25 @@ mono_threads_perform_thread_dump (void)
 }
 
 /* Obtain the thread dump of all threads */
-static gboolean
-mono_threads_get_thread_dump (MonoArray **out_threads, MonoArray **out_stack_frames, MonoError *error)
+void
+ves_icall_System_Threading_Thread_GetStackTraces (MonoArrayHandleOut out_threads_handle, MonoArrayHandleOut out_stack_frames_handle, MonoError *error)
 {
+       MonoStackFrameHandle stack_frame_handle = MONO_HANDLE_NEW (MonoStackFrame, NULL);
+       MonoReflectionMethodHandle reflection_method_handle = MONO_HANDLE_NEW (MonoReflectionMethod, NULL);
+       MonoStringHandle filename_handle = MONO_HANDLE_NEW (MonoString, NULL);
+       MonoArrayHandle thread_frames_handle = MONO_HANDLE_NEW (MonoArray, NULL);
 
        ThreadDumpUserData ud;
        guint32 thread_array [128];
        MonoDomain *domain = mono_domain_get ();
        MonoDebugSourceLocation *location;
        int tindex, nthreads;
-
-       error_init (error);
        
-       *out_threads = NULL;
-       *out_stack_frames = NULL;
+       MonoArray* out_threads = NULL;
+       MonoArray* out_stack_frames = NULL;
+
+       MONO_HANDLE_ASSIGN_RAW (out_threads_handle, NULL);
+       MONO_HANDLE_ASSIGN_RAW (out_stack_frames_handle, NULL);
 
        /* Make a copy of the threads hash to avoid doing work inside threads_lock () */
        nthreads = collect_threads (thread_array, 128);
@@ -4116,12 +4121,15 @@ mono_threads_get_thread_dump (MonoArray **out_threads, MonoArray **out_stack_fra
        ud.frames = g_new0 (MonoStackFrameInfo, 256);
        ud.max_frames = 256;
 
-       *out_threads = mono_array_new_checked (domain, mono_defaults.thread_class, nthreads, error);
+       out_threads = mono_array_new_checked (domain, mono_defaults.thread_class, nthreads, error);
        goto_if_nok (error, leave);
-       *out_stack_frames = mono_array_new_checked (domain, mono_defaults.array_class, nthreads, error);
+       MONO_HANDLE_ASSIGN_RAW (out_threads_handle, out_threads);
+       out_stack_frames = mono_array_new_checked (domain, mono_defaults.array_class, nthreads, error);
        goto_if_nok (error, leave);
+       MONO_HANDLE_ASSIGN_RAW (out_stack_frames_handle, out_stack_frames);
 
        for (tindex = 0; tindex < nthreads; ++tindex) {
+
                guint32 handle = thread_array [tindex];
                MonoInternalThread *thread = (MonoInternalThread *) mono_gchandle_get_target_internal (handle);
 
@@ -4138,16 +4146,18 @@ mono_threads_get_thread_dump (MonoArray **out_threads, MonoArray **out_stack_fra
                        mono_thread_info_safe_suspend_and_run (thread_get_tid (thread), FALSE, get_thread_dump, &ud);
                }
 
-               mono_array_setref_fast (*out_threads, tindex, mono_thread_current_for_thread (thread));
+               mono_array_setref_fast (out_threads, tindex, mono_thread_current_for_thread (thread));
 
                thread_frames = mono_array_new_checked (domain, mono_defaults.stack_frame_class, ud.nframes, error);
+               MONO_HANDLE_ASSIGN_RAW (thread_frames_handle, thread_frames);
                goto_if_nok (error, leave);
-               mono_array_setref_fast (*out_stack_frames, tindex, thread_frames);
+               mono_array_setref_fast (out_stack_frames, tindex, thread_frames);
 
                for (i = 0; i < ud.nframes; ++i) {
                        MonoStackFrameInfo *frame = &ud.frames [i];
                        MonoMethod *method = NULL;
                        MonoStackFrame *sf = (MonoStackFrame *)mono_object_new_checked (domain, mono_defaults.stack_frame_class, error);
+                       MONO_HANDLE_ASSIGN_RAW (stack_frame_handle, sf);
                        goto_if_nok (error, leave);
 
                        sf->native_offset = frame->native_offset;
@@ -4159,6 +4169,7 @@ mono_threads_get_thread_dump (MonoArray **out_threads, MonoArray **out_stack_fra
                                sf->method_address = (gsize) frame->ji->code_start;
 
                                MonoReflectionMethod *rm = mono_method_get_object_checked (domain, method, NULL, error);
+                               MONO_HANDLE_ASSIGN_RAW (reflection_method_handle, rm);
                                goto_if_nok (error, leave);
                                MONO_OBJECT_SETREF_INTERNAL (sf, method, rm);
 
@@ -4168,6 +4179,7 @@ mono_threads_get_thread_dump (MonoArray **out_threads, MonoArray **out_stack_fra
 
                                        if (location->source_file) {
                                                MonoString *filename = mono_string_new_checked (domain, location->source_file, error);
+                                               MONO_HANDLE_ASSIGN_RAW (filename_handle, filename);
                                                goto_if_nok (error, leave);
                                                MONO_OBJECT_SETREF_INTERNAL (sf, filename, filename);
                                                sf->line = location->row;
@@ -4186,7 +4198,6 @@ mono_threads_get_thread_dump (MonoArray **out_threads, MonoArray **out_stack_fra
 
 leave:
        g_free (ud.frames);
-       return is_ok (error);
 }
 
 /**
@@ -5952,14 +5963,6 @@ mono_thread_internal_unhandled_exception (MonoObject* exc)
        }
 }
 
-void
-ves_icall_System_Threading_Thread_GetStackTraces (MonoArray **out_threads, MonoArray **out_stack_traces)
-{
-       ERROR_DECL (error);
-       mono_threads_get_thread_dump (out_threads, out_stack_traces, error);
-       mono_error_set_pending_exception (error);
-}
-
 /*
  * mono_threads_attach_coop_internal: called by native->managed wrappers
  *