2 * exception.c: exception support
5 * Dietmar Maurer (dietmar@ximian.com)
6 * Paolo Molaro (lupus@ximian.com)
8 * (C) 2001 Ximian, Inc.
16 #include <mono/arch/ppc/ppc-codegen.h>
17 #include <mono/metadata/appdomain.h>
18 #include <mono/metadata/tabledefs.h>
19 #include <mono/metadata/threads.h>
20 #include <mono/metadata/debug-helpers.h>
21 #include <mono/metadata/exception.h>
22 #include <mono/metadata/mono-debug.h>
27 typedef struct sigcontext MonoContext;
32 int sc_onstack; // sigstack state to restore
33 int sc_mask; // signal mask to restore
35 int sc_psw; // processor status word
36 int sc_sp; // stack pointer if sc_regs == NULL
37 void *sc_regs; // (kernel private) saved state
42 sigset_t uc_sigmask; // signal mask used by this context
43 stack_t uc_stack; // stack used by this context
44 struct ucontext *uc_link; // pointer to resuming context
45 size_t uc_mcsize; // size of the machine context passed in
46 mcontext_t uc_mcontext; // machine specific context
49 typedef struct ppc_exception_state {
50 unsigned long dar; // Fault registers for coredump
52 unsigned long exception;// number of powerpc exception taken
53 unsigned long pad0; // align to 16 bytes
55 unsigned long pad1[4]; // space in PCB "just in case"
56 } ppc_exception_state_t;
58 typedef struct ppc_vector_state {
59 unsigned long save_vr[32][4];
60 unsigned long save_vscr[4];
61 unsigned int save_pad5[4];
62 unsigned int save_vrvalid; // VRs that have been saved
63 unsigned int save_pad6[7];
66 typedef struct ppc_float_state {
69 unsigned int fpscr_pad; // fpscr is 64 bits, 32 bits of rubbish
70 unsigned int fpscr; // floating point status register
73 typedef struct ppc_thread_state {
74 unsigned int srr0; // Instruction address register (PC)
75 unsigned int srr1; // Machine state register (supervisor)
81 unsigned int cr; // Condition register
82 unsigned int xer; // User's integer exception register
83 unsigned int lr; // Link register
84 unsigned int ctr; // Count register
85 unsigned int mq; // MQ register (601 only)
87 unsigned int vrsave; // Vector Save Register
91 ppc_exception_state_t es;
92 ppc_thread_state_t ss;
94 ppc_vector_state_t vs;
97 typedef struct mcontext * mcontext_t;
103 /* we have the stack pointer, not the base pointer in sigcontext */
104 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->sc_ir = (int)ip; } while (0);
105 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->sc_sp = (int)bp; } while (0);
107 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->sc_ir))
108 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->sc_sp))
110 #else /* sigcontext is different on linux/ppc. See /usr/include/asm/ptrace.h. */
112 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->regs->nip = (unsigned long)ip; } while (0);
113 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->regs->gpr[1] = (unsigned long)bp; } while (0);
115 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->regs->nip))
116 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->regs->gpr[1]))
120 /* disbale this for now */
121 #undef MONO_USE_EXC_TABLES
123 #ifdef MONO_USE_EXC_TABLES
125 /*************************************/
126 /* STACK UNWINDING STUFF */
127 /*************************************/
129 /* These definitions are from unwind-dw2.c in glibc 2.2.5 */
132 #define DWARF_FRAME_REGISTERS 17
134 typedef struct frame_state
140 long reg_or_offset[DWARF_FRAME_REGISTERS+1];
141 unsigned short cfa_reg;
142 unsigned short retaddr_column;
143 char saved[DWARF_FRAME_REGISTERS+1];
149 get_sigcontext_reg (struct sigcontext *ctx, int dwarf_regnum)
151 switch (dwarf_regnum) {
169 g_assert_not_reached ();
176 set_sigcontext_reg (struct sigcontext *ctx, int dwarf_regnum, long value)
178 switch (dwarf_regnum) {
207 g_assert_not_reached ();
211 typedef struct frame_state * (*framesf) (void *, struct frame_state *);
213 static framesf frame_state_for = NULL;
215 static gboolean inited = FALSE;
217 typedef char ** (*get_backtrace_symbols_type) (void *__const *__array, int __size);
219 static get_backtrace_symbols_type get_backtrace_symbols = NULL;
222 init_frame_state_for (void)
227 * There are two versions of __frame_state_for: one in libgcc.a and the
228 * other in glibc.so. We need the version from glibc.
229 * For more info, see this:
230 * http://gcc.gnu.org/ml/gcc/2002-08/msg00192.html
232 if ((module = g_module_open ("libc.so.6", G_MODULE_BIND_LAZY))) {
234 if (!g_module_symbol (module, "__frame_state_for", (gpointer*)&frame_state_for))
235 frame_state_for = NULL;
237 if (!g_module_symbol (module, "backtrace_symbols", (gpointer*)&get_backtrace_symbols)) {
238 get_backtrace_symbols = NULL;
239 frame_state_for = NULL;
242 g_module_close (module);
250 gboolean mono_arch_handle_exception (struct sigcontext *ctx, gpointer obj, gboolean test_only);
252 /* mono_arch_has_unwind_info:
254 * Tests if a function has an DWARF exception table able to restore
255 * all caller saved registers.
258 mono_arch_has_unwind_info (MonoMethod *method)
261 struct frame_state state_in;
262 struct frame_state *res;
265 init_frame_state_for ();
267 if (!frame_state_for)
270 g_assert (method->addr);
272 memset (&state_in, 0, sizeof (state_in));
274 /* offset 10 is just a guess, but it works for all methods tested */
275 if ((res = frame_state_for ((char *)method->addr + 10, &state_in))) {
277 if (res->saved [X86_EBX] != 1 ||
278 res->saved [X86_EDI] != 1 ||
279 res->saved [X86_EBP] != 1 ||
280 res->saved [X86_ESI] != 1) {
295 void *return_address;
299 ppc_unwind_native_frame (MonoDomain *domain, MonoJitTlsData *jit_tls, struct sigcontext *ctx,
300 struct sigcontext *new_ctx, MonoLMF *lmf, char **trace)
303 struct stack_frame *frame;
306 struct frame_state state_in;
307 struct frame_state *res;
313 init_frame_state_for ();
315 if (!frame_state_for)
318 frame = MONO_CONTEXT_GET_BP (ctx);
320 max_stack = lmf && lmf->method ? lmf : jit_tls->end_of_stack;
324 memset (&state_in, 0, sizeof (state_in));
326 while ((gpointer)frame->next < (gpointer)max_stack) {
327 gpointer ip, addr = frame->return_address;
329 char *tmp, **symbols;
332 ip = MONO_CONTEXT_GET_IP (new_ctx);
333 symbols = get_backtrace_symbols (&ip, 1);
335 tmp = g_strdup_printf ("%s\nin (unmanaged) %s", *trace, symbols [0]);
337 tmp = g_strdup_printf ("in (unmanaged) %s", symbols [0]);
344 if ((res = frame_state_for (addr, &state_in))) {
347 cfa = (gint8*) (get_sigcontext_reg (new_ctx, res->cfa_reg) + res->cfa_offset);
348 frame = (struct stack_frame *)((gint8*)cfa - 8);
349 for (i = 0; i < DWARF_FRAME_REGISTERS + 1; i++) {
350 int how = res->saved[i];
352 g_assert ((how == 0) || (how == 1));
355 val = * (long*) ((gint8*)cfa + res->reg_or_offset[i]);
356 set_sigcontext_reg (new_ctx, i, val);
359 new_ctx->SC_ESP = (long)cfa;
361 if (res->saved [X86_EBX] == 1 &&
362 res->saved [X86_EDI] == 1 &&
363 res->saved [X86_EBP] == 1 &&
364 res->saved [X86_ESI] == 1 &&
365 (ji = mono_jit_info_table_find (domain, frame->return_address))) {
366 //printf ("FRAME CFA %s\n", mono_method_full_name (ji->method, TRUE));
371 //printf ("FRAME %p %p %p\n", frame, MONO_CONTEXT_GET_IP (new_ctx), mono_jit_info_table_find (domain, MONO_CONTEXT_GET_IP (new_ctx)));
373 MONO_CONTEXT_SET_IP (new_ctx, frame->return_address);
375 MONO_CONTEXT_SET_BP (new_ctx, frame);
377 /* stop if !frame or when we detect an unexpected managed frame */
378 if (!frame || mono_jit_info_table_find (domain, frame->return_address)) {
389 //g_assert_not_reached ();
402 * arch_get_restore_context:
404 * Returns a pointer to a method which restores a previously saved sigcontext.
407 arch_get_restore_context (void)
409 static guint8 *start = NULL;
416 /* restore_contect (struct sigcontext *ctx) */
417 /* we do not restore X86_EAX, X86_EDX */
419 start = code = g_malloc (1024);
422 x86_mov_reg_membase (code, X86_EAX, X86_ESP, 4, 4);
424 /* get return address, stored in EDX */
425 x86_mov_reg_membase (code, X86_EDX, X86_EAX, G_STRUCT_OFFSET (struct sigcontext, SC_EIP), 4);
427 x86_mov_reg_membase (code, X86_EBX, X86_EAX, G_STRUCT_OFFSET (struct sigcontext, SC_EBX), 4);
429 x86_mov_reg_membase (code, X86_EDI, X86_EAX, G_STRUCT_OFFSET (struct sigcontext, SC_EDI), 4);
431 x86_mov_reg_membase (code, X86_ESI, X86_EAX, G_STRUCT_OFFSET (struct sigcontext, SC_ESI), 4);
433 x86_mov_reg_membase (code, X86_ESP, X86_EAX, G_STRUCT_OFFSET (struct sigcontext, SC_ESP), 4);
435 x86_mov_reg_membase (code, X86_EBP, X86_EAX, G_STRUCT_OFFSET (struct sigcontext, SC_EBP), 4);
437 /* jump to the saved IP */
438 x86_jump_reg (code, X86_EDX);
445 * arch_get_call_filter:
447 * Returns a pointer to a method which calls an exception filter. We
448 * also use this function to call finally handlers (we pass NULL as
449 * @exc object in this case).
452 arch_get_call_filter (void)
454 static guint8 start [64];
455 static int inited = 0;
462 /* call_filter (struct sigcontext *ctx, unsigned long eip, gpointer exc) */
466 x86_push_reg (code, X86_EBP);
467 x86_mov_reg_reg (code, X86_EBP, X86_ESP, 4);
468 x86_push_reg (code, X86_EBX);
469 x86_push_reg (code, X86_EDI);
470 x86_push_reg (code, X86_ESI);
473 x86_mov_reg_membase (code, X86_EAX, X86_EBP, 8, 4);
475 x86_mov_reg_membase (code, X86_ECX, X86_EBP, 12, 4);
477 x86_push_reg (code, X86_EBP);
479 x86_push_membase (code, X86_EBP, 16);
481 x86_mov_reg_membase (code, X86_EBP, X86_EAX, G_STRUCT_OFFSET (struct sigcontext, SC_EBP), 4);
482 /* restore registers used by global register allocation (EBX & ESI) */
483 x86_mov_reg_membase (code, X86_EBX, X86_EAX, G_STRUCT_OFFSET (struct sigcontext, SC_EBX), 4);
484 x86_mov_reg_membase (code, X86_ESI, X86_EAX, G_STRUCT_OFFSET (struct sigcontext, SC_ESI), 4);
485 x86_mov_reg_membase (code, X86_EDI, X86_EAX, G_STRUCT_OFFSET (struct sigcontext, SC_EDI), 4);
486 /* save the ESP - this is used by endfinally */
487 x86_mov_membase_reg (code, X86_EBP, mono_exc_esp_offset, X86_ESP, 4);
488 /* call the handler */
489 x86_call_reg (code, X86_ECX);
490 x86_alu_reg_imm (code, X86_ADD, X86_ESP, 4);
492 x86_pop_reg (code, X86_EBP);
493 /* restore saved regs */
494 x86_pop_reg (code, X86_ESI);
495 x86_pop_reg (code, X86_EDI);
496 x86_pop_reg (code, X86_EBX);
500 g_assert ((code - start) < 64);
506 throw_exception (unsigned long eax, unsigned long ecx, unsigned long edx, unsigned long ebx,
507 unsigned long esi, unsigned long edi, unsigned long ebp, MonoObject *exc,
508 unsigned long eip, unsigned long esp)
510 static void (*restore_context) (struct sigcontext *);
511 struct sigcontext ctx;
513 if (!restore_context)
514 restore_context = arch_get_restore_context ();
516 /* adjust eip so that it point into the call instruction */
530 mono_arch_handle_exception (&ctx, exc, FALSE);
531 restore_context (&ctx);
533 g_assert_not_reached ();
537 * arch_get_throw_exception:
539 * Returns a function pointer which can be used to raise
540 * exceptions. The returned function has the following
541 * signature: void (*func) (MonoException *exc);
542 * For example to raise an arithmetic exception you can use:
544 * x86_push_imm (code, mono_get_exception_arithmetic ());
545 * x86_call_code (code, arch_get_throw_exception ());
549 mono_arch_get_throw_exception (void)
551 static guint8 start [24];
552 static int inited = 0;
562 x86_push_reg (code, X86_ESP);
563 x86_push_membase (code, X86_ESP, 4); /* IP */
564 x86_push_membase (code, X86_ESP, 12); /* exception */
565 x86_push_reg (code, X86_EBP);
566 x86_push_reg (code, X86_EDI);
567 x86_push_reg (code, X86_ESI);
568 x86_push_reg (code, X86_EBX);
569 x86_push_reg (code, X86_EDX);
570 x86_push_reg (code, X86_ECX);
571 x86_push_reg (code, X86_EAX);
572 x86_call_code (code, throw_exception);
573 /* we should never reach this breakpoint */
574 x86_breakpoint (code);
576 g_assert ((code - start) < 24);
582 * arch_get_throw_exception_by_name:
584 * Returns a function pointer which can be used to raise
585 * corlib exceptions. The returned function has the following
586 * signature: void (*func) (char *exc_name);
587 * For example to raise an arithmetic exception you can use:
589 * x86_push_imm (code, "ArithmeticException");
590 * x86_call_code (code, arch_get_throw_exception_by_name ());
594 mono_arch_get_throw_exception_by_name (void)
596 static guint8 start [32];
597 static int inited = 0;
606 x86_push_membase (code, X86_ESP, 4); /* exception name */
607 x86_push_imm (code, "System");
608 x86_push_imm (code, mono_defaults.exception_class->image);
609 x86_call_code (code, mono_exception_from_name);
610 x86_alu_reg_imm (code, X86_ADD, X86_ESP, 12);
611 /* save the newly create object (overwrite exception name)*/
612 x86_mov_membase_reg (code, X86_ESP, 4, X86_EAX, 4);
613 x86_jump_code (code, mono_arch_get_throw_exception ());
615 g_assert ((code - start) < 32);
621 glist_to_array (GList *list)
623 MonoDomain *domain = mono_domain_get ();
630 len = g_list_length (list);
631 res = mono_array_new (domain, mono_defaults.int_class, len);
633 for (i = 0; list; list = list->next, i++)
634 mono_array_set (res, gpointer, i, list->data);
639 /* mono_arch_find_jit_info:
641 * This function is used to gather information from @ctx. It return the
642 * MonoJitInfo of the corresponding function, unwinds one stack frame and
643 * stores the resulting context into @new_ctx. It also stores a string
644 * describing the stack location into @trace (if not NULL), and modifies
645 * the @lmf if necessary. @native_offset return the IP offset from the
646 * start of the function or -1 if that info is not available.
649 mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoJitInfo *res, MonoContext *ctx,
650 MonoContext *new_ctx, char **trace, MonoLMF **lmf, int *native_offset,
654 gpointer ip = MONO_CONTEXT_GET_IP (ctx);
656 ji = mono_jit_info_table_find (domain, ip);
668 char *source_location, *tmpaddr, *fname;
669 gint32 address, iloffset;
674 if (*lmf && (MONO_CONTEXT_GET_BP (ctx) >= (gpointer)(*lmf)->ebp)) {
675 /* remove any unused lmf */
676 *lmf = (*lmf)->previous_lmf;
679 address = (char *)ip - (char *)ji->code_start;
682 *native_offset = address;
685 if (!ji->method->wrapper_type)
689 source_location = mono_debug_source_location_from_address (ji->method, address, NULL, domain);
690 iloffset = mono_debug_il_offset_from_address (ji->method, address, domain);
693 tmpaddr = g_strdup_printf ("<0x%05x>", address);
695 tmpaddr = g_strdup_printf ("[0x%05x]", iloffset);
697 fname = mono_method_full_name (ji->method, TRUE);
700 *trace = g_strdup_printf ("in %s (at %s) %s", tmpaddr, source_location, fname);
702 *trace = g_strdup_printf ("in %s %s", tmpaddr, fname);
705 g_free (source_location);
710 /* restore caller saved registers */
711 if (ji->used_regs & X86_EBX_MASK) {
712 new_ctx->SC_EBX = *((int *)ctx->SC_EBP + offset);
715 if (ji->used_regs & X86_EDI_MASK) {
716 new_ctx->SC_EDI = *((int *)ctx->SC_EBP + offset);
719 if (ji->used_regs & X86_ESI_MASK) {
720 new_ctx->SC_ESI = *((int *)ctx->SC_EBP + offset);
723 new_ctx->SC_ESP = ctx->SC_EBP;
724 /* we substract 1, so that the IP points into the call instruction */
725 new_ctx->SC_EIP = *((int *)ctx->SC_EBP + 1) - 1;
726 new_ctx->SC_EBP = *((int *)ctx->SC_EBP);
730 #ifdef MONO_USE_EXC_TABLES
731 } else if ((ji = ppc_unwind_native_frame (domain, jit_tls, ctx, new_ctx, *lmf, trace))) {
743 *trace = g_strdup_printf ("in (unmanaged) %s", mono_method_full_name ((*lmf)->method, TRUE));
745 if ((ji = mono_jit_info_table_find (domain, (gpointer)(*lmf)->eip))) {
748 memset (res, 0, sizeof (MonoJitInfo));
749 res->method = (*lmf)->method;
753 new_ctx->SC_ESI = (*lmf)->esi;
754 new_ctx->SC_EDI = (*lmf)->edi;
755 new_ctx->SC_EBX = (*lmf)->ebx;
756 new_ctx->SC_EBP = (*lmf)->ebp;
757 new_ctx->SC_EIP = (*lmf)->eip;
758 /* the lmf is always stored on the stack, so the following
759 * expression points to a stack location which can be used as ESP */
760 new_ctx->SC_ESP = (unsigned long)&((*lmf)->eip);
762 *lmf = (*lmf)->previous_lmf;
772 ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info)
774 MonoDomain *domain = mono_domain_get ();
776 MonoArray *ta = exc->trace_ips;
779 len = mono_array_length (ta);
781 res = mono_array_new (domain, mono_defaults.stack_frame_class, len > skip ? len - skip : 0);
783 for (i = skip; i < len; i++) {
785 MonoStackFrame *sf = (MonoStackFrame *)mono_object_new (domain, mono_defaults.stack_frame_class);
786 gpointer ip = mono_array_get (ta, gpointer, i);
788 ji = mono_jit_info_table_find (domain, ip);
789 g_assert (ji != NULL);
791 sf->method = mono_method_get_object (domain, ji->method, NULL);
792 sf->native_offset = (char *)ip - (char *)ji->code_start;
794 sf->il_offset = mono_debug_il_offset_from_address (ji->method, sf->native_offset, domain);
796 if (need_file_info) {
799 filename = mono_debug_source_location_from_address (ji->method, sf->native_offset, &sf->line, domain);
801 sf->filename = filename? mono_string_new (domain, filename): NULL;
807 mono_array_set (res, gpointer, i, sf);
814 mono_jit_walk_stack (MonoStackWalk func, gpointer user_data) {
815 MonoDomain *domain = mono_domain_get ();
816 MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
817 MonoLMF *lmf = jit_tls->lmf;
818 MonoJitInfo *ji, rji;
819 gint native_offset, il_offset;
822 MonoContext ctx, new_ctx;
824 MONO_CONTEXT_SET_IP (&ctx, __builtin_return_address (0));
825 MONO_CONTEXT_SET_BP (&ctx, __builtin_frame_address (1));
827 while (MONO_CONTEXT_GET_BP (&ctx) < jit_tls->end_of_stack) {
829 ji = mono_arch_find_jit_info (domain, jit_tls, &rji, &ctx, &new_ctx, NULL, &lmf, &native_offset, &managed);
832 if (ji == (gpointer)-1)
835 il_offset = mono_debug_il_offset_from_address (ji->method, native_offset, domain);
837 if (func (ji->method, native_offset, il_offset, managed, user_data))
845 ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
846 MonoReflectionMethod **method,
847 gint32 *iloffset, gint32 *native_offset,
848 MonoString **file, gint32 *line, gint32 *column)
850 MonoDomain *domain = mono_domain_get ();
851 MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
852 MonoLMF *lmf = jit_tls->lmf;
853 MonoJitInfo *ji, rji;
854 MonoContext ctx, new_ctx;
856 MONO_CONTEXT_SET_IP (&ctx, ves_icall_get_frame_info);
857 MONO_CONTEXT_SET_BP (&ctx, __builtin_frame_address (0));
862 ji = mono_arch_find_jit_info (domain, jit_tls, &rji, &ctx, &new_ctx, NULL, &lmf, native_offset, NULL);
866 if (!ji || ji == (gpointer)-1 || MONO_CONTEXT_GET_BP (&ctx) >= jit_tls->end_of_stack)
869 /* skip all wrappers ??*/
870 if (ji->method->wrapper_type == MONO_WRAPPER_RUNTIME_INVOKE ||
871 ji->method->wrapper_type == MONO_WRAPPER_REMOTING_INVOKE_WITH_CHECK ||
872 ji->method->wrapper_type == MONO_WRAPPER_REMOTING_INVOKE)
879 *method = mono_method_get_object (domain, ji->method, NULL);
880 *iloffset = mono_debug_il_offset_from_address (ji->method, *native_offset, domain);
882 if (need_file_info) {
885 filename = mono_debug_source_location_from_address (ji->method, *native_offset, line, domain);
887 *file = filename? mono_string_new (domain, filename): NULL;
897 * arch_handle_exception:
898 * @ctx: saved processor state
899 * @obj: the exception object
900 * @test_only: only test if the exception is caught, but dont call handlers
905 mono_arch_handle_exception (MonoContext *ctx, gpointer obj, gboolean test_only)
907 MonoDomain *domain = mono_domain_get ();
908 MonoJitInfo *ji, rji;
909 static int (*call_filter) (MonoContext *, gpointer, gpointer) = NULL;
910 MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
911 MonoLMF *lmf = jit_tls->lmf;
912 GList *trace_ips = NULL;
913 MonoException *mono_ex;
915 g_assert (ctx != NULL);
917 MonoException *ex = mono_get_exception_null_reference ();
918 ex->message = mono_string_new (domain,
919 "Object reference not set to an instance of an object");
920 obj = (MonoObject *)ex;
923 if (mono_object_isinst (obj, mono_defaults.exception_class)) {
924 mono_ex = (MonoException*)obj;
925 mono_ex->stack_trace = NULL;
932 call_filter = arch_get_call_filter ();
934 g_assert (jit_tls->end_of_stack);
935 g_assert (jit_tls->abort_func);
938 MonoContext ctx_cp = *ctx;
939 if (mono_jit_trace_calls != NULL)
940 g_print ("EXCEPTION handling: %s\n", mono_object_class (obj)->name);
941 if (!mono_arch_handle_exception (&ctx_cp, obj, TRUE)) {
942 if (mono_break_on_exc)
944 mono_unhandled_exception (obj);
952 ji = mono_arch_find_jit_info (domain, jit_tls, &rji, ctx, &new_ctx,
953 test_only ? &trace : NULL, &lmf, NULL, NULL);
955 g_warning ("Exception inside function without unwind info");
956 g_assert_not_reached ();
959 if (ji != (gpointer)-1) {
961 if (test_only && ji->method->wrapper_type != MONO_WRAPPER_RUNTIME_INVOKE && mono_ex) {
964 trace_ips = g_list_append (trace_ips, MONO_CONTEXT_GET_IP (ctx));
966 if (!mono_ex->stack_trace)
967 strace = g_strdup ("");
969 strace = mono_string_to_utf8 (mono_ex->stack_trace);
971 tmp = g_strdup_printf ("%s%s\n", strace, trace);
974 mono_ex->stack_trace = mono_string_new (domain, tmp);
979 if (ji->num_clauses) {
982 g_assert (ji->clauses);
984 for (i = 0; i < ji->num_clauses; i++) {
985 MonoJitExceptionInfo *ei = &ji->clauses [i];
987 if (ei->try_start <= MONO_CONTEXT_GET_IP (ctx) &&
988 MONO_CONTEXT_GET_IP (ctx) <= ei->try_end) {
990 if ((ei->flags == MONO_EXCEPTION_CLAUSE_NONE &&
991 mono_object_isinst (obj, mono_class_get (ji->method->klass->image, ei->data.token))) ||
992 ((ei->flags == MONO_EXCEPTION_CLAUSE_FILTER &&
993 call_filter (ctx, ei->data.filter, obj)))) {
996 mono_ex->trace_ips = glist_to_array (trace_ips);
997 g_list_free (trace_ips);
1001 if (mono_jit_trace_calls != NULL)
1002 g_print ("EXCEPTION: catch found at clause %d of %s\n", i, mono_method_full_name (ji->method, TRUE));
1003 MONO_CONTEXT_SET_IP (ctx, ei->handler_start);
1004 *((gpointer *)((char *)MONO_CONTEXT_GET_BP (ctx) + ji->exvar_offset)) = obj;
1009 if (!test_only && ei->try_start <= MONO_CONTEXT_GET_IP (ctx) &&
1010 MONO_CONTEXT_GET_IP (ctx) < ei->try_end &&
1011 (ei->flags & MONO_EXCEPTION_CLAUSE_FINALLY)) {
1012 if (mono_jit_trace_calls != NULL)
1013 g_print ("EXCEPTION: finally clause %d of %s\n", i, mono_method_full_name (ji->method, TRUE));
1014 call_filter (ctx, ei->handler_start, NULL);
1026 if ((ji == (gpointer)-1) || MONO_CONTEXT_GET_BP (ctx) >= jit_tls->end_of_stack) {
1029 jit_tls->abort_func (obj);
1030 g_assert_not_reached ();
1033 mono_ex->trace_ips = glist_to_array (trace_ips);
1034 g_list_free (trace_ips);
1040 g_assert_not_reached ();
1044 mono_arch_has_unwind_info (gconstpointer addr)