X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fxdebug.c;h=136c214c311d66bb63bf8133afde0f00130c3a5e;hb=9342e7d1d4e5d0d3248de33d05b2c2b993314bd6;hp=6f212f80bd4852735c72591e48c53a4d0536029c;hpb=4bd1f7ba7252579e97d480e3008b3a3f9fc52817;p=mono.git diff --git a/mono/mini/xdebug.c b/mono/mini/xdebug.c index 6f212f80bd4..136c214c311 100644 --- a/mono/mini/xdebug.c +++ b/mono/mini/xdebug.c @@ -75,10 +75,14 @@ typedef enum struct jit_code_entry { - struct jit_code_entry *next_entry; - struct jit_code_entry *prev_entry; - const char *symfile_addr; - guint64 symfile_size; + struct jit_code_entry *next_entry; + struct jit_code_entry *prev_entry; + const char *symfile_addr; + /* + * The gdb code in gdb/jit.c which reads this structure ignores alignment + * requirements, so use two 32 bit fields. + */ + guint32 symfile_size1, symfile_size2; }; struct jit_descriptor @@ -101,16 +105,24 @@ 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) && ((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 +} + #endif static MonoImageWriter *xdebug_w; @@ -138,6 +150,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; @@ -155,7 +172,7 @@ mono_xdebug_init (char *options) img_writer_emit_section_change (w, ".text", 0); img_writer_emit_string (w, ""); - mono_dwarf_writer_emit_base_info (xdebug_writer, mono_arch_get_cie_program ()); + mono_dwarf_writer_emit_base_info (xdebug_writer, mono_unwind_get_cie_program ()); } static void @@ -174,7 +191,7 @@ xdebug_begin_emit (MonoImageWriter **out_w, MonoDwarfWriter **out_dw) dw = mono_dwarf_writer_create (w, il_file, il_file_line_index, FALSE); - mono_dwarf_writer_emit_base_info (dw, mono_arch_get_cie_program ()); + mono_dwarf_writer_emit_base_info (dw, mono_unwind_get_cie_program ()); *out_w = w; *out_dw = dw; @@ -186,6 +203,7 @@ xdebug_end_emit (MonoImageWriter *w, MonoDwarfWriter *dw, MonoMethod *method) guint8 *img; guint32 img_size; struct jit_code_entry *entry; + guint64 *psize; il_file_line_index = mono_dwarf_writer_get_il_file_line_index (dw); mono_dwarf_writer_close (dw); @@ -204,7 +222,7 @@ xdebug_end_emit (MonoImageWriter *w, MonoDwarfWriter *dw, MonoMethod *method) file_counter ++; file_name = g_strdup_printf ("xdb-%d.o", file_counter); - //printf ("%s -> %s\n", mono_method_full_name (method, TRUE), file_name); + printf ("%s %p %d\n", file_name, img, img_size); fp = fopen (file_name, "w"); fwrite (img, img_size, 1, fp); @@ -214,10 +232,11 @@ xdebug_end_emit (MonoImageWriter *w, MonoDwarfWriter *dw, MonoMethod *method) /* Register the image with GDB */ - entry = g_malloc (sizeof (struct jit_code_entry)); + entry = g_malloc0 (sizeof (struct jit_code_entry)); entry->symfile_addr = (const char*)img; - entry->symfile_size = img_size; + psize = (guint64*)&entry->symfile_size1; + *psize = img_size; entry->next_entry = __jit_debug_descriptor.first_entry; if (__jit_debug_descriptor.first_entry) @@ -257,6 +276,8 @@ static int xdebug_method_count; void mono_save_xdebug_info (MonoCompile *cfg) { + MonoDebugMethodJitInfo *dmji; + if (use_gdb_interface) { mono_loader_lock (); @@ -272,7 +293,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 (cfg->jit_info->method, mono_domain_get ());; + 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, dmji); + mono_debug_free_method_jit_info (dmji); #if 0 /* @@ -299,10 +322,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 (cfg->jit_info->method, mono_domain_get ());; + 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, dmji); + mono_debug_free_method_jit_info (dmji); fflush (xdebug_fp); mono_loader_unlock (); } + } /* @@ -312,29 +338,30 @@ 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 (); } } @@ -351,7 +378,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) { }