* culture-info.h: Make defines more consistent, add calendar data
[mono.git] / mono / metadata / mono-debug-debugger.c
index 5f62a4f3b1094e05edd6edbb36d9bff19e66d927..f8f6a8f433941f20a97fea576498c6f37255c092 100644 (file)
 #define TYPE_TABLE_PTR_CHUNK_SIZE      256
 #define TYPE_TABLE_CHUNK_SIZE          65536
 
+static guint32 debugger_lock_level = 0;
 static CRITICAL_SECTION debugger_lock_mutex;
 static gboolean mono_debugger_initialized = FALSE;
 
+static gboolean must_reload_symtabs = FALSE;
+
 static GHashTable *images = NULL;
 static GHashTable *type_table = NULL;
 static GHashTable *class_table = NULL;
@@ -57,15 +60,34 @@ MonoDebuggerIOLayer mono_debugger_io_layer = {
 void
 mono_debugger_lock (void)
 {
-       if (mono_debugger_initialized)
-               EnterCriticalSection (&debugger_lock_mutex);
+       if (!mono_debugger_initialized) {
+               debugger_lock_level++;
+               return;
+       }
+
+       EnterCriticalSection (&debugger_lock_mutex);
+       debugger_lock_level++;
 }
 
 void
 mono_debugger_unlock (void)
 {
-       if (mono_debugger_initialized)
-               LeaveCriticalSection (&debugger_lock_mutex);
+       g_assert (debugger_lock_level > 0);
+
+       if (!mono_debugger_initialized) {
+               debugger_lock_level--;
+               return;
+       }
+
+       if (debugger_lock_level == 1) {
+               if (must_reload_symtabs) {
+                       mono_debugger_event (MONO_DEBUGGER_EVENT_RELOAD_SYMTABS, NULL, 0);
+                       must_reload_symtabs = FALSE;
+               }
+       }
+
+       debugger_lock_level--;
+       LeaveCriticalSection (&debugger_lock_mutex);
 }
 
 static MonoDebuggerSymbolFile *
@@ -98,6 +120,7 @@ mono_debugger_initialize (MonoDomain *domain)
        g_assert (!mono_debugger_initialized);
 
        InitializeCriticalSection (&debugger_lock_mutex);
+       mono_debugger_initialized = TRUE;
 
        mono_debugger_lock ();
 
@@ -114,7 +137,6 @@ mono_debugger_initialize (MonoDomain *domain)
        class_info_table = g_hash_table_new (g_direct_hash, g_direct_equal);
 
        mono_debugger_symbol_table = symbol_table;
-       mono_debugger_initialized = TRUE;
 
        mono_debugger_unlock ();
 }
@@ -128,8 +150,10 @@ mono_debugger_add_symbol_file (MonoDebugHandle *handle)
        mono_debugger_lock ();
 
        info = g_hash_table_lookup (images, handle->image);
-       if (info)
+       if (info) {
+               mono_debugger_unlock ();
                return info;
+       }
 
        info = allocate_symbol_file_entry (mono_debugger_symbol_table);
        info->symfile = handle->symfile;
@@ -337,7 +361,7 @@ mono_debugger_add_type (MonoDebuggerSymbolFile *symfile, MonoClass *klass)
 
        cinfo->type_info = write_class (mono_debugger_symbol_table, klass);
 
-       mono_debugger_event (MONO_DEBUGGER_EVENT_TYPE_ADDED, NULL, 0);
+       must_reload_symtabs = TRUE;
        mono_debugger_unlock ();
 }
 
@@ -467,7 +491,7 @@ mono_debugger_add_method (MonoDebuggerSymbolFile *symfile, MonoDebugMethodInfo *
                }
        }
 
-       mono_debugger_event (MONO_DEBUGGER_EVENT_METHOD_ADDED, NULL, 0);
+       must_reload_symtabs = TRUE;
 }
 
 static MonoDebuggerRangeInfo *
@@ -653,9 +677,12 @@ write_class (MonoDebuggerSymbolTable *table, MonoClass *klass)
 
                if (method->flags & METHOD_ATTRIBUTE_SPECIAL_NAME)
                        continue;
-               if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (method->slot)))
-                       continue;
-               g_hash_table_insert (method_slots, GUINT_TO_POINTER (method->slot), method);
+               
+               if (method->slot != -1) {
+                       if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (method->slot)))
+                               continue;
+                       g_hash_table_insert (method_slots, GUINT_TO_POINTER (method->slot), method);
+               }
 
                if (method->flags & METHOD_ATTRIBUTE_STATIC) {
                        ++num_static_methods;
@@ -1169,8 +1196,11 @@ mono_debugger_lookup_type (const gchar *type_name)
                MonoDebuggerSymbolFile *symfile = mono_debugger_symbol_table->symbol_files [i];
                MonoType *type;
                guint32 offset;
+               gchar *name;
 
-               type = mono_reflection_type_from_name (type_name, symfile->image);
+               name = g_strdup (type_name);
+               type = mono_reflection_type_from_name (name, symfile->image);
+               g_free (name);
                if (!type)
                        continue;
 
@@ -1183,3 +1213,34 @@ mono_debugger_lookup_type (const gchar *type_name)
        mono_debugger_unlock ();
        return 0;
 }
+
+gint32
+mono_debugger_lookup_assembly (const gchar *name)
+{
+       MonoAssembly *assembly;
+       MonoImageOpenStatus status;
+       int i;
+
+       mono_debugger_lock ();
+
+ again:
+       for (i = 0; i < mono_debugger_symbol_table->num_symbol_files; i++) {
+               MonoDebuggerSymbolFile *symfile = mono_debugger_symbol_table->symbol_files [i];
+
+               if (!strcmp (symfile->image_file, name)) {
+                       mono_debugger_unlock ();
+                       return i;
+               }
+       }
+
+       assembly = mono_assembly_open (name, &status);
+
+       if (status != MONO_IMAGE_OK) {
+               g_warning (G_STRLOC ": Cannot open image `%s'", name);
+               mono_debugger_unlock ();
+               return -1;
+       }
+
+       must_reload_symtabs = TRUE;
+       goto again;
+}