[profiler] Rename mono_profiler_install to mono_profiler_create.
[mono.git] / mono / mini / debugger-agent.c
index 1a4940a82cc1fabd67952e792b27ff8bbf1f7ee8..b625580c1fe4c347fedcc46b41f7473db085cc88 100644 (file)
@@ -275,7 +275,7 @@ typedef struct {
 #define HEADER_LENGTH 11
 
 #define MAJOR_VERSION 2
-#define MINOR_VERSION 46
+#define MINOR_VERSION 45
 
 typedef enum {
        CMD_SET_VM = 1,
@@ -595,11 +595,6 @@ typedef struct {
        MonoClass *klass;
 } EventInfo;
 
-/* Dummy structure used for the profiler callbacks */
-typedef struct {
-       void* dummy;
-} DebuggerProfiler;
-
 typedef struct {
        guint8 *buf, *p, *end;
 } Buffer;
@@ -700,8 +695,6 @@ static MonoCoopCond debugger_thread_exited_cond;
 /* Mutex for the cond var above */
 static MonoCoopMutex debugger_thread_exited_mutex;
 
-static DebuggerProfiler debugger_profiler;
-
 /* The single step request instance */
 static SingleStepReq *ss_req;
 
@@ -749,7 +742,7 @@ static void thread_startup (MonoProfiler *prof, uintptr_t tid);
 
 static void thread_end (MonoProfiler *prof, uintptr_t tid);
 
-static void appdomain_load (MonoProfiler *prof, MonoDomain *domain, int result);
+static void appdomain_load (MonoProfiler *prof, MonoDomain *domain);
 
 static void appdomain_start_unload (MonoProfiler *prof, MonoDomain *domain);
 
@@ -761,7 +754,7 @@ static void emit_thread_start (gpointer key, gpointer value, gpointer user_data)
 
 static void invalidate_each_thread (gpointer key, gpointer value, gpointer user_data);
 
-static void assembly_load (MonoProfiler *prof, MonoAssembly *assembly, int result);
+static void assembly_load (MonoProfiler *prof, MonoAssembly *assembly);
 
 static void assembly_unload (MonoProfiler *prof, MonoAssembly *assembly);
 
@@ -769,7 +762,11 @@ static void emit_assembly_load (gpointer assembly, gpointer user_data);
 
 static void emit_type_load (gpointer key, gpointer type, gpointer user_data);
 
-static void jit_end (MonoProfiler *prof, MonoMethod *method, MonoJitInfo *jinfo, int result);
+static void jit_done (MonoProfiler *prof, MonoMethod *method, MonoJitInfo *jinfo);
+
+static void jit_failed (MonoProfiler *prof, MonoMethod *method);
+
+static void jit_end (MonoProfiler *prof, MonoMethod *method, MonoJitInfo *jinfo);
 
 static void add_pending_breakpoints (MonoMethod *method, MonoJitInfo *jinfo);
 
@@ -995,13 +992,18 @@ mono_debugger_agent_init (void)
        mono_coop_mutex_init (&debugger_thread_exited_mutex);
        mono_coop_cond_init (&debugger_thread_exited_cond);
 
-       mono_profiler_install ((MonoProfiler*)&debugger_profiler, runtime_shutdown);
-       mono_profiler_set_events ((MonoProfileFlags)(MONO_PROFILE_APPDOMAIN_EVENTS | MONO_PROFILE_THREADS | MONO_PROFILE_ASSEMBLY_EVENTS | MONO_PROFILE_JIT_COMPILATION | MONO_PROFILE_METHOD_EVENTS));
-       mono_profiler_install_runtime_initialized (runtime_initialized);
-       mono_profiler_install_appdomain (NULL, appdomain_load, appdomain_start_unload, appdomain_unload);
-       mono_profiler_install_thread (thread_startup, thread_end);
-       mono_profiler_install_assembly (NULL, assembly_load, assembly_unload, NULL);
-       mono_profiler_install_jit_end (jit_end);
+       MonoProfilerHandle prof = mono_profiler_create (NULL);
+       mono_profiler_set_runtime_shutdown_end_callback (prof, runtime_shutdown);
+       mono_profiler_set_runtime_initialized_callback (prof, runtime_initialized);
+       mono_profiler_set_domain_loaded_callback (prof, appdomain_load);
+       mono_profiler_set_domain_unloading_callback (prof, appdomain_start_unload);
+       mono_profiler_set_domain_unloaded_callback (prof, appdomain_unload);
+       mono_profiler_set_thread_started_callback (prof, thread_startup);
+       mono_profiler_set_thread_stopped_callback (prof, thread_end);
+       mono_profiler_set_assembly_loaded_callback (prof, assembly_load);
+       mono_profiler_set_assembly_unloading_callback (prof, assembly_unload);
+       mono_profiler_set_jit_done_callback (prof, jit_done);
+       mono_profiler_set_jit_failed_callback (prof, jit_failed);
 
        mono_native_tls_alloc (&debugger_tls_id, NULL);
 
@@ -3960,7 +3962,7 @@ thread_end (MonoProfiler *prof, uintptr_t tid)
 }
 
 static void
-appdomain_load (MonoProfiler *prof, MonoDomain *domain, int result)
+appdomain_load (MonoProfiler *prof, MonoDomain *domain)
 {
        mono_loader_lock ();
        g_hash_table_insert (domains, domain, domain);
@@ -4022,7 +4024,7 @@ invalidate_each_thread (gpointer key, gpointer value, gpointer user_data)
 }
 
 static void
-assembly_load (MonoProfiler *prof, MonoAssembly *assembly, int result)
+assembly_load (MonoProfiler *prof, MonoAssembly *assembly)
 {
        /* Sent later in jit_end () */
        dbg_lock ();
@@ -4110,7 +4112,19 @@ send_assemblies_for_domain (MonoDomain *domain, void *user_data)
 }
 
 static void
-jit_end (MonoProfiler *prof, MonoMethod *method, MonoJitInfo *jinfo, int result)
+jit_done (MonoProfiler *prof, MonoMethod *method, MonoJitInfo *jinfo)
+{
+       jit_end (prof, method, jinfo);
+}
+
+static void
+jit_failed (MonoProfiler *prof, MonoMethod *method)
+{
+       jit_end (prof, method, NULL);
+}
+
+static void
+jit_end (MonoProfiler *prof, MonoMethod *method, MonoJitInfo *jinfo)
 {
        /*
         * We emit type load events when the first method of the type is JITted,
@@ -4138,7 +4152,7 @@ jit_end (MonoProfiler *prof, MonoMethod *method, MonoJitInfo *jinfo, int result)
 
        send_type_load (method->klass);
 
-       if (!result && jinfo)
+       if (jinfo)
                add_pending_breakpoints (method, jinfo);
 }
 
@@ -4792,7 +4806,7 @@ set_set_notification_for_wait_completion_flag (StackFrame *frame)
 static MonoMethod* notify_debugger_of_wait_completion_method_cache = NULL;
 
 static MonoMethod*
-get_notify_debugger_of_wait_completion_method ()
+get_notify_debugger_of_wait_completion_method (void)
 {
        if (notify_debugger_of_wait_completion_method_cache != NULL)
                return notify_debugger_of_wait_completion_method_cache;
@@ -7096,11 +7110,17 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8
                                args [i] = arg_buf [i];
                        }
                } else {
-                       arg_buf [i] = (guint8 *)g_alloca (mono_class_instance_size (mono_class_from_mono_type (sig->params [i])));
+                       MonoClass *arg_class = mono_class_from_mono_type (sig->params [i]);
+                       arg_buf [i] = (guint8 *)g_alloca (mono_class_instance_size (arg_class));
                        err = decode_value (sig->params [i], domain, arg_buf [i], p, &p, end);
                        if (err != ERR_NONE)
                                break;
-                       args [i] = arg_buf [i];
+                       if (mono_class_is_nullable (arg_class)) {
+                               args [i] = mono_nullable_box (arg_buf [i], arg_class, &error);
+                               mono_error_assert_ok (&error);
+                       } else {
+                               args [i] = arg_buf [i];
+                       }
                }
        }
 
@@ -7153,7 +7173,9 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8
                if ((invoke->flags & INVOKE_FLAG_RETURN_OUT_ARGS) && CHECK_PROTOCOL_VERSION (2, 35))
                        out_args = TRUE;
                buffer_add_byte (buf, 1 + (out_this ? 2 : 0) + (out_args ? 4 : 0));
-               if (sig->ret->type == MONO_TYPE_VOID) {
+               if (m->string_ctor) {
+                       buffer_add_value (buf, &mono_get_string_class ()->byval_arg, &res, domain);
+               } else if (sig->ret->type == MONO_TYPE_VOID && !m->string_ctor) {
                        if (!strcmp (m->name, ".ctor")) {
                                if (!m->klass->valuetype)
                                        buffer_add_value (buf, &mono_defaults.object_class->byval_arg, &this_arg, domain);
@@ -9057,14 +9079,6 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
                                        buffer_add_int (buf, locals->code_blocks [i].end_offset - locals->code_blocks [i].start_offset);
                                        last_start = locals->code_blocks [i].start_offset;
                                }
-                               if (CHECK_PROTOCOL_VERSION (2, 46)) {
-                                       /* Scopes for hoisted locals */
-                                       buffer_add_int (buf, locals->num_hoisted);
-                                       for (i = 0; i < locals->num_hoisted; ++i) {
-                                               buffer_add_int (buf, locals->code_blocks [i].start_offset);
-                                               buffer_add_int (buf, locals->code_blocks [i].end_offset);
-                                       }
-                               }
                        }
 
                        num_locals = locals->num_locals;