Merge pull request #2003 from esdrubal/seq_test_fix2
[mono.git] / mono / mini / exceptions-ia64.c
index 26ef6651f91840007f837a16343c65e3068ce807..b9299cbe4fd3181883a5bf90efa29e896e4f6328 100644 (file)
@@ -37,8 +37,6 @@
 
 #define ALIGN_TO(val,align) (((val) + ((align) - 1)) & ~((align) - 1))
 
-#define NOT_IMPLEMENTED g_assert_not_reached ()
-
 #define GP_SCRATCH_REG 31
 #define GP_SCRATCH_REG2 30
 
@@ -92,8 +90,12 @@ restore_context (MonoContext *ctx)
  * Returns a pointer to a method which restores a previously saved sigcontext.
  */
 gpointer
-mono_arch_get_restore_context (void)
+mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot)
 {
+       g_assert (!aot);
+       if (info)
+               *info = NULL;
+
        return restore_context;
 }
 
@@ -218,8 +220,12 @@ call_filter (MonoContext *ctx, gpointer ip)
  * @exc object in this case).
  */
 gpointer
-mono_arch_get_call_filter (void)
+mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
 {
+       g_assert (!aot);
+       if (info)
+               *info = NULL;
+
        /* Initialize the real filter non-lazily */
        get_real_call_filter ();
 
@@ -237,8 +243,10 @@ throw_exception (MonoObject *exc, guint64 rethrow)
 
        if (mono_object_isinst (exc, mono_defaults.exception_class)) {
                MonoException *mono_ex = (MonoException*)exc;
-               if (!rethrow)
+               if (!rethrow) {
                        mono_ex->stack_trace = NULL;
+                       mono_ex->trace_ips = NULL;
+               }
        }
 
        res = unw_getcontext (&unw_ctx);
@@ -258,9 +266,9 @@ throw_exception (MonoObject *exc, guint64 rethrow)
                res = unw_get_reg (&ctx.cursor, UNW_IA64_SP, &sp);
                g_assert (res == 0);
 
-               ji = mono_jit_info_table_find (mono_domain_get (), (gpointer)ip);
+               ji = mini_jit_info_table_find (mono_domain_get (), (gpointer)ip, NULL);
 
-               //printf ("UN: %s %lx %lx\n", ji ? ji->method->name : "", ip, sp);
+               //printf ("UN: %s %lx %lx\n", ji ? jinfo_get_method (ji)->name : "", ip, sp);
 
                if (ji)
                        break;
@@ -276,8 +284,9 @@ throw_exception (MonoObject *exc, guint64 rethrow)
                }
                g_assert (res >= 0);
        }
+       ctx.precise_ip = FALSE;
 
-       mono_handle_exception (&ctx, exc, (gpointer)(ip), FALSE);
+       mono_handle_exception (&ctx, exc);
        restore_context (&ctx);
 
        g_assert_not_reached ();
@@ -355,56 +364,24 @@ get_throw_trampoline (gboolean rethrow)
  * signature: void (*func) (MonoException *exc); 
  *
  */
-gpointer 
-mono_arch_get_throw_exception (void)
+gpointer
+mono_arch_get_throw_exception (MonoTrampInfo **info, gboolean aot)
 {
-       static guint8* start;
-       static gboolean inited = FALSE;
-
-       if (inited)
-               return start;
-
-       start = get_throw_trampoline (FALSE);
-
-       inited = TRUE;
+       g_assert (!aot);
+       if (info)
+               *info = NULL;
 
-       return start;
+       return get_throw_trampoline (FALSE);
 }
 
-gpointer 
-mono_arch_get_rethrow_exception (void)
+gpointer
+mono_arch_get_rethrow_exception (MonoTrampInfo **info, gboolean aot)
 {
-       static guint8* start;
-       static gboolean inited = FALSE;
+       g_assert (!aot);
+       if (info)
+               *info = NULL;
 
-       if (inited)
-               return start;
-
-       start = get_throw_trampoline (TRUE);
-
-       inited = TRUE;
-
-       return start;
-}
-
-gpointer 
-mono_arch_get_throw_exception_by_name (void)
-{      
-       guint8* start;
-       Ia64CodegenState code;
-
-       start = mono_global_codeman_reserve (64);
-
-       /* Not used on ia64 */
-       ia64_codegen_init (code, start);
-       ia64_break_i (code, 1001);
-       ia64_codegen_close (code);
-
-       g_assert ((code.buf - start) <= 256);
-
-       mono_arch_flush_icache (start, code.buf - start);
-
-       return start;
+       return get_throw_trampoline (TRUE);
 }
 
 /**
@@ -417,8 +394,8 @@ mono_arch_get_throw_exception_by_name (void)
  * to get the IP of the throw. Passing the offset has the advantage that it 
  * needs no relocations in the caller.
  */
-gpointer 
-mono_arch_get_throw_corlib_exception (void)
+gpointer
+mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot)
 {
        static guint8* res;
        static gboolean inited = FALSE;
@@ -429,6 +406,10 @@ mono_arch_get_throw_corlib_exception (void)
        unw_dyn_info_t *di;
        unw_dyn_region_info_t *r_pro;
 
+       g_assert (!aot);
+       if (info)
+               *info = NULL;
+
        if (inited)
                return res;
 
@@ -508,68 +489,68 @@ mono_arch_get_throw_corlib_exception (void)
        return res;
 }
 
