#include <glib.h>
#include <config.h>
+#include <mono/metadata/environment.h>
#include <mono/metadata/exception.h>
#include <mono/metadata/exception-internals.h>
#include <mono/metadata/appdomain.h>
#include <mono/metadata/mono-debug.h>
#include <mono/utils/mono-error-internals.h>
+#include <mono/utils/mono-logger-internals.h>
#include <string.h>
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
#endif
+static MonoUnhandledExceptionFunc unhandled_exception_hook = NULL;
+static gpointer unhandled_exception_hook_data = NULL;
+
/**
* mono_exception_from_name:
* @image: the Mono image where to look for the class
}
}
+void
+mono_install_unhandled_exception_hook (MonoUnhandledExceptionFunc func, gpointer user_data)
+{
+ unhandled_exception_hook = func;
+ unhandled_exception_hook_data = user_data;
+}
+
+void
+mono_invoke_unhandled_exception_hook (MonoObject *exc)
+{
+ if (unhandled_exception_hook) {
+ unhandled_exception_hook (exc, unhandled_exception_hook_data);
+ } else {
+ MonoError inner_error;
+ MonoObject *other = NULL;
+ MonoString *str = mono_object_try_to_string (exc, &other, &inner_error);
+ char *msg = NULL;
+
+ if (str && is_ok (&inner_error)) {
+ msg = mono_string_to_utf8_checked (str, &inner_error);
+ }
+ if (!is_ok (&inner_error)) {
+ msg = g_strdup_printf ("Nested exception while formatting original exception");
+ mono_error_cleanup (&inner_error);
+ } else if (other) {
+ char *original_backtrace = mono_exception_get_managed_backtrace ((MonoException*)exc);
+ char *nested_backtrace = mono_exception_get_managed_backtrace ((MonoException*)other);
+
+ msg = g_strdup_printf ("Nested exception detected.\nOriginal Exception: %s\nNested exception:%s\n",
+ original_backtrace, nested_backtrace);
+
+ g_free (original_backtrace);
+ g_free (nested_backtrace);
+ } else {
+ msg = g_strdup ("Nested exception trying to figure out what went wrong");
+ }
+ mono_runtime_printf_err ("[ERROR] FATAL UNHANDLED EXCEPTION: %s", msg);
+ g_free (msg);
+#if defined(HOST_IOS)
+ g_assertion_message ("Terminating runtime due to unhandled exception");
+#else
+ exit (mono_environment_exitcode_get ());
+#endif
+ }
+
+ g_assert_not_reached ();
+}
#ifndef _MONO_METADATA_EXCEPTION_H_
#define _MONO_METADATA_EXCEPTION_H_
+#include <glib.h>
#include <mono/metadata/object.h>
#include <mono/metadata/image.h>
MONO_API MonoException *
mono_get_exception_runtime_wrapped (MonoObject *wrapped_exception);
+/* Installs a function which is called when the runtime encounters an unhandled exception.
+ * This hook isn't expected to return.
+ * If no hook has been installed, the runtime will print a message before aborting.
+ */
+typedef void (*MonoUnhandledExceptionFunc) (MonoObject *exc, gpointer user_data);
+MONO_API void mono_install_unhandled_exception_hook (MonoUnhandledExceptionFunc func, gpointer user_data);
+void mono_invoke_unhandled_exception_hook (MonoObject *exc);
+
MONO_END_DECLS
#endif /* _MONO_METADATA_EXCEPTION_H_ */
if (!mono_error_ok (&error)) {
MonoException *ex = mono_error_convert_to_exception (&error);
- if (ex)
+ if (ex) {
mono_unhandled_exception (&ex->object);
+ mono_invoke_unhandled_exception_hook (&ex->object);
+ g_assert_not_reached ();
+ }
} else {
mono_error_cleanup (&error);
}
mono_thread_internal_reset_abort (mono_thread_internal_current ());
} else if (!is_appdomainunloaded_exception (klass)) {
mono_unhandled_exception (exc);
+ // AK: Should we call mono_invoke_unhandled_exception_hook here?
if (mono_environment_exitcode_get () == 1)
exit (255);
}
if (exc) {
mono_unhandled_exception (exc);
mono_invoke_unhandled_exception_hook (exc);
- return 1;
+ g_assert_not_reached ();
}
return res;
} else {
int res = mono_runtime_run_main_checked (method, argc, argv, &error);
if (!is_ok (&error)) {
MonoException *ex = mono_error_convert_to_exception (&error);
- if (ex)
- mono_unhandled_exception ((MonoObject*)ex);
+ if (ex) {
+ mono_unhandled_exception (&ex->object);
+ mono_invoke_unhandled_exception_hook (&ex->object);
+ g_assert_not_reached ();
+ }
}
return res;
}
static gpointer try_more_restore_tramp = NULL;
static gpointer restore_stack_protection_tramp = NULL;
-static MonoUnhandledExceptionFunc unhandled_exception_hook = NULL;
-static gpointer unhandled_exception_hook_data = NULL;
-
static void try_more_restore (void);
static void restore_stack_protection (void);
static void mono_walk_stack_full (MonoJitStackWalk func, MonoContext *start_ctx, MonoDomain *domain, MonoJitTlsData *jit_tls, MonoLMF *lmf, MonoUnwindOptions unwind_options, gpointer user_data);
#endif
}
-void
-mono_install_unhandled_exception_hook (MonoUnhandledExceptionFunc func, gpointer user_data)
-{
- unhandled_exception_hook = func;
- unhandled_exception_hook_data = user_data;
-}
-
-void
-mono_invoke_unhandled_exception_hook (MonoObject *exc)
-{
- if (unhandled_exception_hook) {
- unhandled_exception_hook (exc, unhandled_exception_hook_data);
- } else {
- MonoError inner_error;
- MonoObject *other = NULL;
- MonoString *str = mono_object_try_to_string (exc, &other, &inner_error);
- char *msg = NULL;
-
- if (str && is_ok (&inner_error)) {
- msg = mono_string_to_utf8_checked (str, &inner_error);
- }
- if (!is_ok (&inner_error)) {
- msg = g_strdup_printf ("Nested exception while formatting original exception");
- mono_error_cleanup (&inner_error);
- } else if (other) {
- char *original_backtrace = mono_exception_get_managed_backtrace ((MonoException*)exc);
- char *nested_backtrace = mono_exception_get_managed_backtrace ((MonoException*)other);
-
- msg = g_strdup_printf ("Nested exception detected.\nOriginal Exception: %s\nNested exception:%s\n",
- original_backtrace, nested_backtrace);
-
- g_free (original_backtrace);
- g_free (nested_backtrace);
- } else {
- msg = g_strdup ("Nested exception trying to figure out what went wrong");
- }
- mono_runtime_printf_err ("[ERROR] FATAL UNHANDLED EXCEPTION: %s", msg);
- g_free (msg);
-#if defined(HOST_IOS)
- g_assertion_message ("Terminating runtime due to unhandled exception");
-#else
- exit (mono_environment_exitcode_get ());
-#endif
- }
-
- g_assert_not_reached ();
-}
-
/*
* mono_restore_context:
*
MonoObject *target = mono_gchandle_get_target (jit_tls->thrown_exc);
mono_unhandled_exception (target);
+ // AK: should we call mono_invoke_unhandled_exception_hook here?
exit (mono_environment_exitcode_get ());
}
MonoString **file, gint32 *line, gint32 *column);
void mono_set_cast_details (MonoClass *from, MonoClass *to);
-/* Installs a function which is called when the runtime encounters an unhandled exception.
- * This hook isn't expected to return.
- * If no hook has been installed, the runtime will print a message before aborting.
- */
-typedef void (*MonoUnhandledExceptionFunc) (MonoObject *exc, gpointer user_data);
-MONO_API void mono_install_unhandled_exception_hook (MonoUnhandledExceptionFunc func, gpointer user_data);
-void mono_invoke_unhandled_exception_hook (MonoObject *exc);
-
void mono_decompose_typechecks (MonoCompile *cfg);
/* Dominator/SSA methods */
void mono_compile_dominator_info (MonoCompile *cfg, int dom_flags);