2009-10-11 Zoltan Varga <vargaz@gmail.com>
authorZoltan Varga <vargaz@gmail.com>
Sun, 11 Oct 2009 02:06:11 +0000 (02:06 -0000)
committerZoltan Varga <vargaz@gmail.com>
Sun, 11 Oct 2009 02:06:11 +0000 (02:06 -0000)
* aot-compiler.c (mono_save_xdebug_info): Emit a symbol for the method which
can be used to set breakpoints in gdb.

* image-writer.c (bin_writer_emit_writeout): Add support for setting the text
segment to an absolute address.

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

mono/mini/ChangeLog
mono/mini/aot-compiler.c
mono/mini/image-writer.c
mono/mini/image-writer.h

index 28ae92ec2345462d211c2a0625256cbb9b1362e5..c2994c17aae0168e9c5bb1ae301f4a8a74e8a069 100644 (file)
@@ -1,3 +1,11 @@
+2009-10-11  Zoltan Varga  <vargaz@gmail.com>
+
+       * aot-compiler.c (mono_save_xdebug_info): Emit a symbol for the method which
+       can be used to set breakpoints in gdb.
+
+       * image-writer.c (bin_writer_emit_writeout): Add support for setting the text
+       segment to an absolute address.
+
 2009-10-10  Zoltan Varga  <vargaz@gmail.com>
 
        * aot-compiler.c (mono_save_trampoline_xdebug_info): Implement this for the
index 1a22a9f01cc49788ce17713933cd988dc0a01334..31793c4804e09d6f7e4c15b22637fbfc7df549fb 100644 (file)
@@ -5585,6 +5585,7 @@ static MonoDwarfWriter *xdebug_writer;
 static FILE *xdebug_fp, *il_file;
 static gboolean use_gdb_interface, save_symfiles;
 static int il_file_line_index;
+static GHashTable *xdebug_syms;
 
 void
 mono_xdebug_init (char *options)
@@ -5640,10 +5641,6 @@ xdebug_begin_emit (MonoImageWriter **out_w, MonoDwarfWriter **out_dw)
 
        dw = mono_dwarf_writer_create (w, il_file, il_file_line_index, FALSE);
 
-       /* 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 (dw, arch_get_cie_program ());
 
        *out_w = w;
@@ -5674,7 +5671,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 -> %s\n", mono_method_full_name (method, TRUE), file_name);
 
                fp = fopen (file_name, "w");
                fwrite (img, img_size, 1, fp);
@@ -5713,13 +5710,30 @@ mono_save_xdebug_info (MonoCompile *cfg)
        if (use_gdb_interface) {
                MonoImageWriter *w;
                MonoDwarfWriter *dw;
+               char *sym;
 
                mono_loader_lock ();
 
+               if (!xdebug_syms)
+                       xdebug_syms = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
                xdebug_begin_emit (&w, &dw);
 
                mono_dwarf_writer_emit_method (dw, 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 ()));
 
+               /* 
+                * Emit a symbol for the code by emitting it at the beginning of the text 
+                * segment, and setting the text segment to have an absolute address.
+                * This symbol can be used to set breakpoints in gdb.
+                */
+               sym = get_debug_sym (cfg->jit_info->method, "", xdebug_syms);
+               img_writer_emit_section_change (w, ".text", 0);
+               img_writer_set_section_addr (w, (gssize)cfg->jit_info->code_start);
+               img_writer_emit_global (w, sym, TRUE);
+               img_writer_emit_label (w, sym);
+               img_writer_emit_bytes (w, cfg->jit_info->code_start, cfg->jit_info->code_size);
+               g_free (sym);
+
                xdebug_end_emit (w, dw, cfg->jit_info->method);
                
                mono_loader_unlock ();
index 5b294676e6a997fce7107f5bd0d0bcb0fe206498..cd570b9c17d72aed83f1c74d99a3fffcd8a5d51c 100644 (file)
@@ -213,6 +213,8 @@ struct _BinSection {
        int file_offset;
        int virt_offset;
        int shidx;
+       guint64 addr;
+       gboolean has_addr;
 };
 
 static void
@@ -245,6 +247,13 @@ bin_writer_emit_section_change (MonoImageWriter *acfg, const char *section_name,
        }
 }
 
+static void
+bin_writer_set_section_addr (MonoImageWriter *acfg, guint64 addr)
+{
+       acfg->cur_section->addr = addr;
+       acfg->cur_section->has_addr = TRUE;
+}
+
 static void
 bin_writer_emit_symbol_inner (MonoImageWriter *acfg, const char *name, const char *end_label, gboolean is_global, gboolean func)
 {
@@ -1129,6 +1138,10 @@ bin_writer_emit_writeout (MonoImageWriter *acfg)
        virt_offset = file_offset;
        secth [SECT_TEXT].sh_addr = secth [SECT_TEXT].sh_offset = file_offset;
        if (sections [SECT_TEXT]) {
+               if (sections [SECT_TEXT]->has_addr) {
+                       secth [SECT_TEXT].sh_addr = sections [SECT_TEXT]->addr;
+                       secth [SECT_TEXT].sh_flags &= ~SHF_ALLOC;
+               }
                size = sections [SECT_TEXT]->cur_offset;
                secth [SECT_TEXT].sh_size = size;
                file_offset += size;
@@ -1751,6 +1764,19 @@ img_writer_emit_pop_section (MonoImageWriter *acfg)
        img_writer_emit_section_change (acfg, acfg->section_stack [acfg->stack_pos], acfg->subsection_stack [acfg->stack_pos]);
 }
 
+void
+img_writer_set_section_addr (MonoImageWriter *acfg, guint64 addr)
+{
+#ifdef USE_BIN_WRITER
+       if (!acfg->use_bin_writer)
+               NOT_IMPLEMENTED;
+       else
+               bin_writer_set_section_addr (acfg, addr);
+#else
+       NOT_IMPLEMENTED;
+#endif
+}
+
 void
 img_writer_emit_global (MonoImageWriter *acfg, const char *name, gboolean func)
 {
index 1b12ac4c2d60abaeb7ab0975c7cb58a0a9a605d4..6ad0067157464d1045964213d6631a402aebf2fa 100644 (file)
@@ -44,6 +44,8 @@ void img_writer_emit_push_section (MonoImageWriter *w, const char *section_name,
 
 void img_writer_emit_pop_section (MonoImageWriter *w) MONO_INTERNAL;
 
+void img_writer_set_section_addr (MonoImageWriter *acfg, guint64 addr) MONO_INTERNAL;
+
 void img_writer_emit_global (MonoImageWriter *w, const char *name, gboolean func) MONO_INTERNAL;
 
 void img_writer_emit_local_symbol (MonoImageWriter *w, const char *name, const char *end_label, gboolean func) MONO_INTERNAL;