-/* mono_arch_find_jit_info:
+/*
+ * mono_arch_unwind_frame:
  *
- * This function is used to gather information from @ctx. It return the 
- * MonoJitInfo of the corresponding function, unwinds one stack frame and
- * stores the resulting context into @new_ctx. It also stores a string 
- * describing the stack location into @trace (if not NULL), and modifies
- * the @lmf if necessary. @native_offset return the IP offset from the 
- * start of the function or -1 if that info is not available.
+ * This function is used to gather information from @ctx, and store it in @frame_info.
+ * It unwinds one stack frame, and stores the resulting context into @new_ctx. @lmf
+ * is modified if needed.
+ * Returns TRUE on success, FALSE otherwise.
  */
-MonoJitInfo *
-mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoJitInfo *res, MonoJitInfo *prev_ji, MonoContext *ctx, 
-                        MonoContext *new_ctx, char **trace, MonoLMF **lmf, int *native_offset,
-                        gboolean *managed)
+gboolean
+mono_arch_unwind_frame (MonoDomain *domain, MonoJitTlsData *jit_tls, 
+                                                        MonoJitInfo *ji, MonoContext *ctx, 
+                                                        MonoContext *new_ctx, MonoLMF **lmf,
+                                                        mgreg_t **save_locations,
+                                                        StackFrameInfo *frame)
 {
-       MonoJitInfo *ji;
        int err;
        unw_word_t ip;
 
-       *new_ctx = *ctx;
-
-       while (TRUE) {
-               err = unw_get_reg (&new_ctx->cursor, UNW_IA64_IP, &ip);
-               g_assert (err == 0);
-
-               /* Avoid costly table lookup during stack overflow */
-               if (prev_ji && ((guint8*)ip > (guint8*)prev_ji->code_start && ((guint8*)ip < ((guint8*)prev_ji->code_start) + prev_ji->code_size)))
-                       ji = prev_ji;
-               else
-                       ji = mono_jit_info_table_find (domain, (gpointer)ip);
-
-               if (managed)
-                       *managed = FALSE;
+       memset (frame, 0, sizeof (StackFrameInfo));
+       frame->ji = ji;
 
-               /*
-               {
-                       char name[256];
-                       unw_word_t off;
+       *new_ctx = *ctx;
+       new_ctx->precise_ip = FALSE;
 
-                       unw_get_proc_name (&new_ctx->cursor, name, 256, &off);
-                       printf ("F: %s\n", name);
-               }
-               */
+       if (!ji) {
+               while (TRUE) {
+                       err = unw_get_reg (&new_ctx->cursor, UNW_IA64_IP, &ip);
+                       g_assert (err == 0);
 
-               if (ji != NULL) {
-                       if (managed)
-                               if (!ji->method->wrapper_type)
-                                       *managed = TRUE;
+                       ji = mini_jit_info_table_find (domain, (gpointer)ip, NULL);
 
-                       break;
+                       /*
+                         {
+                         char name[256];
+                         unw_word_t off;
+
+                         unw_get_proc_name (&new_ctx->cursor, name, 256, &off);
+                         printf ("F: %s\n", name);
+                         }
+                       */
+
+                       if (ji)
+                               break;
+
+                       /* This is an unmanaged frame, so just unwind through it */
+                       /* FIXME: This returns -3 for the __clone2 frame in libc */
+                       err = unw_step (&new_ctx->cursor);
+                       if (err < 0)
+                               break;
+
+                       if (err == 0)
+                               break;
                }
-
-               /* This is an unmanaged frame, so just unwind through it */
-               /* FIXME: This returns -3 for the __clone2 frame in libc */
-               err = unw_step (&new_ctx->cursor);
-               if (err < 0)
-                       break;
-
-               if (err == 0)
-                       break;
        }
 
        if (ji) {
+               if (ji->is_trampoline)
+                       frame->type = FRAME_TYPE_TRAMPOLINE;
+               else
+                       frame->type = FRAME_TYPE_MANAGED;
+               frame->ji = ji;
+
                //print_ctx (new_ctx);
 
                err = unw_step (&new_ctx->cursor);
@@ -577,10 +558,10 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoJitInf
 
                //print_ctx (new_ctx);
 
-               return ji;
+               return TRUE;
        }
        else
-               return (gpointer)(gssize)-1;
+               return FALSE;
 }
 
 /**
@@ -590,7 +571,7 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoJitInf
  * @obj: the exception object
  */
 gboolean
-mono_arch_handle_exception (void *sigctx, gpointer obj, gboolean test_only)
+mono_arch_handle_exception (void *sigctx, gpointer obj)
 {
        /* libunwind takes care of this */
        unw_context_t unw_ctx;
@@ -612,7 +593,7 @@ mono_arch_handle_exception (void *sigctx, gpointer obj, gboolean test_only)
                res = unw_get_reg (&ctx.cursor, UNW_IA64_IP, &ip);
                g_assert (res == 0);
 
-               ji = mono_jit_info_table_find (mono_domain_get (), (gpointer)ip);
+               ji = mini_jit_info_table_find (mono_domain_get (), (gpointer)ip, NULL);
 
                if (ji)
                        break;
@@ -620,8 +601,9 @@ mono_arch_handle_exception (void *sigctx, gpointer obj, gboolean test_only)
                res = unw_step (&ctx.cursor);
                g_assert (res >= 0);
        }
+       ctx.precise_ip = TRUE;
 
-       mono_handle_exception (&ctx, obj, (gpointer)ip, test_only);
+       mono_handle_exception (&ctx, obj);
 
        restore_context (&ctx);