X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5b3677b425b9cc6949c1573d59ac772540cbf4b2..41c803093e7108f16bfb4cc7e2c41c52104c73c2:/src/xbt/ex.c diff --git a/src/xbt/ex.c b/src/xbt/ex.c index 4b0d7bdf1c..a54869ff9a 100644 --- a/src/xbt/ex.c +++ b/src/xbt/ex.c @@ -1,6 +1,6 @@ /* ex - Exception Handling */ -/* Copyright (c) 2005-2014. The SimGrid Team. +/* Copyright (c) 2005-2015. The SimGrid Team. * All rights reserved. */ /* Copyright (c) 2002-2004 Ralf S. Engelschall */ @@ -52,6 +52,8 @@ #include "xbt_modinter.h" /* backtrace initialization headers */ #include "xbt/ex_interface.h" +#include "simgrid/sg_config.h" /* Configuration mechanism of SimGrid */ + #undef HAVE_BACKTRACE #if defined(HAVE_EXECINFO_H) && defined(HAVE_POPEN) && defined(ADDR2LINE) @@ -133,6 +135,8 @@ void xbt_backtrace_display_current(void) void xbt_ex_display(xbt_ex_t * e) { char *thrower = NULL; + if (e->pid != xbt_getpid()) + thrower = bprintf(" on process %d",e->pid); fprintf(stderr, "** SimGrid: UNCAUGHT EXCEPTION received on %s(%d): category: %s; value: %d\n" @@ -144,6 +148,11 @@ void xbt_ex_display(xbt_ex_t * e) XBT_CRITICAL("%s", e->msg); xbt_free(thrower); + if (xbt_initialized==0 || smx_cleaned) { + fprintf(stderr, "Ouch. SimGrid is not initialized yet, or already closing. No backtrace available.\n"); + return; /* Not started yet or already closing. Trying to generate a backtrace would probably fail */ + } + if (!e->bt_strings) xbt_ex_setup_backtrace(e); @@ -153,8 +162,27 @@ void xbt_ex_display(xbt_ex_t * e) int i; fprintf(stderr, "\n"); - for (i = 0; i < e->used; i++) - fprintf(stderr, "%s\n", e->bt_strings[i]); + for (i = 0; i < e->used; i++) { + if (sg_cfg_get_boolean("exception/cutpath")) { + char* p = e->bt_strings[i]; + xbt_str_rtrim(p, ":0123456789"); + char* filename = strrchr(p, '/')+1; + char* end_of_message = strrchr(p, ' '); + + int length = strlen(p)-strlen(end_of_message); + char* dest = malloc(length); + + memcpy(dest, &p[0], length); + dest[length] = 0; + + fprintf(stderr, "%s %s\n", dest, filename); + + free(dest); + } + else { + fprintf(stderr, "%s\n", e->bt_strings[i]); + } + } } else #endif @@ -177,8 +205,7 @@ void __xbt_ex_terminate_default(xbt_ex_t * e) /* the externally visible API */ XBT_EXPORT_NO_IMPORT(xbt_running_ctx_fetcher_t) __xbt_running_ctx_fetch = &__xbt_ex_ctx_default; -XBT_EXPORT_NO_IMPORT(ex_term_cb_t) __xbt_ex_terminate = - &__xbt_ex_terminate_default; +XBT_EXPORT_NO_IMPORT(ex_term_cb_t) __xbt_ex_terminate = &__xbt_ex_terminate_default; void xbt_ex_free(xbt_ex_t e) @@ -311,7 +338,7 @@ XBT_TEST_UNIT("variables", test_variables, "variable value preservation") { xbt_ex_t ex; int r1; - int _XBT_GNUC_UNUSED r2; + int XBT_ATTRIB_UNUSED r2; int v1; volatile int v2;