2004-12-03 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / metadata / mono-debug.c
index b977ec0546d5ec4381384e634cb77382f2050f3a..717fb997e141e49f22d313776ea49f3ed9f34b87 100644 (file)
@@ -26,14 +26,19 @@ static gboolean in_the_mono_debugger = FALSE;
 static gboolean mono_debug_initialized = FALSE;
 GHashTable *mono_debug_handles = NULL;
 
-static MonoDebugHandle *mono_debug_open_image    (MonoImage *image);
-static void             mono_debug_close_image   (MonoDebugHandle *debug);
+static MonoDebugHandle     *mono_debug_open_image      (MonoImage *image);
+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_add_type      (MonoClass *klass);
+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.
@@ -43,7 +48,7 @@ extern void (*mono_debugger_class_init_func) (MonoClass *klass);
  * callbacks here.
  */
 void
-mono_debug_init (MonoDomain *domain, MonoDebugFormat format)
+mono_debug_init (MonoDebugFormat format)
 {
        g_assert (!mono_debug_initialized);
 
@@ -52,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);
+}
 
-       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);
-       */
+void
+mono_debug_init_1 (MonoDomain *domain)
+{
+       MonoDebugHandle *handle = mono_debug_open_image (mono_get_corlib ());
+
+       if (in_the_mono_debugger)
+               mono_debugger_add_builtin_types (handle->_priv->debugger_info);
 }
 
 /*
@@ -78,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
@@ -123,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;
 }
@@ -156,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)
 {
@@ -169,6 +192,7 @@ mono_debug_add_type (MonoClass *klass)
                mono_debugger_add_type (handle->_priv->debugger_info, klass);
 }
 
+
 struct LookupMethodData
 {
        MonoDebugMethodInfo *minfo;
@@ -208,46 +232,28 @@ _mono_debug_lookup_method (MonoMethod *method)
  * wrapper method.
  */
 void
