Merge pull request #606 from sesef/master
[mono.git] / mono / mini / xdebug.c
index de88855483f5d884c193796a8822711e72b15630..f32deb0cc045cb53f15f7cebcf75ff35c77f685f 100644 (file)
@@ -105,17 +105,16 @@ struct jit_descriptor
 /* GDB puts a breakpoint in this function.  */
 void MONO_NOINLINE __jit_debug_register_code(void);
 
-#if !defined(MONO_LLVM_LOADED) && defined(ENABLE_LLVM) && ((LLVM_MAJOR_VERSION == 2 && LLVM_MINOR_VERSION >= 7) || LLVM_MAJOR_VERSION > 2)
-/* LLVM already defines these */
-extern struct jit_descriptor __jit_debug_descriptor;
-#else
-
 /* Make sure to specify the version statically, because the
    debugger may check the version before we can set it.  */
 struct jit_descriptor __jit_debug_descriptor = { 1, 0, 0, 0 };
 
-void MONO_NOINLINE __jit_debug_register_code(void) { };
+/* gcc seems to inline/eliminate calls to noinline functions, thus the asm () */
+void MONO_NOINLINE __jit_debug_register_code(void) {
+#if defined(__GNUC__)
+       asm ("");
 #endif
+}
 
 static MonoImageWriter *xdebug_w;
 static MonoDwarfWriter *xdebug_writer;
@@ -142,6 +141,11 @@ mono_xdebug_init (char *options)
 
        /* This file will contain the IL code for methods which don't have debug info */
        il_file = fopen ("xdb.il", "w");
+       if (il_file == NULL) {
+               use_gdb_interface = FALSE;
+               g_warning ("** Unable to create xdb.il. Managed symbol names won't be available.");
+               return;
+       }
 
        if (use_gdb_interface)
                return;
@@ -331,7 +335,8 @@ mono_save_trampoline_xdebug_info (MonoTrampInfo *info)
                MonoImageWriter *w;
                MonoDwarfWriter *dw;
 
-               mono_loader_lock ();
+               /* This can be called before the loader lock is initialized */
+               mono_loader_lock_if_inited ();
 
                xdebug_begin_emit (&w, &dw);
 
@@ -339,15 +344,15 @@ mono_save_trampoline_xdebug_info (MonoTrampInfo *info)
 
                xdebug_end_emit (w, dw, NULL);
                
-               mono_loader_unlock ();
+               mono_loader_unlock_if_inited ();
        } else {
                if (!xdebug_writer)
                        return;
 
-               mono_loader_lock ();
+               mono_loader_lock_if_inited ();
                mono_dwarf_writer_emit_trampoline (xdebug_writer, info->name, NULL, NULL, info->code, info->code_size, info->unwind_ops);
                fflush (xdebug_fp);
-               mono_loader_unlock ();
+               mono_loader_unlock_if_inited ();
        }
 }