#include <execinfo.h>
#endif
+#ifndef PLATFORM_WIN32
+#include <sys/types.h>
+#include <unistd.h>
+#endif
+
#include <mono/metadata/appdomain.h>
#include <mono/metadata/tabledefs.h>
#include <mono/metadata/threads.h>
#include <mono/metadata/exception.h>
#include <mono/metadata/gc-internal.h>
#include <mono/metadata/mono-debug.h>
+#include <mono/metadata/profiler.h>
#include "mini.h"
#include "trace.h"
void
mono_walk_stack (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoContext *start_ctx, MonoStackFrameWalk func, gpointer user_data)
{
- MonoLMF *lmf = jit_tls->lmf;
+ MonoLMF *lmf = mono_get_lmf ();
MonoJitInfo *ji, rji;
gint native_offset;
gboolean managed;
ctx = *start_ctx;
- while (MONO_CONTEXT_GET_BP (&ctx) < jit_tls->end_of_stack) {
+ while (MONO_CONTEXT_GET_SP (&ctx) < jit_tls->end_of_stack) {
/*
* FIXME: mono_find_jit_info () will need to be able to return a different
* MonoDomain when apddomain transitions are found on the stack.
{
MonoDomain *domain = mono_domain_get ();
MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
- MonoLMF *lmf = jit_tls->lmf;
+ MonoLMF *lmf = mono_get_lmf ();
MonoJitInfo *ji, rji;
gint native_offset, il_offset;
gboolean managed;
{
MonoDomain *domain = mono_domain_get ();
MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
- MonoLMF *lmf = jit_tls->lmf;
+ MonoLMF *lmf = mono_get_lmf ();
MonoJitInfo *ji, rji;
MonoContext ctx, new_ctx;
MonoDebugSourceLocation *location;
ctx = new_ctx;
- if (!ji || ji == (gpointer)-1 || MONO_CONTEXT_GET_BP (&ctx) >= jit_tls->end_of_stack)
+ if (!ji || ji == (gpointer)-1 || MONO_CONTEXT_GET_SP (&ctx) >= jit_tls->end_of_stack)
return FALSE;
/* skip all wrappers ??*/
static int (*call_filter) (MonoContext *, gpointer) = NULL;
static void (*restore_context) (void *);
MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
- MonoLMF *lmf = jit_tls->lmf;
+ MonoLMF *lmf = mono_get_lmf ();
MonoArray *initial_trace_ips = NULL;
GList *trace_ips = NULL;
MonoException *mono_ex;
has_dynamic_methods = TRUE;
if (stack_overflow)
- free_stack = (guint8*)(MONO_CONTEXT_GET_BP (ctx)) - (guint8*)(MONO_CONTEXT_GET_BP (&initial_ctx));
+ free_stack = (guint8*)(MONO_CONTEXT_GET_SP (ctx)) - (guint8*)(MONO_CONTEXT_GET_SP (&initial_ctx));
else
free_stack = 0xffffff;
/* catch block */
if ((ei->flags == MONO_EXCEPTION_CLAUSE_NONE) || (ei->flags == MONO_EXCEPTION_CLAUSE_FILTER)) {
- /* store the exception object in cfg->excvar */
- g_assert (ei->exvar_offset);
+ /* store the exception object in bp + ei->exvar_offset */
*((gpointer *)(gpointer)((char *)MONO_CONTEXT_GET_BP (ctx) + ei->exvar_offset)) = obj;
}
g_print ("EXCEPTION: catch found at clause %d of %s\n", i, mono_method_full_name (ji->method, TRUE));
mono_debugger_handle_exception (ei->handler_start, MONO_CONTEXT_GET_SP (ctx), obj);
MONO_CONTEXT_SET_IP (ctx, ei->handler_start);
- jit_tls->lmf = lmf;
+ *(mono_get_lmf_addr ()) = lmf;
if (gc_disabled)
mono_gc_enable ();
}
if (!test_only && ei->try_start <= MONO_CONTEXT_GET_IP (ctx) &&
MONO_CONTEXT_GET_IP (ctx) < ei->try_end &&
- (ei->flags & MONO_EXCEPTION_CLAUSE_FINALLY)) {
+ (ei->flags == MONO_EXCEPTION_CLAUSE_FAULT)) {
+ if (mono_trace_is_enabled () && mono_trace_eval (ji->method))
+ g_print ("EXCEPTION: fault clause %d of %s\n", i, mono_method_full_name (ji->method, TRUE));
+ mono_debugger_handle_exception (ei->handler_start, MONO_CONTEXT_GET_SP (ctx), obj);
+ call_filter (ctx, ei->handler_start);
+ }
+ if (!test_only && ei->try_start <= MONO_CONTEXT_GET_IP (ctx) &&
+ MONO_CONTEXT_GET_IP (ctx) < ei->try_end &&
+ (ei->flags == MONO_EXCEPTION_CLAUSE_FINALLY)) {
if (mono_trace_is_enabled () && mono_trace_eval (ji->method))
g_print ("EXCEPTION: finally clause %d of %s\n", i, mono_method_full_name (ji->method, TRUE));
mono_debugger_handle_exception (ei->handler_start, MONO_CONTEXT_GET_SP (ctx), obj);
}
}
}
+ if (!test_only)
+ if (mono_profiler_get_events () && MONO_PROFILE_ENTER_LEAVE)
+ mono_profiler_method_leave (ji->method);
}
*ctx = new_ctx;
mono_gc_enable ();
if (!test_only) {
- jit_tls->lmf = lmf;
+ *(mono_get_lmf_addr ()) = lmf;
if (IS_ON_SIGALTSTACK (jit_tls)) {
/* Switch back to normal stack */
static int (*call_filter) (MonoContext *, gpointer) = NULL;
MonoDomain *domain = mono_domain_get ();
MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
- MonoLMF *lmf = jit_tls->lmf;
+ MonoLMF *lmf = mono_get_lmf ();
MonoContext ctx, new_ctx;
MonoJitInfo *ji, rji;
int i;
#ifndef PLATFORM_WIN32
struct sigaction sa;
#endif
- const char *signal_str = (signal == SIGSEGV) ? "SIGSEGV" : "SIGABRT";
-
if (handling_sigsegv)
return;
/* To prevent infinite loops when the stack walk causes a crash */
handling_sigsegv = TRUE;
- /*
- * A SIGSEGV indicates something went very wrong so we can no longer depend
- * on anything working. So try to print out lots of diagnostics, starting
- * with ones which have a greater chance of working.
- */
- fprintf (stderr,
- "\n"
- "=================================================================\n"
- "Got a %s while executing native code. This usually indicates\n"
- "a fatal error in the mono runtime or one of the native libraries \n"
- "used by your application.\n"
- "=================================================================\n"
- "\n", signal_str);
-
fprintf (stderr, "Stacktrace:\n\n");
mono_jit_walk_stack (print_stack_frame, TRUE, stderr);
{
void *array [256];
char **names;
+ char cmd [1024];
int i, size;
+ gchar *out, *err;
+ gint exit_status;
+ const char *signal_str = (signal == SIGSEGV) ? "SIGSEGV" : "SIGABRT";
fprintf (stderr, "\nNative stacktrace:\n\n");
fprintf (stderr, "\t%s\n", names [i]);
}
free (names);
- }
fflush (stderr);
+
+ /* Try to get more meaningful information using gdb */
+
+#ifndef PLATFORM_WIN32
+ sprintf (cmd, "gdb --ex 'attach %ld' --ex 'info threads' --ex 'thread apply all bt' --batch", (long)getpid ());
+ {
+ int res = g_spawn_command_line_sync (cmd, &out, &err, &exit_status, NULL);
+
+ if (res) {
+ fprintf (stderr, "\nDebug info from gdb:\n\n");
+ fprintf (stderr, "%s\n", out);
+ }
+ }
+#endif
+ /*
+ * A SIGSEGV indicates something went very wrong so we can no longer depend
+ * on anything working. So try to print out lots of diagnostics, starting
+ * with ones which have a greater chance of working.
+ */
+ fprintf (stderr,
+ "\n"
+ "=================================================================\n"
+ "Got a %s while executing native code. This usually indicates\n"
+ "a fatal error in the mono runtime or one of the native libraries \n"
+ "used by your application.\n"
+ "=================================================================\n"
+ "\n", signal_str);
+
+ }
#endif
#ifndef PLATFORM_WIN32