-mono_debug_add_wrapper (MonoMethod *method, MonoMethod *wrapper_method, MonoDomain *domain)
+mono_debug_add_wrapper (MonoMethod *method, gpointer wrapper, MonoDomain *domain)
 {
-       MonoClass *klass = mono_method_get_class (method);
+       MonoClass *klass = method->klass;
+       MonoDebugDomainData *domain_data;
        MonoDebugHandle *handle;
-       MonoDebugMethodInfo *minfo;
        MonoDebugMethodJitInfo *jit;
-       MonoDebugDomainData *domain_data;
-       guint32 iflags;
 
-       mono_method_get_flags (method, &iflags);
-       if (!(iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
-               return;
+       mono_debugger_lock ();
 
        mono_class_init (klass);
 
        handle = _mono_debug_get_image (klass->image);
-       g_assert (handle);
-
-       minfo = _mono_debug_lookup_method (method);
-       if (!minfo)
-               return;
-
-       domain_data = mono_debug_get_domain_data (handle, domain);
-       if (domain_data->jit [minfo->index]) {
-               /* FIXME FIXME FIXME
-               // This is bug #48591.
-               */
+       if (!handle || !handle->symfile || !handle->symfile->offset_table) {
+               mono_debugger_unlock ();
                return;
        }
 
-       jit = g_hash_table_lookup (domain_data->_priv->wrapper_info, wrapper_method);
+       domain_data = mono_debug_get_domain_data (handle, domain);
+       jit = g_hash_table_lookup (domain_data->_priv->wrapper_info, method);
        g_assert (jit);
 
-       mono_debugger_lock ();
-
-       domain_data->jit [minfo->index] = jit;
-       jit->wrapper_addr = method->addr;
-
-       if (handle->_priv->debugger_info && (domain == mono_get_root_domain ()))
-               mono_debugger_add_method (handle->_priv->debugger_info, minfo, jit);
+       mono_debugger_add_wrapper (method, jit, wrapper);
 
        mono_debugger_unlock ();
 }
@@ -277,7 +283,14 @@ mono_debug_add_method (MonoMethod *method, MonoDebugMethodJitInfo *jit, MonoDoma
        }
 
        handle = _mono_debug_get_image (klass->image);
-       if (!handle) {
+       if (!handle || !handle->symfile || !handle->symfile->offset_table) {
+               mono_debugger_unlock ();
+               return;
+       }
+
+       domain_data = mono_debug_get_domain_data (handle, domain);
+       if (method->wrapper_type != MONO_WRAPPER_NONE) {
+               g_hash_table_insert (domain_data->_priv->wrapper_info, method, jit);
                mono_debugger_unlock ();
                return;
        }
@@ -288,7 +301,6 @@ mono_debug_add_method (MonoMethod *method, MonoDebugMethodJitInfo *jit, MonoDoma
                return;
        }
 
-       domain_data = mono_debug_get_domain_data (handle, domain);
        if (domain_data->jit [minfo->index]) {
                /* FIXME FIXME FIXME
                // This is bug #48591.
@@ -297,12 +309,6 @@ mono_debug_add_method (MonoMethod *method, MonoDebugMethodJitInfo *jit, MonoDoma
                return;
        }
 
-       if (method->wrapper_type != MONO_WRAPPER_NONE) {
-               g_hash_table_insert (domain_data->_priv->wrapper_info, method, jit);
-               mono_debugger_unlock ();
-               return;
-       }
-
        domain_data->jit [minfo->index] = jit;
 
        if (handle->_priv->debugger_info && (domain == mono_get_root_domain ()))
@@ -330,10 +336,16 @@ il_offset_from_address (MonoDebugMethodJitInfo *jit, guint32 address)
        return -1;
 }
 
-/*
+/**
+ * mono_debug_source_location_from_address:
+ * @method:
+ * @address:
+ * @line_number:
+ * @domain:
+ *
  * Used by the exception code to get a source location from a machine address.
  *
- * Returns a textual representation of the specified address which is suitable to be displayed to
+ * Returns: a textual representation of the specified address which is suitable to be displayed to
  * the user (for instance "/home/martin/monocvs/debugger/test/Y.cs:8").
  *
  * If the optional @line_number argument is not NULL, the line number is stored there and just the
@@ -344,7 +356,6 @@ gchar *
 mono_debug_source_location_from_address (MonoMethod *method, guint32 address, guint32 *line_number,
                                         MonoDomain *domain)
 {
-       char *res;
        MonoDebugMethodInfo *minfo;
        MonoDebugDomainData *domain_data;
 
@@ -376,7 +387,12 @@ mono_debug_source_location_from_address (MonoMethod *method, guint32 address, gu
        return NULL;
 }
 
-/*
+/**
+ * mono_debug_source_location_from_il_offset:
+ * @method:
+ * @offset:
+ * @line_number:
+ *
  * Used by the exception code to get a source location from an IL offset.
  *
  * Returns a textual representation of the specified address which is suitable to be displayed to
@@ -404,8 +420,13 @@ mono_debug_source_location_from_il_offset (MonoMethod *method, guint32 offset, g
        return res;
 }
 
-/*
- * Returns the IL offset corresponding to machine address @address which is an offset
+/**
+ * mono_debug_il_offset_from_address:
+ * @method:
+ * @address:
+ * @domain:
+ *
+ * Returns: the IL offset corresponding to machine address @address which is an offset
  * relative to the beginning of the method @method.
  */
 gint32
@@ -433,8 +454,13 @@ mono_debug_il_offset_from_address (MonoMethod *method, gint32 address, MonoDomai
        return res;
 }
 
-/*
- * Returns the machine address corresponding to IL offset @il_offset.
+/**
+ * mono_debug_address_from_il_offset:
+ * @method:
+ * @il_offset:
+ * @domain:
+ *
+ * Returns: the machine address corresponding to IL offset @il_offset.
  * The returned value is an offset relative to the beginning of the method @method.
  */
 gint32
@@ -462,7 +488,7 @@ mono_debug_address_from_il_offset (MonoMethod *method, gint32 il_offset, MonoDom
        return res;
 }
 
-MonoDebugDomainData *
+static MonoDebugDomainData *
 mono_debug_get_domain_data (MonoDebugHandle *handle, MonoDomain *domain)
 {
        MonoDebugDomainData *data;