2004-07-05 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / metadata / mono-debug.c
index 804d11c88179caf98da4efcdbbae1bc468e72b41..b8503ecbc4be7be428935b57fb52d1f1e03bca25 100644 (file)
@@ -2,15 +2,29 @@
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/tabledefs.h>
 #include <mono/metadata/tokentype.h>
+#include <mono/metadata/appdomain.h>
+#include <mono/metadata/class-internals.h>
 #include <mono/metadata/mono-debug.h>
 #include <mono/metadata/mono-debug-debugger.h>
+#include <mono/metadata/mono-endian.h>
 
-MonoDebugFormat mono_debug_format;
+struct _MonoDebugHandlePriv
+{
+       MonoDebuggerSymbolFile *debugger_info;
+       MonoDebugDomainData *domain_table;
+};
+
+struct _MonoDebugDomainDataPriv
+{
+       GHashTable *wrapper_info;
+       MonoDebugDomainData *next;
+};
+
+MonoDebugFormat mono_debug_format = MONO_DEBUG_FORMAT_NONE;
 
-static CRITICAL_SECTION debugger_lock_mutex;
+static gboolean in_the_mono_debugger = FALSE;
 static gboolean mono_debug_initialized = FALSE;
-static gboolean debug_handles_dirty = FALSE;
-static GHashTable *debug_handles = NULL;
+GHashTable *mono_debug_handles = NULL;
 
 static MonoDebugHandle *mono_debug_open_image    (MonoImage *image);
 static void             mono_debug_close_image   (MonoDebugHandle *debug);
@@ -21,22 +35,6 @@ static void             mono_debug_add_type      (MonoClass *klass);
 
 extern void (*mono_debugger_class_init_func) (MonoClass *klass);
 
-/* This is incremented each time the symbol table is modified.
- * The debugger looks at this variable and if it has a higher value than its current
- * copy of the symbol table, it must call mono_debug_update_symbol_file_table().
- */
-guint32 mono_debugger_symbol_file_table_generation = 0;
-guint32 mono_debugger_symbol_file_table_modified = 0;
-
-/* Caution: This variable may be accessed at any time from the debugger;
- *          it is very important not to modify the memory it is pointing to
- *          without previously setting this pointer back to NULL.
- */
-MonoDebuggerSymbolFileTable *mono_debugger_symbol_file_table = NULL;
-
-/* Caution: This function MUST be called before touching the symbol table! */
-static void release_symbol_file_table (void);
-
 /*
  * Initialize debugging support.
  *
@@ -45,7 +43,7 @@ static void release_symbol_file_table (void);
  * callbacks here.
  */
 void
