2004-07-12 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Sun, 11 Jul 2004 21:24:28 +0000 (21:24 -0000)
committerMartin Baulig <martin@novell.com>
Sun, 11 Jul 2004 21:24:28 +0000 (21:24 -0000)
* mono-debug.c (mono_debug_init): Don't take a `MonoDomain *'.
This function must be called before initializing the runtime.
(mono_debug_init_1): New function; call this after initializing
the runtime, but before loading the assembly.  It tells the
debugger to load corlib and the builtin types.

* mono-debug-debugger.c: Did some larger changes in the debugging
code; support recursive class declarations, make sure we actually
add all classes.

svn path=/trunk/mono/; revision=31011

mono/interpreter/interp.c
mono/metadata/ChangeLog
mono/metadata/class.c
mono/metadata/mono-debug-debugger.c
mono/metadata/mono-debug-debugger.h
mono/metadata/mono-debug.c
mono/metadata/mono-debug.h
mono/mini/driver.c

index 23d79432ee7c1e84fdb186379ee1c38bb6bb91e1..ab38ae4ff37ab1f2146a5505011fd20f4059e501 100644 (file)
@@ -4230,8 +4230,10 @@ static void main_thread_handler (gpointer user_data)
        MainThreadArgs *main_args=(MainThreadArgs *)user_data;
        MonoAssembly *assembly;
 
-       if (main_args->enable_debugging)
-               mono_debug_init (main_args->domain, MONO_DEBUG_FORMAT_MONO);
+       if (main_args->enable_debugging) {
+               mono_debug_init (MONO_DEBUG_FORMAT_MONO);
+               mono_debug_init_1 (main_args->domain);
+       }
 
        assembly = mono_domain_assembly_open (main_args->domain,
                                              main_args->file);
index 94539bff9d11f2c9ab346e39ea7214583abd2dac..0240924a985595c1f5111887e714cb06853381eb 100644 (file)
@@ -1,3 +1,15 @@
+2004-07-12  Martin Baulig  <martin@ximian.com>
+
+       * mono-debug.c (mono_debug_init): Don't take a `MonoDomain *'.
+       This function must be called before initializing the runtime.
+       (mono_debug_init_1): New function; call this after initializing
+       the runtime, but before loading the assembly.  It tells the
+       debugger to load corlib and the builtin types.
+
+       * mono-debug-debugger.c: Did some larger changes in the debugging
+       code; support recursive class declarations, make sure we actually
+       add all classes.
+
 2004-07-11 Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * debug-helpers.c: undo my previous patch and fixed the real issue in
index ae455e1c4cee430b9d26bd7a9549aa2298240b8e..d07beca409c772a3592522d9e38d363beadef872 100644 (file)
@@ -40,6 +40,7 @@ gboolean mono_print_vtable = FALSE;
 
 static MonoClass * mono_class_create_from_typedef (MonoImage *image, guint32 type_token);
 
+void (*mono_debugger_start_class_init_func) (MonoClass *klass) = NULL;
 void (*mono_debugger_class_init_func) (MonoClass *klass) = NULL;
 
 MonoClass *
@@ -1298,6 +1299,9 @@ mono_class_init (MonoClass *class)
 
        class->init_pending = 1;
 
+       if (mono_debugger_start_class_init_func)
+               mono_debugger_start_class_init_func (class);
+
        mono_stats.initialized_class_count++;
 
        if (class->generic_inst && !class->generic_inst->is_dynamic) {
@@ -1456,6 +1460,10 @@ mono_class_init (MonoClass *class)
                 */
                setup_interface_offsets (class, 0);
                mono_loader_unlock ();
+
+               if (mono_debugger_class_init_func)
+                       mono_debugger_class_init_func (class);
+
                return;
        }
 
@@ -1523,7 +1531,6 @@ mono_class_init (MonoClass *class)
                mono_debugger_class_init_func (class);
 }
 
