Merge branch 'master' into msbuilddll2
[mono.git] / mono / mini / xdebug.c
index 08d701c247e90aaa240ab5f0708d846c5052f74b..9e415ca339092ac0da6eb5ae8a14828f46e08217 100644 (file)
@@ -105,16 +105,25 @@ struct jit_descriptor
 /* GDB puts a breakpoint in this function.  */
 void MONO_NOINLINE __jit_debug_register_code(void);
 
-#if defined(ENABLE_LLVM) && ((LLVM_MAJOR_VERSION == 2 && LLVM_MINOR_VERSION >= 7) || LLVM_MAJOR_VERSION > 2)
+#if !defined(MONO_LLVM_LOADED) && defined(ENABLE_LLVM) && !defined(MONO_CROSS_COMPILE)
+
 /* LLVM already defines these */
+
 extern struct jit_descriptor __jit_debug_descriptor;
+
 #else
 
+/* 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
+}
+
 /* 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) { };
 #endif
 
 static MonoImageWriter *xdebug_w;
@@ -125,7 +134,7 @@ static int il_file_line_index;
 static GHashTable *xdebug_syms;
 
 void
-mono_xdebug_init (char *options)
+mono_xdebug_init (const char *options)
 {
        MonoImageWriter *w;
        char **args, **ptr;
@@ -142,6 +151,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;
@@ -153,13 +167,13 @@ mono_xdebug_init (char *options)
 
        img_writer_emit_start (w);
 
-       xdebug_writer = mono_dwarf_writer_create (w, il_file, 0, TRUE);
+       xdebug_writer = mono_dwarf_writer_create (w, il_file, 0, TRUE, TRUE);
 
        /* Emit something so the file has a text segment */
        img_writer_emit_section_change (w, ".text", 0);
        img_writer_emit_string (w, "");
 
-       mono_dwarf_writer_emit_base_info (xdebug_writer, mono_unwind_get_cie_program ());
+       mono_dwarf_writer_emit_base_info (xdebug_writer, "JITted code", mono_unwind_get_cie_program ());
 }
 
 static void
@@ -176,9 +190,9 @@ xdebug_begin_emit (MonoImageWriter **out_w, MonoDwarfWriter **out_dw)
        if (!il_file)
                il_file = fopen ("xdb.il", "w");
 
-       dw = mono_dwarf_writer_create (w, il_file, il_file_line_index, FALSE);
+       dw = mono_dwarf_writer_create (w, il_file, il_file_line_index, FALSE, TRUE);
 
-       mono_dwarf_writer_emit_base_info (dw, mono_unwind_get_cie_program ());
+       mono_dwarf_writer_emit_base_info (dw, "JITted code", mono_unwind_get_cie_program ());
 
        *out_w = w;
        *out_dw = dw;
@@ -263,6 +277,8 @@ static int xdebug_method_count;
 void
 mono_save_xdebug_info (MonoCompile *cfg)
 {
+       MonoDebugMethodJitInfo *dmji;
+
        if (use_gdb_interface) {
                mono_loader_lock ();
 
@@ -278,7 +294,9 @@ mono_save_xdebug_info (MonoCompile *cfg)
 
                xdebug_method_count ++;
 
-               mono_dwarf_writer_emit_method (xdebug_writer, cfg, cfg->jit_info->method, NULL, NULL, cfg->jit_info->code_start, cfg->jit_info->code_size, cfg->args, cfg->locals, cfg->unwind_ops, mono_debug_find_method (cfg->jit_info->method, mono_domain_get ()));
+               dmji = mono_debug_find_method (jinfo_get_method (cfg->jit_info), mono_domain_get ());;
+               mono_dwarf_writer_emit_method (xdebug_writer, cfg, jinfo_get_method (cfg->jit_info), NULL, NULL, cfg->jit_info->code_start, cfg->jit_info->code_size, cfg->args, cfg->locals, cfg->unwind_ops, dmji);
+               mono_debug_free_method_jit_info (dmji);
 
 #if 0
                /* 
@@ -305,10 +323,13 @@ mono_save_xdebug_info (MonoCompile *cfg)
                        return;
 
                mono_loader_lock ();
-               mono_dwarf_writer_emit_method (xdebug_writer, cfg, cfg->jit_info->method, NULL, NULL, cfg->jit_info->code_start, cfg->jit_info->code_size, cfg->args, cfg->locals, cfg->unwind_ops, mono_debug_find_method (cfg->jit_info->method, mono_domain_get ()));
+               dmji = mono_debug_find_method (jinfo_get_method (cfg->jit_info), mono_domain_get ());
+               mono_dwarf_writer_emit_method (xdebug_writer, cfg, jinfo_get_method (cfg->jit_info), NULL, NULL, cfg->jit_info->code_start, cfg->jit_info->code_size, cfg->args, cfg->locals, cfg->unwind_ops, dmji);
+               mono_debug_free_method_jit_info (dmji);
                fflush (xdebug_fp);
                mono_loader_unlock ();
        }
+
 }
 
 /*
@@ -318,36 +339,37 @@ mono_save_xdebug_info (MonoCompile *cfg)
  * LOCKING: Acquires the loader lock.
  */
 void
-mono_save_trampoline_xdebug_info (const char *tramp_name, guint8 *code, guint32 code_size, GSList *unwind_info)
+mono_save_trampoline_xdebug_info (MonoTrampInfo *info)
 {
        if (use_gdb_interface) {
                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);
 
-               mono_dwarf_writer_emit_trampoline (dw, tramp_name, NULL, NULL, code, code_size, unwind_info);
+               mono_dwarf_writer_emit_trampoline (dw, info->name, NULL, NULL, info->code, info->code_size, info->unwind_ops);
 
                xdebug_end_emit (w, dw, NULL);
                
-               mono_loader_unlock ();
+               mono_loader_unlock_if_inited ();
        } else {
                if (!xdebug_writer)
                        return;
 
-               mono_loader_lock ();
-               mono_dwarf_writer_emit_trampoline (xdebug_writer, tramp_name, NULL, NULL, code, code_size, unwind_info);
+               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 ();
        }
 }
 
 #else /* !defined(DISABLE_AOT) && !defined(DISABLE_JIT) */
 
 void
-mono_xdebug_init (char *options)
+mono_xdebug_init (const char *options)
 {
 }
 
@@ -357,7 +379,7 @@ mono_save_xdebug_info (MonoCompile *cfg)
 }
 
 void
-mono_save_trampoline_xdebug_info (const char *tramp_name, guint8 *code, guint32 code_size, GSList *unwind_info)
+mono_save_trampoline_xdebug_info (MonoTrampInfo *info)
 {
 }