Tue Aug 31 17:55:15 CEST 2004 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Tue, 31 Aug 2004 14:51:47 +0000 (14:51 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Tue, 31 Aug 2004 14:51:47 +0000 (14:51 -0000)
* mono-debug.c, debug-mono-symfile.c: add some locking love.

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

mono/metadata/ChangeLog
mono/metadata/debug-mono-symfile.c
mono/metadata/mono-debug.c

index bd1355445a3ff4e5eeb7ded46987850233cc0e1e..aefacd3894d8018685bce0e2365a4451ef141207 100644 (file)
@@ -1,3 +1,8 @@
+
+Tue Aug 31 17:55:15 CEST 2004 Paolo Molaro <lupus@ximian.com>
+
+       * mono-debug.c, debug-mono-symfile.c: add some locking love.
+
 2004-08-30  Zoltan Varga  <vargaz@freemail.hu>
 
        * domain-internals.h domain.c: Add a per-domain jump trampoline hash.
index 6beea2fe2098c4d66a83f89d664bd5ce0690f521..e6c3e826459448e17f3df431fa33e234fb40d8e7 100644 (file)
@@ -14,6 +14,7 @@
 #include <mono/metadata/debug-mono-symfile.h>
 #include <mono/metadata/mono-endian.h>
 #include <mono/metadata/metadata-internals.h>
+#include <mono/metadata/mono-debug-debugger.h>
 
 #include <fcntl.h>
 #include <unistd.h>
@@ -96,6 +97,7 @@ mono_debug_open_mono_symbol_file (MonoDebugHandle *handle, gboolean create_symfi
 {
        MonoSymbolFile *symfile;
 
+       mono_debugger_lock ();
        symfile = g_new0 (MonoSymbolFile, 1);
 
        symfile->filename = g_strdup_printf ("%s.mdb", mono_image_get_filename (handle->image));
@@ -104,13 +106,16 @@ mono_debug_open_mono_symbol_file (MonoDebugHandle *handle, gboolean create_symfi
                                  &symfile->raw_contents_size, NULL))
                symfile->raw_contents = NULL;
 
-       if (load_symfile (handle, symfile))
+       if (load_symfile (handle, symfile)) {
+               mono_debugger_unlock ();
                return symfile;
-       else if (!create_symfile) {
+       else if (!create_symfile) {
                mono_debug_close_mono_symbol_file (symfile);
+               mono_debugger_unlock ();
                return NULL;
        }
 
+       mono_debugger_unlock ();
        return symfile;
 }
 
@@ -120,10 +125,12 @@ mono_debug_close_mono_symbol_file (MonoSymbolFile *symfile)
        if (!symfile)
                return;
 
+       mono_debugger_lock ();
        if (symfile->method_hash)
                g_hash_table_destroy (symfile->method_hash);
 
        g_free (symfile);
+       mono_debugger_unlock ();
 }
 
 static int
@@ -163,12 +170,17 @@ mono_debug_find_source_location (MonoSymbolFile *symfile, MonoMethod *method, gu
        const char *ptr;
        int i;
 
-       if (!symfile->method_hash)
+       mono_debugger_lock ();
+       if (!symfile->method_hash) {
+               mono_debugger_unlock ();
                return NULL;
+       }
 
        minfo = g_hash_table_lookup (symfile->method_hash, method);
-       if (!minfo)
+       if (!minfo) {
+               mono_debugger_unlock ();
                return NULL;
+       }
 
        if (read32(&(minfo->entry->_source_index))) {
                int offset = read32(&(symfile->offset_table->_source_table_offset)) +
@@ -188,6 +200,7 @@ mono_debug_find_source_location (MonoSymbolFile *symfile, MonoMethod *method, gu
 
                if (line_number) {
                        *line_number = read32(&(lne->_row));
+                       mono_debugger_unlock ();
                        if (source_file)
                                return source_file;
                        else
@@ -195,11 +208,16 @@ mono_debug_find_source_location (MonoSymbolFile *symfile, MonoMethod *method, gu
                } else if (source_file) {
                        gchar *retval = g_strdup_printf ("%s:%d", source_file, read32(&(lne->_row)));
                        g_free (source_file);
+                       mono_debugger_unlock ();
                        return retval;
-               } else
-                       return g_strdup_printf ("%d", read32(&(lne->_row)));
+               } else {
+                       gchar* retval = g_strdup_printf ("%d", read32(&(lne->_row)));
+                       mono_debugger_unlock ();
+                       return retval;
+               }
        }
 
+       mono_debugger_unlock ();
        return NULL;
 }
 
@@ -245,6 +263,7 @@ mono_debug_find_method (MonoDebugHandle *handle, MonoMethod *method)
        if (handle->image != mono_class_get_image (mono_method_get_class (method)))
                return NULL;
 
+       mono_debugger_lock ();
        first_ie = (MonoSymbolFileMethodIndexEntry *)
                (symfile->raw_contents + read32(&(symfile->offset_table->_method_table_offset)));
 
@@ -252,8 +271,10 @@ mono_debug_find_method (MonoDebugHandle *handle, MonoMethod *method)
                                   read32(&(symfile->offset_table->_method_count)),
                                   sizeof (MonoSymbolFileMethodIndexEntry), compare_method);
 
-       if (!ie)
+       if (!ie) {
+               mono_debugger_unlock ();
                return NULL;
+       }
 
        me = (MonoSymbolFileMethodEntry *) (symfile->raw_contents + read32(&(ie->_file_offset)));
 
@@ -268,5 +289,6 @@ mono_debug_find_method (MonoDebugHandle *handle, MonoMethod *method)
 
        g_hash_table_insert (symfile->method_hash, method, minfo);
 
+       mono_debugger_unlock ();
        return minfo;
 }
index 1009dc56b8d2c840cec54f02643bf7a3c5b8bdf1..5e24015f28853a7778fc53012134b35ffbe87456 100644 (file)
@@ -67,6 +67,7 @@ mono_debug_init (MonoDebugFormat format)
        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_debugger_unlock ();
 }
 
 void