-
 void
 mono_class_setup_mono_type (MonoClass *class)
 {
index 55ce47269f0cbb92760ee5ba177563fabd8008e3..068cb635c37884bcb50fe0e8f5a4b7206f67302d 100644 (file)
@@ -29,6 +29,7 @@ static gboolean mono_debugger_initialized = FALSE;
 static MonoObject *last_exception = NULL;
 
 static gboolean must_reload_symtabs = FALSE;
+static gboolean builtin_types_initialized = FALSE;
 
 static GHashTable *images = NULL;
 static GHashTable *type_table = NULL;
@@ -40,6 +41,8 @@ static MonoDebuggerRangeInfo *allocate_range_entry (MonoDebuggerSymbolFile *symf
 static MonoDebuggerClassInfo *allocate_class_entry (MonoDebuggerSymbolFile *symfile);
 static guint32 allocate_type_entry (MonoDebuggerSymbolTable *table, guint32 size, guint8 **ptr);
 static guint32 write_type (MonoDebuggerSymbolTable *table, MonoType *type);
+static guint32 do_write_class (MonoDebuggerSymbolTable *table, MonoClass *klass,
+                              MonoDebuggerClassInfo *cinfo);
 static guint32 write_class (MonoDebuggerSymbolTable *table, MonoClass *klass);
 
 MonoDebuggerSymbolTable *mono_debugger_symbol_table = NULL;
@@ -122,12 +125,13 @@ allocate_symbol_file_entry (MonoDebuggerSymbolTable *table)
        symfile->index = table->num_symbol_files;
        symfile->range_entry_size = sizeof (MonoDebuggerRangeInfo);
        symfile->class_entry_size = sizeof (MonoDebuggerClassInfo);
+       symfile->class_table_size = sizeof (MonoDebuggerClassTable);
        table->symbol_files [table->num_symbol_files++] = symfile;
        return symfile;
 }
 
 void
-mono_debugger_initialize (MonoDomain *domain)
+mono_debugger_initialize (void)
 {
        MonoDebuggerSymbolTable *symbol_table;
        
@@ -145,8 +149,6 @@ mono_debugger_initialize (MonoDomain *domain)
        symbol_table->version = MONO_DEBUGGER_VERSION;
        symbol_table->total_size = sizeof (MonoDebuggerSymbolTable);
 
-       symbol_table->domain = domain;
-
        images = g_hash_table_new (g_direct_hash, g_direct_equal);
        type_table = g_hash_table_new (g_direct_hash, g_direct_equal);
        misc_table = g_hash_table_new (g_direct_hash, g_direct_equal);
@@ -184,7 +186,8 @@ mono_debugger_add_symbol_file (MonoDebugHandle *handle)
 }
 
 static void
-write_builtin_type (MonoDebuggerSymbolTable *table, MonoClass *klass, MonoDebuggerBuiltinTypeInfo *info)
+write_builtin_type (MonoDebuggerSymbolTable *table, MonoDebuggerSymbolFile *symfile,
+                   MonoClass *klass, MonoDebuggerBuiltinTypeInfo *info)
 {
        guint8 buffer [BUFSIZ], *ptr = buffer;
        guint32 size;
@@ -260,44 +263,48 @@ write_builtin_type (MonoDebuggerSymbolTable *table, MonoClass *klass, MonoDebugg
        }
 
        size = ptr - buffer;
-       info->cinfo->type_info = info->type_info = allocate_type_entry (table, size, &info->type_data);
+       info->type_info = allocate_type_entry (table, size, &info->type_data);
        memcpy (info->type_data, buffer, size);
+
+       info->centry->info = g_new0 (MonoDebuggerClassInfo, 1); //allocate_class_entry (symfile);
+       info->centry->info->klass = klass;
+       if (klass->rank) {
+               info->centry->info->token = klass->element_class->type_token;
+               info->centry->info->rank = klass->rank;
+       } else
+               info->centry->info->token = klass->type_token;
+       info->centry->info->type_info = info->type_info;
 }
 
 static MonoDebuggerBuiltinTypeInfo *
 add_builtin_type (MonoDebuggerSymbolFile *symfile, MonoClass *klass)
 {
-       MonoDebuggerClassInfo *cinfo;
+       MonoDebuggerClassEntry *centry;
        MonoDebuggerBuiltinTypeInfo *info;
 
-       cinfo = g_new0 (MonoDebuggerClassInfo, 1);
-       cinfo->klass = klass;
-       if (klass->rank) {
-               cinfo->token = klass->element_class->type_token;
-               cinfo->rank = klass->rank;
-       } else
-               cinfo->token = klass->type_token;
-
-       g_hash_table_insert (class_info_table, klass, cinfo);
+       centry = g_new0 (MonoDebuggerClassEntry, 1);
 
        info = g_new0 (MonoDebuggerBuiltinTypeInfo, 1);
        info->klass = klass;
-       info->cinfo = cinfo;
+       info->centry = centry;
+
+       g_hash_table_insert (class_info_table, klass, centry);
 
-       write_builtin_type (mono_debugger_symbol_table, klass, info);
+       write_builtin_type (mono_debugger_symbol_table, symfile, klass, info);
        return info;
 }
 
 static void
 add_builtin_type_2 (MonoDebuggerBuiltinTypeInfo *info)
 {
-       info->class_info = write_class (mono_debugger_symbol_table, info->klass);
+       info->class_info = do_write_class (mono_debugger_symbol_table, info->klass, NULL);
        * (guint32 *) (info->type_data + 5) = info->class_info;
 }
 
 static void
 add_exception_class (MonoDebuggerSymbolFile *symfile, MonoException *exc)
 {
+       mono_debugger_start_add_type (symfile, ((MonoObject *) exc)->vtable->klass);
        mono_debugger_add_type (symfile, ((MonoObject *) exc)->vtable->klass);
 }
 
@@ -305,7 +312,7 @@ MonoDebuggerBuiltinTypes *
 mono_debugger_add_builtin_types (MonoDebuggerSymbolFile *symfile)
 {
        MonoDebuggerBuiltinTypes *types = g_new0 (MonoDebuggerBuiltinTypes, 1);
-       MonoException *exc;
+       MonoClass *klass;
 
        mono_debugger_symbol_table->corlib = symfile;
        mono_debugger_symbol_table->builtin_types = types;
@@ -314,6 +321,10 @@ mono_debugger_add_builtin_types (MonoDebuggerSymbolFile *symfile)
        types->type_info_size = sizeof (MonoDebuggerBuiltinTypeInfo);
 
        types->object_type = add_builtin_type (symfile, mono_defaults.object_class);
+       klass = mono_class_from_name (mono_defaults.corlib, "System", "ValueType");
+       g_assert (klass);
+       types->valuetype_type = add_builtin_type (symfile, klass);
+
        types->byte_type = add_builtin_type (symfile, mono_defaults.byte_class);
        types->void_type = add_builtin_type (symfile, mono_defaults.void_class);
        types->boolean_type = add_builtin_type (symfile, mono_defaults.boolean_class);
@@ -331,11 +342,17 @@ mono_debugger_add_builtin_types (MonoDebuggerSymbolFile *symfile)
        types->char_type = add_builtin_type (symfile, mono_defaults.char_class);
        types->string_type = add_builtin_type (symfile, mono_defaults.string_class);
 
+       klass = mono_class_from_name (mono_defaults.corlib, "System", "Type");
+       g_assert (klass);
+       types->type_type = add_builtin_type (symfile, klass);
+
        types->enum_type = add_builtin_type (symfile, mono_defaults.enum_class);
        types->array_type = add_builtin_type (symfile, mono_defaults.array_class);
        types->exception_type = add_builtin_type (symfile, mono_defaults.exception_class);
 
        add_builtin_type_2 (types->object_type);
+       add_builtin_type_2 (types->valuetype_type);
+
        add_builtin_type_2 (types->byte_type);
        add_builtin_type_2 (types->void_type);
        add_builtin_type_2 (types->boolean_type);
@@ -352,6 +369,8 @@ mono_debugger_add_builtin_types (MonoDebuggerSymbolFile *symfile)
        add_builtin_type_2 (types->double_type);
        add_builtin_type_2 (types->char_type);
        add_builtin_type_2 (types->string_type);
+       add_builtin_type_2 (types->type_type);
+
        add_builtin_type_2 (types->enum_type);
        add_builtin_type_2 (types->array_type);
        add_builtin_type_2 (types->exception_type);
@@ -371,36 +390,92 @@ mono_debugger_add_builtin_types (MonoDebuggerSymbolFile *symfile)
        add_exception_class (symfile, mono_get_exception_appdomain_unloaded ());
        add_exception_class (symfile, mono_get_exception_stack_overflow ());
 
+       builtin_types_initialized = TRUE;
+
        return types;
 }
 
+static guint32
+write_class (MonoDebuggerSymbolTable *table, MonoClass *klass)
+{
+       MonoDebuggerClassEntry *centry;
+
+       if (builtin_types_initialized && !klass->init_pending)
+               mono_class_init (klass);
+
+       centry = g_hash_table_lookup (class_info_table, klass);
+       if (!centry) {
+               MonoDebuggerSymbolFile *symfile = _mono_debugger_get_symfile (klass->image);
+
+               g_assert (symfile);
+               mono_debugger_start_add_type (symfile, klass);
+               centry = g_hash_table_lookup (class_info_table, klass);
+       }
+       g_assert (centry);
+
+       if (centry->info) {
+               g_assert (centry->info->type_info);
+               return centry->info->type_info;
+       }
+
+       if (!centry->type_reference) {
+               guint8 *ptr;
+
+               centry->type_reference = allocate_type_entry (table, 5, &ptr);
+
+               *ptr++ = MONO_DEBUGGER_TYPE_KIND_REFERENCE;
+               WRITE_POINTER (ptr, klass);
+       }
+
+       return centry->type_reference;
+}
+
+void
+mono_debugger_start_add_type (MonoDebuggerSymbolFile *symfile, MonoClass *klass)
+{
+       MonoDebuggerClassEntry *centry;
+
+       mono_debugger_lock ();
+       centry = g_hash_table_lookup (class_info_table, klass);
+       if (centry) {
+               mono_debugger_unlock ();
+               return;
+       }
+
+       centry = g_new0 (MonoDebuggerClassEntry, 1);
+       g_hash_table_insert (class_info_table, klass, centry);
+       mono_debugger_unlock ();
+}
+
 void
 mono_debugger_add_type (MonoDebuggerSymbolFile *symfile, MonoClass *klass)
 {
-       MonoDebuggerClassInfo *cinfo;
+       MonoDebuggerClassEntry *centry;
 
        mono_debugger_lock ();
+       centry = g_hash_table_lookup (class_info_table, klass);
+       g_assert (centry);
 
-       cinfo = g_hash_table_lookup (class_info_table, klass);
-       if (cinfo) {
+       if (centry->info) {
                mono_debugger_unlock ();
                return;
        }
 
-       symfile->generation++;
-
-       cinfo = allocate_class_entry (symfile);
-       cinfo->klass = klass;
+       centry->info = allocate_class_entry (symfile);
+       centry->info->klass = klass;
        if (klass->rank) {
-               cinfo->token = klass->element_class->type_token;
-               cinfo->rank = klass->rank;
+               centry->info->token = klass->element_class->type_token;
+               centry->info->rank = klass->rank;
        } else
-               cinfo->token = klass->type_token;
-       g_hash_table_insert (class_info_table, klass, cinfo);
+               centry->info->token = klass->type_token;
 
-       cinfo->type_info = write_class (mono_debugger_symbol_table, klass);
+       do_write_class (mono_debugger_symbol_table, klass, centry->info);
 
+       g_assert (centry->info && centry->info->type_info);
+
+       symfile->generation++;
        must_reload_symtabs = TRUE;
+
        mono_debugger_unlock ();
 }
 
@@ -562,24 +637,38 @@ static MonoDebuggerClassInfo *
 allocate_class_entry (MonoDebuggerSymbolFile *symfile)
 {
        MonoDebuggerClassInfo *retval;
-       guint32 size, chunks;
+       MonoDebuggerClassTable *table;
+       guint32 size;
+
+       if (!symfile->class_table_start) {
+               table = g_new0 (MonoDebuggerClassTable, 1);
+               symfile->class_table_start = symfile->current_class_table = table;
 
-       if (!symfile->class_table) {
                size = sizeof (MonoDebuggerClassInfo) * CLASS_TABLE_CHUNK_SIZE;
-               symfile->class_table = g_malloc0 (size);
-               symfile->num_class_entries = 1;
-               return symfile->class_table;
+               table->data = g_malloc0 (size);
+               table->size = CLASS_TABLE_CHUNK_SIZE;
+               table->index = 1;
+
+               return table->data;
        }
 
-       if (!((symfile->num_class_entries + 1) % CLASS_TABLE_CHUNK_SIZE)) {
-               chunks = (symfile->num_class_entries + 1) / CLASS_TABLE_CHUNK_SIZE;
-               size = sizeof (MonoDebuggerClassInfo) * CLASS_TABLE_CHUNK_SIZE * (chunks + 1);
+       table = symfile->current_class_table;
+       if (table->index >= table->size) {
+               table = g_new0 (MonoDebuggerClassTable, 1);
 
-               symfile->class_table = g_realloc (symfile->class_table, size);
+               symfile->current_class_table->next = table;
+               symfile->current_class_table = table;
+
+               size = sizeof (MonoDebuggerClassInfo) * CLASS_TABLE_CHUNK_SIZE;
+               table->data = g_malloc0 (size);
+               table->size = CLASS_TABLE_CHUNK_SIZE;
+               table->index = 1;
+
+               return table->data;
        }
 
-       retval = symfile->class_table + symfile->num_class_entries;
-       symfile->num_class_entries++;
+       retval = table->data + table->index;
+       table->index++;
        return retval;
 }
 
@@ -602,7 +691,7 @@ allocate_type_entry (MonoDebuggerSymbolTable *table, guint32 size, guint8 **ptr)
                table->current_type_table = g_malloc0 (TYPE_TABLE_CHUNK_SIZE);
                table->type_table_size = TYPE_TABLE_CHUNK_SIZE;
                table->type_table_chunk_size = TYPE_TABLE_CHUNK_SIZE;
-               table->type_table_offset = 1;
+               table->type_table_offset = MONO_DEBUGGER_TYPE_MAX + 1;
        }
 
  again:
@@ -710,7 +799,7 @@ property_is_static (MonoProperty *prop)
 }
 
 static guint32
-write_class (MonoDebuggerSymbolTable *table, MonoClass *klass)
+do_write_class (MonoDebuggerSymbolTable *table, MonoClass *klass, MonoDebuggerClassInfo *cinfo)
 {
        guint8 buffer [BUFSIZ], *ptr = buffer, *old_ptr;
        GPtrArray *methods = NULL, *static_methods = NULL, *ctors = NULL;
@@ -724,6 +813,8 @@ write_class (MonoDebuggerSymbolTable *table, MonoClass *klass)
        GHashTable *method_slots = NULL;
        int i;
 
+       if (klass->init_pending)
+               g_warning (G_STRLOC ": %p - %s.%s", klass, klass->name_space, klass->name);
        g_assert (!klass->init_pending);
        mono_class_init (klass);
 
@@ -733,11 +824,13 @@ write_class (MonoDebuggerSymbolTable *table, MonoClass *klass)
 
        if (klass->enumtype) {
                offset = allocate_type_entry (table, 13, &ptr);
+               if (cinfo)
+                       cinfo->type_info = offset;
                g_hash_table_insert (class_table, klass, GUINT_TO_POINTER (offset));
 
                *ptr++ = MONO_DEBUGGER_TYPE_KIND_ENUM;
                WRITE_UINT32 (ptr, klass->instance_size);
-               WRITE_UINT32 (ptr, table->builtin_types->enum_type->type_info);
+               WRITE_UINT32 (ptr, MONO_DEBUGGER_TYPE_ENUM);
                WRITE_UINT32 (ptr, write_type (table, klass->enum_basetype));
                return offset;
        }
@@ -815,6 +908,9 @@ write_class (MonoDebuggerSymbolTable *table, MonoClass *klass)
        offset = allocate_type_entry (table, data_size, &ptr);
        old_ptr = ptr;
 
+       if (cinfo)
+               cinfo->type_info = offset;
+
        g_hash_table_insert (class_table, klass, GUINT_TO_POINTER (offset));
 
        *ptr++ = MONO_DEBUGGER_TYPE_KIND_CLASS_INFO;
@@ -969,66 +1065,66 @@ write_type (MonoDebuggerSymbolTable *table, MonoType *type)
                return offset;
 
        klass = mono_class_from_mono_type (type);
-       if (klass->init_pending)
-               return 0;
-       mono_class_init (klass);
+       if (type->type == MONO_TYPE_CLASS)
+               return write_class (table, klass);
+
+       // mono_class_init (klass);
 
        switch (type->type) {
        case MONO_TYPE_VOID:
-               return table->builtin_types->void_type->type_info;
+               return MONO_DEBUGGER_TYPE_VOID;
 
        case MONO_TYPE_BOOLEAN:
-               return table->builtin_types->boolean_type->type_info;
+               return MONO_DEBUGGER_TYPE_BOOLEAN;
 
        case MONO_TYPE_I1:
-               return table->builtin_types->sbyte_type->type_info;
+               return MONO_DEBUGGER_TYPE_I1;
 
        case MONO_TYPE_U1:
-               return table->builtin_types->byte_type->type_info;
+               return MONO_DEBUGGER_TYPE_U1;
 
        case MONO_TYPE_CHAR:
-               return table->builtin_types->char_type->type_info;
+               return MONO_DEBUGGER_TYPE_CHAR;
 
        case MONO_TYPE_I2:
-               return table->builtin_types->int16_type->type_info;
+               return MONO_DEBUGGER_TYPE_I2;
 
        case MONO_TYPE_U2:
-               return table->builtin_types->uint16_type->type_info;
+               return MONO_DEBUGGER_TYPE_U2;
 
        case MONO_TYPE_I4:
-               return table->builtin_types->int32_type->type_info;
+               return MONO_DEBUGGER_TYPE_I4;
 
        case MONO_TYPE_U4:
-               return table->builtin_types->uint32_type->type_info;
+               return MONO_DEBUGGER_TYPE_U4;
 
        case MONO_TYPE_I8:
-               return table->builtin_types->int64_type->type_info;
+               return MONO_DEBUGGER_TYPE_I8;
 
        case MONO_TYPE_U8:
-               return table->builtin_types->uint64_type->type_info;
+               return MONO_DEBUGGER_TYPE_U8;
 
        case MONO_TYPE_R4:
-               return table->builtin_types->single_type->type_info;
+               return MONO_DEBUGGER_TYPE_R4;
 
        case MONO_TYPE_R8:
-               return table->builtin_types->double_type->type_info;
+               return MONO_DEBUGGER_TYPE_R8;
 
        case MONO_TYPE_STRING:
-               return table->builtin_types->string_type->type_info;
+               return MONO_DEBUGGER_TYPE_STRING;
 
        case MONO_TYPE_I:
-               return table->builtin_types->int_type->type_info;
+               return MONO_DEBUGGER_TYPE_I;
 
        case MONO_TYPE_U:
-               return table->builtin_types->uint_type->type_info;
+               return MONO_DEBUGGER_TYPE_U;
 
        case MONO_TYPE_SZARRAY: {
                MonoArray array;
 
                *ptr++ = MONO_DEBUGGER_TYPE_KIND_SZARRAY;
                WRITE_UINT32 (ptr, sizeof (MonoArray));
-               g_assert (table->builtin_types->array_type->type_info != 0);
-               WRITE_UINT32 (ptr, table->builtin_types->array_type->type_info);
+               WRITE_UINT32 (ptr, MONO_DEBUGGER_TYPE_ARRAY);
                *ptr++ = (guint8*)&array.max_length - (guint8*)&array;
                *ptr++ = sizeof (array.max_length);
                *ptr++ = (guint8*)&array.vector - (guint8*)&array;
@@ -1042,8 +1138,7 @@ write_type (MonoDebuggerSymbolTable *table, MonoType *type)
 
                *ptr++ = MONO_DEBUGGER_TYPE_KIND_ARRAY;
                WRITE_UINT32 (ptr, sizeof (MonoArray));
-               g_assert (table->builtin_types->array_type->type_info != 0);
-               WRITE_UINT32 (ptr, table->builtin_types->array_type->type_info);
+               WRITE_UINT32 (ptr, MONO_DEBUGGER_TYPE_ARRAY);
                *ptr++ = (guint8*)&array.max_length - (guint8*)&array;
                *ptr++ = sizeof (array.max_length);
                *ptr++ = (guint8*)&array.vector - (guint8*)&array;
index a0db139085317076b1775e0e6a191dc2065b8fca..028b5590d1b59c8d45bea2b7e2472b063f18475a 100644 (file)
@@ -18,7 +18,9 @@ typedef struct _MonoDebuggerSymbolTable               MonoDebuggerSymbolTable;
 typedef struct _MonoDebuggerSymbolFile         MonoDebuggerSymbolFile;
 typedef struct _MonoDebuggerSymbolFilePriv     MonoDebuggerSymbolFilePriv;
 typedef struct _MonoDebuggerRangeInfo          MonoDebuggerRangeInfo;
+typedef struct _MonoDebuggerClassEntry         MonoDebuggerClassEntry;
 typedef struct _MonoDebuggerClassInfo          MonoDebuggerClassInfo;
+typedef struct _MonoDebuggerClassTable         MonoDebuggerClassTable;
 typedef struct _MonoDebuggerIOLayer            MonoDebuggerIOLayer;
 
 typedef enum {
@@ -38,9 +40,33 @@ typedef enum {
        MONO_DEBUGGER_TYPE_KIND_OBJECT,
        MONO_DEBUGGER_TYPE_KIND_STRUCT,
        MONO_DEBUGGER_TYPE_KIND_CLASS,
-       MONO_DEBUGGER_TYPE_KIND_CLASS_INFO
+       MONO_DEBUGGER_TYPE_KIND_CLASS_INFO,
+       MONO_DEBUGGER_TYPE_KIND_REFERENCE
 } MonoDebuggerTypeKind;
 
+typedef enum {
+       MONO_DEBUGGER_TYPE_UNKNOWN      = 0,
+       MONO_DEBUGGER_TYPE_VOID,
+       MONO_DEBUGGER_TYPE_BOOLEAN,
+       MONO_DEBUGGER_TYPE_CHAR,
+       MONO_DEBUGGER_TYPE_I1,
+       MONO_DEBUGGER_TYPE_U1,
+       MONO_DEBUGGER_TYPE_I2,
+       MONO_DEBUGGER_TYPE_U2,
+       MONO_DEBUGGER_TYPE_I4,
+       MONO_DEBUGGER_TYPE_U4,
+       MONO_DEBUGGER_TYPE_I8,
+       MONO_DEBUGGER_TYPE_U8,
+       MONO_DEBUGGER_TYPE_R4,
+       MONO_DEBUGGER_TYPE_R8,
+       MONO_DEBUGGER_TYPE_I,
+       MONO_DEBUGGER_TYPE_U,
+       MONO_DEBUGGER_TYPE_STRING,
+       MONO_DEBUGGER_TYPE_ARRAY,
+       MONO_DEBUGGER_TYPE_ENUM,
+       MONO_DEBUGGER_TYPE_MAX          = 100
+} MonoDebuggerType;
+
 struct _MonoDebuggerBreakpointInfo {
        guint32 index;
        MonoMethodDesc *desc;
@@ -48,8 +74,8 @@ struct _MonoDebuggerBreakpointInfo {
 
 struct _MonoDebuggerBuiltinTypeInfo
 {
+       MonoDebuggerClassEntry *centry;
        MonoClass *klass;
-       MonoDebuggerClassInfo *cinfo;
        guint32 type_info;
        guint32 class_info;
        guint8 *type_data;
@@ -59,6 +85,7 @@ struct _MonoDebuggerBuiltinTypes {
        guint32 total_size;
        guint32 type_info_size;
        MonoDebuggerBuiltinTypeInfo *object_type;
+       MonoDebuggerBuiltinTypeInfo *valuetype_type;
        MonoDebuggerBuiltinTypeInfo *byte_type;
        MonoDebuggerBuiltinTypeInfo *void_type;
        MonoDebuggerBuiltinTypeInfo *boolean_type;
@@ -78,6 +105,7 @@ struct _MonoDebuggerBuiltinTypes {
        MonoDebuggerBuiltinTypeInfo *enum_type;
        MonoDebuggerBuiltinTypeInfo *array_type;
        MonoDebuggerBuiltinTypeInfo *exception_type;
+       MonoDebuggerBuiltinTypeInfo *type_type;
 };
 
 struct _MonoDebuggerSymbolTable {
@@ -88,7 +116,6 @@ struct _MonoDebuggerSymbolTable {
        /*
         * Corlib and builtin types.
         */
-       MonoDomain *domain;
        MonoDebuggerSymbolFile *corlib;
        MonoDebuggerBuiltinTypes *builtin_types;
 
@@ -156,9 +183,10 @@ struct _MonoDebuggerSymbolFile {
        MonoDebuggerRangeInfo *range_table;
        guint32 range_entry_size;
        guint32 num_range_entries;
-       /* Pointer to the malloced class table. */
-       MonoDebuggerClassInfo *class_table;
-       guint32 num_class_entries;
+       /* Pointer to the class table. */
+       guint32 class_table_size;
+       MonoDebuggerClassTable *current_class_table;
+       MonoDebuggerClassTable *class_table_start;
        /* Private. */
        MonoDebuggerSymbolFilePriv *_priv;
 };
@@ -171,6 +199,12 @@ struct _MonoDebuggerRangeInfo {
        guint32 dynamic_size;
 };
 
+struct _MonoDebuggerClassTable {
+       MonoDebuggerClassTable *next;
+       guint32 index, size;
+       MonoDebuggerClassInfo *data;
+};
+
 struct _MonoDebuggerClassInfo {
        MonoClass *klass;
        guint32 rank;
@@ -178,6 +212,11 @@ struct _MonoDebuggerClassInfo {
        guint32 type_info;
 };
 
+struct _MonoDebuggerClassEntry {
+       MonoDebuggerClassInfo *info;
+       guint32 type_reference;
+};
+
 enum {
        MONO_DEBUGGER_MISC_ENTRY_TYPE_UNKNOWN   = 0,
        MONO_DEBUGGER_MISC_ENTRY_TYPE_WRAPPER
@@ -227,15 +266,19 @@ extern MonoDebuggerIOLayer mono_debugger_io_layer;
 
 extern void (*mono_debugger_event_handler) (MonoDebuggerEvent event, gpointer data, guint32 arg);
 
-void            mono_debugger_initialize                  (MonoDomain *domain);
+void            mono_debugger_initialize                  (void);
 void            mono_debugger_cleanup                     (void);
 
 void            mono_debugger_lock                        (void);
 void            mono_debugger_unlock                      (void);
 void            mono_debugger_event                       (MonoDebuggerEvent event, gpointer data, guint32 arg);
 
+MonoDebuggerSymbolFile   *_mono_debugger_get_symfile      (MonoImage *image);
 MonoDebuggerSymbolFile   *mono_debugger_add_symbol_file   (MonoDebugHandle *handle);
-void                      mono_debugger_add_type          (MonoDebuggerSymbolFile *symfile, MonoClass *klass);
+void                      mono_debugger_start_add_type    (MonoDebuggerSymbolFile *symfile,
+                                                          MonoClass *klass);
+void                      mono_debugger_add_type          (MonoDebuggerSymbolFile *symfile,
+                                                          MonoClass *klass);
 MonoDebuggerBuiltinTypes *mono_debugger_add_builtin_types (MonoDebuggerSymbolFile *symfile);
 
 void            mono_debugger_add_method                  (MonoDebuggerSymbolFile *symfile,
index 1eb139cbb83dbba796ff90c8d3215f9c383b26ab..7af2a0307aa5a1346716ada43a2bc9a2e181bdfa 100644 (file)
@@ -32,11 +32,13 @@ static void                 mono_debug_close_image     (MonoDebugHandle *debug);
 static MonoDebugHandle     *_mono_debug_get_image      (MonoImage *image);
 static void                 mono_debug_add_assembly    (MonoAssembly *assembly,
                                                        gpointer user_data);
+static void                 mono_debug_start_add_type  (MonoClass *klass);
 static void                 mono_debug_add_type        (MonoClass *klass);
 static MonoDebugDomainData *mono_debug_get_domain_data (MonoDebugHandle *handle,
                                                        MonoDomain *domain);
 
 extern void (*mono_debugger_class_init_func) (MonoClass *klass);
+extern void (*mono_debugger_start_class_init_func) (MonoClass *klass);
 
 /*
  * Initialize debugging support.
@@ -46,10 +48,8 @@ extern void (*mono_debugger_class_init_func) (MonoClass *klass);
  * callbacks here.
  */
 void
-mono_debug_init (MonoDomain *domain, MonoDebugFormat format)
+mono_debug_init (MonoDebugFormat format)
 {
-       MonoAssembly **ass;
-
        g_assert (!mono_debug_initialized);
 
        mono_debug_initialized = TRUE;
@@ -57,22 +57,25 @@ mono_debug_init (MonoDomain *domain, MonoDebugFormat format)
        in_the_mono_debugger = format == MONO_DEBUG_FORMAT_DEBUGGER;
 
        if (in_the_mono_debugger)
-               mono_debugger_initialize (domain);
+               mono_debugger_initialize ();
 
        mono_debugger_lock ();
 
        mono_debug_handles = g_hash_table_new_full
                (NULL, NULL, NULL, (GDestroyNotify) mono_debug_close_image);
 
+       mono_debugger_start_class_init_func = mono_debug_start_add_type;
        mono_debugger_class_init_func = mono_debug_add_type;
        mono_install_assembly_load_hook (mono_debug_add_assembly, NULL);
+}
+
+void
+mono_debug_init_1 (MonoDomain *domain)
+{
+       MonoDebugHandle *handle = mono_debug_open_image (mono_get_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);
-       */
+       if (in_the_mono_debugger)
+               mono_debugger_add_builtin_types (handle->_priv->debugger_info);
 }
 
 /*
@@ -83,12 +86,7 @@ mono_debug_init (MonoDomain *domain, MonoDebugFormat format)
 void
 mono_debug_init_2 (MonoAssembly *assembly)
 {
-       MonoDebugHandle *handle;
-
        mono_debug_open_image (mono_assembly_get_image (assembly));
-
-       handle = _mono_debug_get_image (mono_get_corlib ());
-       g_assert (handle);
 }
 
 void
@@ -128,11 +126,8 @@ mono_debug_open_image (MonoImage *image)
                return handle;
 
        handle->symfile = mono_debug_open_mono_symbol_file (handle, in_the_mono_debugger);
-       if (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;
 }
@@ -161,6 +156,29 @@ mono_debug_add_assembly (MonoAssembly *assembly, gpointer user_data)
  * This is called via the `mono_debugger_class_init_func' from mono_class_init() each time
  * a new class is initialized.
  */
+MonoDebuggerSymbolFile *
+_mono_debugger_get_symfile (MonoImage *image)
+{
+       MonoDebugHandle *handle = _mono_debug_get_image (image);
+       if (!handle)
+               return NULL;
+
+       return handle->_priv->debugger_info;
+}
+
+static void
+mono_debug_start_add_type (MonoClass *klass)
+{
+       MonoDebugHandle *handle;
+
+       handle = _mono_debug_get_image (klass->image);
+       if (!handle)
+               return;
+
+       if (handle->_priv->debugger_info)
+               mono_debugger_start_add_type (handle->_priv->debugger_info, klass);
+}
+
 static void
 mono_debug_add_type (MonoClass *klass)
 {
@@ -174,6 +192,7 @@ mono_debug_add_type (MonoClass *klass)
                mono_debugger_add_type (handle->_priv->debugger_info, klass);
 }
 
+
 struct LookupMethodData
 {
        MonoDebugMethodInfo *minfo;
index d591f7d7fea35c17fa6e4653391f0a1b43d188ad..70722a168ba0f52074cf3bed328e3b59fdee87ca 100644 (file)
@@ -80,13 +80,14 @@ struct _MonoDebugVarInfo {
        guint32 end_scope;
 };
 
-#define MONO_DEBUGGER_VERSION                          44
+#define MONO_DEBUGGER_VERSION                          45
 #define MONO_DEBUGGER_MAGIC                            0x7aff65af4253d427ULL
 
 extern MonoDebugFormat mono_debug_format;
 extern GHashTable *mono_debug_handles;
 
-void mono_debug_init (MonoDomain *domain, MonoDebugFormat format);
+void mono_debug_init (MonoDebugFormat format);
+void mono_debug_init_1 (MonoDomain *domain);
 void mono_debug_init_2 (MonoAssembly *assembly);
 void mono_debug_cleanup (void);
 void mono_debug_add_wrapper (MonoMethod *method, gpointer wrapper, MonoDomain *domain);
index e58cbfc65839a97eba40a32160bd65226f22182c..68ec46815bf0346c45d8edb62d87f658867b6ad6 100644 (file)
@@ -760,8 +760,10 @@ mono_main (int argc, char* argv[])
                break;
        }
 
-       if (enable_debugging)
-               mono_debug_init (domain, MONO_DEBUG_FORMAT_MONO);
+       if (enable_debugging) {
+               mono_debug_init (MONO_DEBUG_FORMAT_MONO);
+               mono_debug_init_1 (domain);
+       }
 
        /* Parse gac loading options before loading assemblies. */
        if (mono_compile_aot || action == DO_EXEC) {