#include <mono/metadata/appdomain.h>
#include <mono/metadata/tabledefs.h>
#include <mono/arch/x86/x86-codegen.h>
+#include <mono/metadata/mono-debug-debugger.h>
#include "jit.h"
#include "codegen.h"
-#include "debug.h"
/*
* Address of the x86 trampoline code. This is used by the debugger to check
*/
guint8 *mono_generic_trampoline_code = NULL;
-/*
- * Address of a special breakpoint trampoline code for the debugger.
- */
-guint8 *mono_breakpoint_trampoline_code = NULL;
-
/*
* get_unbox_trampoline:
* @m: method pointer
return start;
}
-/*
- * get_breakpoint_trampoline:
- * @m: method pointer
- * @addr: pointer to native code for @m
- *
- * creates a special trampoline for the debugger which is used to get
- * a breakpoint after compiling a method.
- */
-static gpointer
-get_breakpoint_trampoline (MonoMethod *m, guint32 breakpoint_id, gpointer addr)
-{
- guint8 *code, *start, *buf;
-
- if (!mono_breakpoint_trampoline_code) {
- mono_breakpoint_trampoline_code = buf = g_malloc (13);
-
- x86_call_code (buf, mono_debugger_trampoline_breakpoint_callback);
- x86_breakpoint (buf);
- x86_alu_reg_imm (buf, X86_ADD, X86_ESP, 8);
- x86_ret (buf);
-
- g_assert ((buf - mono_breakpoint_trampoline_code) <= 13);
- }
-
- start = code = g_malloc (22);
- x86_push_imm (code, addr);
- x86_push_imm (code, breakpoint_id);
- x86_push_imm (code, m);
- x86_jump_code (code, mono_breakpoint_trampoline_code);
- g_assert ((code - start) <= 22);
-
- return start;
-}
-
/**
* x86_magic_trampoline:
* @eax: saved x86 register
guint8 reg;
gint32 disp;
char *o;
- guint32 breakpoint_id;
- gpointer addr, trampoline;
+ gpointer addr;
EnterCriticalSection (metadata_section);
addr = mono_compile_method (m);
reg = code [1] & 0x07;
disp = *((gint32*)(code + 2));
} else if ((code [1] == 0xe8)) {
- breakpoint_id = mono_method_has_breakpoint (m, TRUE);
- if (breakpoint_id) {
- mono_remove_breakpoint (breakpoint_id);
- trampoline = get_breakpoint_trampoline (m, breakpoint_id, addr);
- } else
- trampoline = addr;
*((guint32*)(code + 2)) = (guint)addr - ((guint)code + 1) - 5;
- return trampoline;
+ return addr;
} else {
printf ("Invalid trampoline sequence: %x %x %x %x %x %x %x\n", code [0], code [1], code [2], code [3],
code [4], code [5], code [6]);
o += disp;
if (m->klass->valuetype) {
- trampoline = *((gpointer *)o) = get_unbox_trampoline (m, addr);
+ return *((gpointer *)o) = get_unbox_trampoline (m, addr);
} else {
- trampoline = *((gpointer *)o) = addr;
- }
-
- breakpoint_id = mono_method_has_breakpoint (m, TRUE);
- if (breakpoint_id) {
- mono_remove_breakpoint (breakpoint_id);
- return get_breakpoint_trampoline (m, breakpoint_id, trampoline);
- } else {
- return trampoline;
+ return *((gpointer *)o) = addr;
}
}
gpointer
arch_create_jit_trampoline (MonoMethod *method)
{
- MonoDomain *domain = mono_domain_get ();
guint8 *code, *buf;
- GHashTable *jit_code_hash;
/* previously created trampoline code */
if (method->info)
return method->info;
}
- /* check if we already have JITed code */
- if (mono_jit_share_code)
- jit_code_hash = mono_root_domain->jit_code_hash;
- else
- jit_code_hash = domain->jit_code_hash;
-
- if ((code = g_hash_table_lookup (jit_code_hash, method))) {
- mono_jit_stats.methods_lookups++;
- return code;
- }
-
if (!mono_generic_trampoline_code) {
mono_generic_trampoline_code = buf = g_malloc (256);
/* save caller save regs because we need to do a call */