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)
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;
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);
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 ();
int file_offset;
int virt_offset;
int shidx;
+ guint64 addr;
+ gboolean has_addr;
};
static void
}
}
+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)
{
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;
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)
{