-mono_debug_init (MonoDebugFormat format)
+mono_debug_init (MonoDomain *domain, MonoDebugFormat format)
 {
        MonoAssembly **ass;
 
@@ -53,20 +51,25 @@ mono_debug_init (MonoDebugFormat format)
 
        mono_debug_initialized = TRUE;
        mono_debug_format = format;
+       in_the_mono_debugger = format == MONO_DEBUG_FORMAT_DEBUGGER;
 
-       InitializeCriticalSection (&debugger_lock_mutex);
+       if (in_the_mono_debugger)
+               mono_debugger_initialize (domain);
 
-       mono_debug_lock ();
+       mono_debugger_lock ();
 
-       debug_handles = g_hash_table_new_full
+       mono_debug_handles = g_hash_table_new_full
                (NULL, NULL, NULL, (GDestroyNotify) mono_debug_close_image);
 
        mono_debugger_class_init_func = mono_debug_add_type;
        mono_install_assembly_load_hook (mono_debug_add_assembly, NULL);
 
-       mono_debug_open_image (mono_defaults.corlib);
+       mono_debug_open_image (mono_get_corlib ());
+       /*
+        * FIXME: Ugh: what is this code supposed to do? corlib has no references.
        for (ass = mono_defaults.corlib->references; ass && *ass; ass++)
                mono_debug_open_image ((*ass)->image);
+       */
 }
 
 /*
@@ -77,85 +80,28 @@ mono_debug_init (MonoDebugFormat format)
 void
 mono_debug_init_2 (MonoAssembly *assembly)
 {
-       mono_debug_open_image (assembly->image);
-
-       mono_debug_add_type (mono_defaults.object_class);
-       mono_debug_add_type (mono_defaults.object_class);
-       mono_debug_add_type (mono_defaults.byte_class);
-       mono_debug_add_type (mono_defaults.void_class);
-       mono_debug_add_type (mono_defaults.boolean_class);
-       mono_debug_add_type (mono_defaults.sbyte_class);
-       mono_debug_add_type (mono_defaults.int16_class);
-       mono_debug_add_type (mono_defaults.uint16_class);
-       mono_debug_add_type (mono_defaults.int32_class);
-       mono_debug_add_type (mono_defaults.uint32_class);
-       mono_debug_add_type (mono_defaults.int_class);
-       mono_debug_add_type (mono_defaults.uint_class);
-       mono_debug_add_type (mono_defaults.int64_class);
-       mono_debug_add_type (mono_defaults.uint64_class);
-       mono_debug_add_type (mono_defaults.single_class);
-       mono_debug_add_type (mono_defaults.double_class);
-       mono_debug_add_type (mono_defaults.char_class);
-       mono_debug_add_type (mono_defaults.string_class);
-       mono_debug_add_type (mono_defaults.enum_class);
-       mono_debug_add_type (mono_defaults.array_class);
-       mono_debug_add_type (mono_defaults.multicastdelegate_class);
-       mono_debug_add_type (mono_defaults.asyncresult_class);
-       mono_debug_add_type (mono_defaults.waithandle_class);
-       mono_debug_add_type (mono_defaults.typehandle_class);
-       mono_debug_add_type (mono_defaults.fieldhandle_class);
-       mono_debug_add_type (mono_defaults.methodhandle_class);
-       mono_debug_add_type (mono_defaults.monotype_class);
-       mono_debug_add_type (mono_defaults.exception_class);
-       mono_debug_add_type (mono_defaults.threadabortexception_class);
-       mono_debug_add_type (mono_defaults.thread_class);
-       mono_debug_add_type (mono_defaults.transparent_proxy_class);
-       mono_debug_add_type (mono_defaults.real_proxy_class);
-       mono_debug_add_type (mono_defaults.mono_method_message_class);
-       mono_debug_add_type (mono_defaults.appdomain_class);
-       mono_debug_add_type (mono_defaults.field_info_class);
-       mono_debug_add_type (mono_defaults.stringbuilder_class);
-       mono_debug_add_type (mono_defaults.math_class);
-       mono_debug_add_type (mono_defaults.stack_frame_class);
-       mono_debug_add_type (mono_defaults.stack_trace_class);
-       mono_debug_add_type (mono_defaults.marshal_class);
-       mono_debug_add_type (mono_defaults.iserializeable_class);
-       mono_debug_add_type (mono_defaults.serializationinfo_class);
-       mono_debug_add_type (mono_defaults.streamingcontext_class);
-
-       mono_debug_update_symbol_file_table ();
-
-       mono_debug_unlock ();
-}
+       MonoDebugHandle *handle;
 
-void
-mono_debug_cleanup (void)
-{
-       release_symbol_file_table ();
+       mono_debug_open_image (mono_assembly_get_image (assembly));
 
-       if (debug_handles)
-               g_hash_table_destroy (debug_handles);
-       debug_handles = NULL;
+       handle = _mono_debug_get_image (mono_get_corlib ());
+       g_assert (handle);
 }
 
 void
-mono_debug_lock (void)
+mono_debug_cleanup (void)
 {
-       if (mono_debug_initialized)
-               EnterCriticalSection (&debugger_lock_mutex);
-}
+       mono_debugger_cleanup ();
 
-void
-mono_debug_unlock (void)
-{
-       if (mono_debug_initialized)
-               LeaveCriticalSection (&debugger_lock_mutex);
+       if (mono_debug_handles)
+               g_hash_table_destroy (mono_debug_handles);
+       mono_debug_handles = NULL;
 }
 
 static MonoDebugHandle *
 _mono_debug_get_image (MonoImage *image)
 {
-       return g_hash_table_lookup (debug_handles, image);
+       return g_hash_table_lookup (mono_debug_handles, image);
 }
 
 static MonoDebugHandle *
@@ -169,15 +115,20 @@ mono_debug_open_image (MonoImage *image)
 
        handle = g_new0 (MonoDebugHandle, 1);
        handle->image = image;
-       handle->image->ref_count++;
-       handle->wrapper_info = g_hash_table_new (g_direct_hash, g_direct_equal);
+       mono_image_addref (image);
+       handle->image_file = g_strdup (mono_image_get_filename (image));
+       handle->_priv = g_new0 (MonoDebugHandlePriv, 1);
 
-       g_hash_table_insert (debug_handles, image, handle);
+       g_hash_table_insert (mono_debug_handles, image, handle);
 
-       if (!image->assembly->dynamic) {
-               handle->symfile = mono_debug_open_mono_symbol_file
-                       (handle->image, mono_debug_format == MONO_DEBUG_FORMAT_DEBUGGER);
-               mono_debugger_symbol_file_table_generation++;
+       if (mono_image_is_dynamic (image))
+               return handle;
+
+       handle->symfile = mono_debug_open_mono_symbol_file (handle, in_the_mono_debugger);
+       if (in_the_mono_debugger) {
+               handle->_priv->debugger_info = mono_debugger_add_symbol_file (handle);
+               if (image == mono_get_corlib ())
+                       mono_debugger_add_builtin_types (handle->_priv->debugger_info);
        }
 
        return handle;
@@ -188,17 +139,19 @@ mono_debug_close_image (MonoDebugHandle *handle)
 {
        if (handle->symfile)
                mono_debug_close_mono_symbol_file (handle->symfile);
-       g_hash_table_destroy (handle->wrapper_info);
-       handle->image->ref_count--;
+       /* decrease the refcount added with mono_image_addref () */
+       mono_image_close (handle->image);
+       /* FIXME: should also free handle->image_file? */
+       g_free (handle->_priv);
        g_free (handle);
 }
 
 static void
 mono_debug_add_assembly (MonoAssembly *assembly, gpointer user_data)
 {
-       mono_debug_lock ();
-       mono_debug_open_image (assembly->image);
-       mono_debug_unlock ();
+       mono_debugger_lock ();
+       mono_debug_open_image (mono_assembly_get_image (assembly));
+       mono_debugger_unlock ();
 }
 
 /*
@@ -211,14 +164,11 @@ mono_debug_add_type (MonoClass *klass)
        MonoDebugHandle *handle;
 
        handle = _mono_debug_get_image (klass->image);
-       g_assert (handle);
+       if (!handle)
+               return;
 
-       if (handle->symfile) {
-               mono_debug_lock ();
-               mono_debug_symfile_add_type (handle->symfile, klass);
-               mono_debugger_event (MONO_DEBUGGER_EVENT_TYPE_ADDED, handle->symfile, klass);
-               mono_debug_unlock ();
-       }
+       if (handle->_priv->debugger_info)
+               mono_debugger_add_type (handle->_priv->debugger_info, klass);
 }
 
 struct LookupMethodData
@@ -237,18 +187,21 @@ lookup_method_func (gpointer key, gpointer value, gpointer user_data)
                return;
 
        if (handle->symfile)
-               data->minfo = mono_debug_find_method (handle->symfile, data->method);
+               data->minfo = mono_debug_find_method (handle, data->method);
 }
 
 static MonoDebugMethodInfo *
 _mono_debug_lookup_method (MonoMethod *method)
 {
-       struct LookupMethodData data = { NULL, method };
+       struct LookupMethodData data;
+
+       data.minfo = NULL;
+       data.method = method;
 
-       if (!debug_handles)
+       if (!mono_debug_handles)
                return NULL;
 
-       g_hash_table_foreach (debug_handles, lookup_method_func, &data);
+       g_hash_table_foreach (mono_debug_handles, lookup_method_func, &data);
        return data.minfo;
 }
 
@@ -257,14 +210,17 @@ _mono_debug_lookup_method (MonoMethod *method)
  * wrapper method.
  */
 void
