Merge pull request #261 from joncham/bug-null-interface-bitset
[mono.git] / mono / metadata / mono-debug-debugger.c
index f4c54de700a5f104573e40745afbbf1a36bd6acc..929c3fbb2037a75a398384f243a269334773cf52 100644 (file)
@@ -1,3 +1,13 @@
+/*
+ * mono-debug-debugger.c: 
+ *
+ * Author:
+ *     Mono Project (http://www.mono-project.com)
+ *
+ * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
+ * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
+ */
+
 #include <config.h>
 #include <stdlib.h>
 #include <string.h>
@@ -11,6 +21,7 @@
 #include <mono/metadata/gc-internal.h>
 #include <mono/metadata/object-internals.h>
 #include <mono/metadata/class-internals.h>
+#include <mono/metadata/domain-internals.h>
 #include <mono/metadata/exception.h>
 #include <mono/metadata/mono-debug.h>
 #include <mono/metadata/mono-debug-debugger.h>
@@ -24,12 +35,6 @@ volatile gint32 _mono_debugger_interruption_request = 0;
 
 void (*mono_debugger_event_handler) (MonoDebuggerEvent event, guint64 data, guint64 arg) = NULL;
 
-typedef struct {
-       gpointer stack_pointer;
-       MonoObject *exception_obj;
-       guint32 stop;
-} MonoDebuggerExceptionInfo;
-
 typedef struct
 {
        guint32 index;
@@ -45,6 +50,14 @@ typedef struct {
        gchar *name;
 } ClassInitCallback;
 
+typedef struct {
+       guint32 id;
+       guint32 shadow_path_len;
+       gchar *shadow_path;
+       MonoDomain *domain;
+       MonoAppDomainSetup *setup;
+} AppDomainSetupInfo;
+
 static GPtrArray *class_init_callbacks = NULL;
 
 static int initialized = 0;
@@ -68,7 +81,7 @@ mono_debugger_unlock (void)
 void
 mono_debugger_initialize (gboolean use_debugger)
 {
-       MONO_GC_REGISTER_ROOT (last_exception);
+       MONO_GC_REGISTER_ROOT_SINGLE (last_exception);
        
        g_assert (!mono_debugger_use_debugger);
 
@@ -85,132 +98,32 @@ mono_debugger_event (MonoDebuggerEvent event, guint64 data, guint64 arg)
 }
 
 void
-mono_debugger_cleanup (void)
-{
-       mono_debugger_event (MONO_DEBUGGER_EVENT_FINALIZE_MANAGED_CODE, 0, 0);
-       mono_debugger_event_handler = NULL;
-}
-
-gboolean
-mono_debugger_unhandled_exception (gpointer addr, gpointer stack, MonoObject *exc)
+mono_debugger_event_create_appdomain (MonoDomain *domain, gchar *shadow_path)
 {
-       const gchar *name;
+       AppDomainSetupInfo info;
 
-       if (!mono_debugger_use_debugger)
-               return FALSE;
+       info.id = mono_domain_get_id (domain);
+       info.shadow_path_len = shadow_path ? strlen (shadow_path) : 0;
+       info.shadow_path = shadow_path;
 
-       name = mono_class_get_name (mono_object_get_class (exc));
-       if (!strcmp (name, "ThreadAbortException"))
-               return FALSE;
+       info.domain = domain;
+       info.setup = domain->setup;
 
-       // Prevent the object from being finalized.
-       last_exception = exc;
-
-       mono_debugger_event (MONO_DEBUGGER_EVENT_UNHANDLED_EXCEPTION,
-                            (guint64) (gsize) exc, (guint64) (gsize) addr);
-       return TRUE;
+       mono_debugger_event (MONO_DEBUGGER_EVENT_CREATE_APPDOMAIN, (guint64) (gsize) &info, 0);
 }
 
 void
-mono_debugger_handle_exception (gpointer addr, gpointer stack, MonoObject *exc)
+mono_debugger_event_unload_appdomain (MonoDomain *domain)
 {
-       MonoDebuggerExceptionInfo info;
-
-       if (!mono_debugger_use_debugger)
-               return;
-
-       // Prevent the object from being finalized.
-       last_exception = exc;
-
-       info.stack_pointer = stack;
-       info.exception_obj = exc;
-       info.stop = 0;
-
-       mono_debugger_event (MONO_DEBUGGER_EVENT_HANDLE_EXCEPTION, (guint64) (gsize) &info,
-                            (guint64) (gsize) addr);
-}
-
-gboolean
-mono_debugger_throw_exception (gpointer addr, gpointer stack, MonoObject *exc)
-{
-       MonoDebuggerExceptionInfo info;
-
-       if (!mono_debugger_use_debugger)
-               return FALSE;
-
-       // Prevent the object from being finalized.
-       last_exception = exc;
-
-       info.stack_pointer = stack;
-       info.exception_obj = exc;
-       info.stop = 0;
-
-       mono_debugger_event (MONO_DEBUGGER_EVENT_THROW_EXCEPTION, (guint64) (gsize) &info,
-                            (guint64) (gsize) addr);
-       return info.stop != 0;
+       mono_debugger_event (MONO_DEBUGGER_EVENT_UNLOAD_APPDOMAIN,
+                            (guint64) (gsize) domain, (guint64) mono_domain_get_id (domain));
 }
 
-static gchar *
-get_exception_message (MonoObject *exc)
-{
-       char *message = NULL;
-       MonoString *str; 
-       MonoMethod *method;
-       MonoClass *klass;
-       gint i;
-
-       if (mono_object_isinst (exc, mono_defaults.exception_class)) {
-               klass = exc->vtable->klass;
-               method = NULL;
-               while (klass && method == NULL) {
-                       for (i = 0; i < klass->method.count; ++i) {
-                               method = klass->methods [i];
-                               if (!strcmp ("ToString", method->name) &&
-                                   mono_method_signature (method)->param_count == 0 &&
-                                   method->flags & METHOD_ATTRIBUTE_VIRTUAL &&
-                                   method->flags & METHOD_ATTRIBUTE_PUBLIC) {
-                                       break;
-                               }
-                               method = NULL;
-                       }
-                       
-                       if (method == NULL)
-                               klass = klass->parent;
-               }
-
-               g_assert (method);
-
-               str = (MonoString *) mono_runtime_invoke (method, exc, NULL, NULL);
-               if (str)
-                       message = mono_string_to_utf8 (str);
-       }
-
-       return message;
-}
-
-MonoObject *
-mono_debugger_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc)
+void
+mono_debugger_cleanup (void)
 {
-       MonoObject *retval;
-       gchar *message;
-
-       if (!strcmp (method->name, ".ctor")) {
-               retval = obj = mono_object_new (mono_domain_get (), method->klass);
-
-               mono_runtime_invoke (method, obj, params, exc);
-       } else
-               retval = mono_runtime_invoke (method, obj, params, exc);
-
-       if (!exc || (*exc == NULL))
-               return retval;
-
-       message = get_exception_message (*exc);
-       if (message) {
-               *exc = (MonoObject *) mono_string_new_wrapper (message);
-               g_free (message);
-       }
-
-       return retval;
+       mono_debugger_event (MONO_DEBUGGER_EVENT_FINALIZE_MANAGED_CODE, 0, 0);
+       mono_debugger_event_handler = NULL;
 }
 
 void