@@ -350,26 +351,35 @@ gchar *
 mono_debug_source_location_from_address (MonoMethod *method, guint32 address, guint32 *line_number,
                                         MonoDomain *domain)
 {
-       MonoDebugMethodInfo *minfo = _mono_debug_lookup_method (method);
+       char *res;
+       MonoDebugMethodInfo *minfo;
        MonoDebugDomainData *domain_data;
 
+       mono_debugger_lock ();
+       minfo = _mono_debug_lookup_method (method);
        if (!minfo || !minfo->handle || !minfo->handle->symfile ||
-           !minfo->handle->symfile->offset_table)
+           !minfo->handle->symfile->offset_table) {
+               mono_debugger_unlock ();
                return NULL;
+       }
 
        domain_data = mono_debug_get_domain_data (minfo->handle, domain);
-       if (!domain_data->jit [minfo->index])
+       if (!domain_data->jit [minfo->index]) {
+               mono_debugger_unlock ();
                return NULL;
+       }
 
        if (minfo->handle && minfo->handle->symfile) {
                gint32 offset = il_offset_from_address (domain_data->jit [minfo->index], address);
+               char *res = NULL;
                
-               if (offset < 0)
-                       return NULL;
-
-               return mono_debug_find_source_location (minfo->handle->symfile, method, offset, line_number);
+               if (offset >= 0)
+                       res = mono_debug_find_source_location (minfo->handle->symfile, method, offset, line_number);
+               mono_debugger_unlock ();
+               return res;
        }
 
+       mono_debugger_unlock ();
        return NULL;
 }
 
@@ -386,12 +396,19 @@ mono_debug_source_location_from_address (MonoMethod *method, guint32 address, gu
 gchar *
 mono_debug_source_location_from_il_offset (MonoMethod *method, guint32 offset, guint32 *line_number)
 {
-       MonoDebugMethodInfo *minfo = _mono_debug_lookup_method (method);
+       char *res;
+       MonoDebugMethodInfo *minfo;
 
-       if (!minfo || !minfo->handle || !minfo->handle->symfile)
+       mono_debugger_lock ();
+       minfo = _mono_debug_lookup_method (method);
+       if (!minfo || !minfo->handle || !minfo->handle->symfile) {
+               mono_debugger_unlock ();
                return NULL;
+       }
 
-       return mono_debug_find_source_location (minfo->handle->symfile, method, offset, line_number);
+       res = mono_debug_find_source_location (minfo->handle->symfile, method, offset, line_number);
+       mono_debugger_unlock ();
+       return res;
 }
 
 /*
@@ -403,18 +420,24 @@ mono_debug_il_offset_from_address (MonoMethod *method, gint32 address, MonoDomai
 {
        MonoDebugMethodInfo *minfo;
        MonoDebugDomainData *domain_data;
+       gint32 res;
 
        if (address < 0)
                return -1;
 
+       mono_debugger_lock ();
        minfo = _mono_debug_lookup_method (method);
        if (!minfo || !minfo->il_offsets || !minfo->handle || !minfo->handle->symfile ||
-           !minfo->handle->symfile->offset_table)
+           !minfo->handle->symfile->offset_table) {
+               mono_debugger_unlock ();
                return -1;
+       }
 
        domain_data = mono_debug_get_domain_data (minfo->handle, domain);
 
-       return il_offset_from_address (domain_data->jit [minfo->index], address);
+       res = il_offset_from_address (domain_data->jit [minfo->index], address);
+       mono_debugger_unlock ();
+       return res;
 }
 
 /*
@@ -426,18 +449,24 @@ mono_debug_address_from_il_offset (MonoMethod *method, gint32 il_offset, MonoDom
 {
        MonoDebugMethodInfo *minfo;
        MonoDebugDomainData *domain_data;
+       gint32 res;
 
        if (il_offset < 0)
                return -1;
 
+       mono_debugger_lock ();
        minfo = _mono_debug_lookup_method (method);
        if (!minfo || !minfo->il_offsets || !minfo->handle || !minfo->handle->symfile ||
-           !minfo->handle->symfile->offset_table)
+           !minfo->handle->symfile->offset_table) {
+               mono_debugger_unlock ();
                return -1;
+       }
 
        domain_data = mono_debug_get_domain_data (minfo->handle, domain);
 
-       return _mono_debug_address_from_il_offset (domain_data->jit [minfo->index], il_offset);
+       res = _mono_debug_address_from_il_offset (domain_data->jit [minfo->index], il_offset);
+       mono_debugger_unlock ();
+       return res;
 }
 
 static MonoDebugDomainData *