-mono_debug_add_wrapper (MonoMethod *method, MonoMethod *wrapper_method)
+mono_debug_add_wrapper (MonoMethod *method, MonoMethod *wrapper_method, MonoDomain *domain)
 {
-       MonoClass *klass = method->klass;
+       MonoClass *klass = mono_method_get_class (method);
        MonoDebugHandle *handle;
        MonoDebugMethodInfo *minfo;
        MonoDebugMethodJitInfo *jit;
+       MonoDebugDomainData *domain_data;
+       guint32 iflags;
 
-       if (!(method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
+       mono_method_get_flags (method, &iflags);
+       if (!(iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
                return;
 
        mono_class_init (klass);
@@ -273,25 +229,29 @@ mono_debug_add_wrapper (MonoMethod *method, MonoMethod *wrapper_method)
        g_assert (handle);
 
        minfo = _mono_debug_lookup_method (method);
-       if (!minfo || minfo->jit)
+       if (!minfo)
                return;
 
-       jit = g_hash_table_lookup (handle->wrapper_info, wrapper_method);
-       g_assert (jit);
+       domain_data = mono_debug_get_domain_data (handle, domain);
+       if (domain_data->jit [minfo->index]) {
+               /* FIXME FIXME FIXME
+               // This is bug #48591.
+               */
+               return;
+       }
 
-       mono_debug_lock ();
+       jit = g_hash_table_lookup (domain_data->_priv->wrapper_info, wrapper_method);
+       g_assert (jit);
 
-       debug_handles_dirty = TRUE;
+       mono_debugger_lock ();
 
-       minfo->jit = jit;
-       minfo->jit->wrapper_addr = method->addr;
+       domain_data->jit [minfo->index] = jit;
+       jit->wrapper_addr = method->addr;
 
-       if (handle->symfile) {
-               mono_debug_symfile_add_method (handle->symfile, method);
-               mono_debugger_event (MONO_DEBUGGER_EVENT_METHOD_ADDED, handle->symfile, method);
-       }
+       if (handle->_priv->debugger_info && (domain == mono_get_root_domain ()))
+               mono_debugger_add_method (handle->_priv->debugger_info, minfo, jit);
 
-       mono_debug_unlock ();
+       mono_debugger_unlock ();
 }
 
 /*
@@ -299,66 +259,71 @@ mono_debug_add_wrapper (MonoMethod *method, MonoMethod *wrapper_method)
  * compiled method.
  */
 void
-mono_debug_add_method (MonoMethod *method, MonoDebugMethodJitInfo *jit)
+mono_debug_add_method (MonoMethod *method, MonoDebugMethodJitInfo *jit, MonoDomain *domain)
 {
        MonoClass *klass = method->klass;
+       MonoDebugDomainData *domain_data;
        MonoDebugHandle *handle;
        MonoDebugMethodInfo *minfo;
 
+       mono_debugger_lock ();
+
        mono_class_init (klass);
 
        if ((method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) ||
            (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) ||
            (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
-           (method->flags & METHOD_ATTRIBUTE_ABSTRACT))
+           (method->flags & METHOD_ATTRIBUTE_ABSTRACT)) {
+               mono_debugger_unlock ();
                return;
+       }
 
        handle = _mono_debug_get_image (klass->image);
-       g_assert (handle);
-
-       if (method->wrapper_type != MONO_WRAPPER_NONE) {
-               g_hash_table_insert (handle->wrapper_info, method, jit);
+       if (!handle) {
+               mono_debugger_unlock ();
                return;
        }
 
        minfo = _mono_debug_lookup_method (method);
-       if (!minfo)
+       if (!minfo) {
+               mono_debugger_unlock ();
                return;
+       }
 
-       mono_debug_lock ();
-       debug_handles_dirty = TRUE;
-
-       g_assert (!minfo->jit);
-       minfo->jit = jit;
+       domain_data = mono_debug_get_domain_data (handle, domain);
+       if (domain_data->jit [minfo->index]) {
+               /* FIXME FIXME FIXME
+               // This is bug #48591.
+               */
+               mono_debugger_unlock ();
+               return;
+       }
 
-       if (handle->symfile) {
-               mono_debug_symfile_add_method (handle->symfile, method);
-               mono_debugger_event (MONO_DEBUGGER_EVENT_METHOD_ADDED, handle->symfile, method);
+       if (method->wrapper_type != MONO_WRAPPER_NONE) {
+               g_hash_table_insert (domain_data->_priv->wrapper_info, method, jit);
+               mono_debugger_unlock ();
+               return;
        }
 
-       mono_debug_unlock ();
-}
+       domain_data->jit [minfo->index] = jit;
 
-void
-mono_debug_update (void)
-{
-       if (mono_debug_format != MONO_DEBUG_FORMAT_NONE) {
-               mono_debug_update_symbol_file_table ();
-               debug_handles_dirty = FALSE;
-       }
+       if (handle->_priv->debugger_info && (domain == mono_get_root_domain ()))
+               mono_debugger_add_method (handle->_priv->debugger_info, minfo, jit);
+
+       mono_debugger_unlock ();
 }
 
 static gint32
-il_offset_from_address (MonoDebugMethodInfo *minfo, guint32 address)
+il_offset_from_address (MonoDebugMethodJitInfo *jit, guint32 address)
 {
        int i;
 
-       if (!minfo->jit || !minfo->jit->line_numbers)
+       if (!jit || !jit->line_numbers)
                return -1;
 
-       for (i = minfo->jit->line_numbers->len - 1; i >= 0; i--) {
+       for (i = jit->line_numbers->len - 1; i >= 0; i--) {
                MonoDebugLineNumberEntry lne = g_array_index (
-                       minfo->jit->line_numbers, MonoDebugLineNumberEntry, i);
+                       jit->line_numbers, MonoDebugLineNumberEntry, i);
 
                if (lne.address <= address)
                        return lne.offset;
@@ -378,20 +343,26 @@ il_offset_from_address (MonoDebugMethodInfo *minfo, guint32 address)
  * line number 8 in the variable pointed to by @line_number).
  */
 gchar *
-mono_debug_source_location_from_address (MonoMethod *method, guint32 address, guint32 *line_number)
+mono_debug_source_location_from_address (MonoMethod *method, guint32 address, guint32 *line_number,
+                                        MonoDomain *domain)
 {
        MonoDebugMethodInfo *minfo = _mono_debug_lookup_method (method);
+       MonoDebugDomainData *domain_data;
 
        if (!minfo)
                return NULL;
 
-       if (minfo->symfile) {
-               gint32 offset = il_offset_from_address (minfo, address);
+       domain_data = mono_debug_get_domain_data (minfo->handle, domain);
+       if (!domain_data->jit [minfo->index])
+               return NULL;
+
+       if (minfo->handle) {
+               gint32 offset = il_offset_from_address (domain_data->jit [minfo->index], address);
                
                if (offset < 0)
                        return NULL;
 
-               return mono_debug_find_source_location (minfo->symfile, method, offset, line_number);
+               return mono_debug_find_source_location (minfo->handle->symfile, method, offset, line_number);
        }
 
        return NULL;
@@ -412,10 +383,10 @@ mono_debug_source_location_from_il_offset (MonoMethod *method, guint32 offset, g
 {
        MonoDebugMethodInfo *minfo = _mono_debug_lookup_method (method);
 
-       if (!minfo || !minfo->symfile)
+       if (!minfo || !minfo->handle)
                return NULL;
 
-       return mono_debug_find_source_location (minfo->symfile, method, offset, line_number);
+       return mono_debug_find_source_location (minfo->handle->symfile, method, offset, line_number);
 }
 
 /*
@@ -423,9 +394,10 @@ mono_debug_source_location_from_il_offset (MonoMethod *method, guint32 offset, g
  * relative to the beginning of the method @method.
  */
 gint32
-mono_debug_il_offset_from_address (MonoMethod *method, gint32 address)
+mono_debug_il_offset_from_address (MonoMethod *method, gint32 address, MonoDomain *domain)
 {
        MonoDebugMethodInfo *minfo;
+       MonoDebugDomainData *domain_data;
 
        if (address < 0)
                return -1;
@@ -434,7 +406,9 @@ mono_debug_il_offset_from_address (MonoMethod *method, gint32 address)
        if (!minfo || !minfo->il_offsets)
                return -1;
 
-       return il_offset_from_address (minfo, address);
+       domain_data = mono_debug_get_domain_data (minfo->handle, domain);
+
+       return il_offset_from_address (domain_data->jit [minfo->index], address);
 }
 
 /*
@@ -442,9 +416,10 @@ mono_debug_il_offset_from_address (MonoMethod *method, gint32 address)
  * The returned value is an offset relative to the beginning of the method @method.
  */
 gint32
-mono_debug_address_from_il_offset (MonoMethod *method, gint32 il_offset)
+mono_debug_address_from_il_offset (MonoMethod *method, gint32 il_offset, MonoDomain *domain)
 {
        MonoDebugMethodInfo *minfo;
+       MonoDebugDomainData *domain_data;
 
        if (il_offset < 0)
                return -1;
@@ -453,88 +428,29 @@ mono_debug_address_from_il_offset (MonoMethod *method, gint32 il_offset)
        if (!minfo || !minfo->il_offsets)
                return -1;
 
-       return _mono_debug_address_from_il_offset (minfo, il_offset);
-}
-
-static void
-release_symbol_file_table ()
-{
-       MonoDebuggerSymbolFileTable *temp;
+       domain_data = mono_debug_get_domain_data (minfo->handle, domain);
 
-       if (!mono_debugger_symbol_file_table)
-               return;
-
-       /*
-        * Caution: The debugger may access the memory pointed to by this variable
-        *          at any time.  It is very important to set the pointer to NULL
-        *          before freeing the area.
-        */
-
-       temp = mono_debugger_symbol_file_table;
-       mono_debugger_symbol_file_table = NULL;
-       g_free (mono_debugger_symbol_file_table);
+       return _mono_debug_address_from_il_offset (domain_data->jit [minfo->index], il_offset);
 }
 
-static void
-update_symbol_file_table_count_func (gpointer key, gpointer value, gpointer user_data)
+MonoDebugDomainData *
+mono_debug_get_domain_data (MonoDebugHandle *handle, MonoDomain *domain)
 {
-       MonoDebugHandle *handle = (MonoDebugHandle *) value;
-
-       if (!handle->symfile)
-               return;
-
-       ++ (* (int *) user_data);
-}
-
-struct SymfileTableData
-{
-       MonoDebuggerSymbolFileTable *symfile_table;
-       int index;
-};
-
-static void
-update_symbol_file_table_func (gpointer key, gpointer value, gpointer user_data)
-{
-       MonoDebugHandle *handle = (MonoDebugHandle *) value;
-       struct SymfileTableData *data = (struct SymfileTableData *) user_data;
-
-       if (!handle->symfile)
-               return;
-
-       data->symfile_table->symfiles [data->index++] = handle->symfile;
-}
-
-int
-mono_debug_update_symbol_file_table (void)
-{
-       int count = 0;
-       MonoDebuggerSymbolFileTable *symfile_table;
-       struct SymfileTableData data;
-       guint32 size;
-
-       mono_debug_lock ();
-
-       g_hash_table_foreach (debug_handles, update_symbol_file_table_count_func, &count);
-
-       release_symbol_file_table ();
-
-       size = sizeof (MonoDebuggerSymbolFileTable) + count * sizeof (MonoSymbolFile *);
-       symfile_table = g_malloc0 (size);
-       symfile_table->magic = MONO_SYMBOL_FILE_DYNAMIC_MAGIC;
-       symfile_table->version = MONO_SYMBOL_FILE_DYNAMIC_VERSION;
-       symfile_table->total_size = size;
-       symfile_table->count = count;
-       symfile_table->generation = mono_debugger_symbol_file_table_generation;
-       symfile_table->global_symfile = mono_debugger_global_symbol_file;
-
-       data.symfile_table = symfile_table;
-       data.index = 0;
+       MonoDebugDomainData *data;
+       int domain_id = mono_domain_get_id (domain);
 
-       g_hash_table_foreach (debug_handles, update_symbol_file_table_func, &data);
+       for (data = handle->_priv->domain_table; data; data = data->_priv->next)
+               if (data->domain_id == domain_id)
+                       return data;
 
-       mono_debugger_symbol_file_table = symfile_table;
+       data = g_new0 (MonoDebugDomainData, 1);
+       data->domain_id = domain_id;
+       data->jit = g_new0 (MonoDebugMethodJitInfo *, read32(&(handle->symfile->offset_table->_method_count)) + 1);
 
-       mono_debug_unlock ();
+       data->_priv = g_new0 (MonoDebugDomainDataPriv, 1);
+       data->_priv->next = handle->_priv->domain_table;
+       data->_priv->wrapper_info = g_hash_table_new (g_direct_hash, g_direct_equal);
+       handle->_priv->domain_table = data;
 
-       return TRUE;
+       return data;
 }