@@ -279,36 +192,33 @@ mono_debugger_remove_method_breakpoint (guint64 index)
 void
 mono_debugger_check_breakpoints (MonoMethod *method, MonoDebugMethodAddress *debug_info)
 {
-       MonoClass *klass;
        int i;
 
-       if (!method_breakpoints)
-               return;
-
        if (method->is_inflated)
                method = ((MonoMethodInflated *) method)->declaring;
 
-       for (i = 0; i < method_breakpoints->len; i++) {
-               MethodBreakpointInfo *info = g_ptr_array_index (method_breakpoints, i);
+       if (method_breakpoints) {
+               for (i = 0; i < method_breakpoints->len; i++) {
+                       MethodBreakpointInfo *info = g_ptr_array_index (method_breakpoints, i);
 
-               if (method != info->method)
-                       continue;
+                       if (method != info->method)
+                               continue;
 
-               mono_debugger_event (MONO_DEBUGGER_EVENT_JIT_BREAKPOINT,
-                                    (guint64) (gsize) debug_info, info->index);
+                       mono_debugger_event (MONO_DEBUGGER_EVENT_JIT_BREAKPOINT,
+                                            (guint64) (gsize) debug_info, info->index);
+               }
        }
 
-       if (!class_init_callbacks)
-               return;
-
-       for (i = 0; i < class_init_callbacks->len; i++) {
-               ClassInitCallback *info = g_ptr_array_index (class_init_callbacks, i);
+       if (class_init_callbacks) {
+               for (i = 0; i < class_init_callbacks->len; i++) {
+                       ClassInitCallback *info = g_ptr_array_index (class_init_callbacks, i);
 
-               if ((method->token != info->token) || (method->klass->image != info->image))
-                       continue;
+                       if ((method->token != info->token) || (method->klass->image != info->image))
+                               continue;
 
-               mono_debugger_event (MONO_DEBUGGER_EVENT_JIT_BREAKPOINT,
-                                    (guint64) (gsize) debug_info, info->index);
+                       mono_debugger_event (MONO_DEBUGGER_EVENT_JIT_BREAKPOINT,
+                                            (guint64) (gsize) debug_info, info->index);
+               }
        }
 }
 
@@ -334,10 +244,6 @@ mono_debugger_register_class_init_callback (MonoImage *image, const gchar *full_
        mono_loader_lock ();
 
        klass = mono_class_from_name (image, name_space ? name_space : "", name);
-       if (klass && klass->inited && klass->methods) {
-               mono_loader_unlock ();
-               return klass;
-       }
 
        info = g_new0 (ClassInitCallback, 1);
        info->image = image;
@@ -351,7 +257,7 @@ mono_debugger_register_class_init_callback (MonoImage *image, const gchar *full_
 
        g_ptr_array_add (class_init_callbacks, info);
        mono_loader_unlock ();
-       return NULL;
+       return klass;
 }
 
 void