X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c2b67da53caa5f63793426f332a783d00fc5ccf2..4725d7a4bc5ac1fdae3e86222cdc23eaaf6fb226:/src/xbt/ex.c diff --git a/src/xbt/ex.c b/src/xbt/ex.c index c93ea855b2..7c0714fcf8 100644 --- a/src/xbt/ex.c +++ b/src/xbt/ex.c @@ -25,20 +25,20 @@ #include "xbt/ex_interface.h" #undef HAVE_BACKTRACE -#if defined(HAVE_EXECINFO_H) && defined(HAVE_POPEN) && defined(ADDR2LINE) +#if defined(HAVE_EXECINFO_H) && defined(HAVE_POPEN) && defined(ADDR2LINE) # define HAVE_BACKTRACE 1 /* Hello linux box */ #endif #if defined(WIN32) && defined(_M_IX86) && !defined(__GNUC__) # define HAVE_BACKTRACE 1 /* Hello x86 windows box */ -#endif - +#endif + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_ex,xbt,"Exception mecanism"); /* default __ex_ctx callback function */ ex_ctx_t *__xbt_ex_ctx_default(void) { - /* Don't scream: this is a default which is never used (so, yes, + /* Don't scream: this is a default which is never used (so, yes, there is one setjump container by running entity). This default gets overriden in xbt/xbt_os_thread.c so that it works in @@ -47,10 +47,10 @@ ex_ctx_t *__xbt_ex_ctx_default(void) { It also gets overriden in xbt/context.c when using ucontextes (as well as in Java for now, but after the java overhaul, it will get cleaned out) - */ - static ex_ctx_t ctx = XBT_CTX_INITIALIZER; + */ + static ex_ctx_t ctx = XBT_CTX_INITIALIZER; - return &ctx; + return &ctx; } /* Change raw libc symbols to file names and line numbers */ @@ -58,24 +58,24 @@ void xbt_ex_setup_backtrace(xbt_ex_t *e); void xbt_backtrace_display(xbt_ex_t *e) { xbt_ex_setup_backtrace(e); - + #ifdef HAVE_BACKTRACE if (e->used == 0) { - fprintf(stderr,"(backtrace not set)\n"); - } else { - int i; - - fprintf(stderr,"Backtrace (displayed in thread %p):\n", - (void*)xbt_thread_self()); - for (i=1; iused; i++) /* no need to display "xbt_display_backtrace" */ - fprintf(stderr,"---> %s\n",e->bt_strings[i] +4); + fprintf(stderr,"(backtrace not set)\n"); + } else { + int i; + + fprintf(stderr,"Backtrace (displayed in thread %p):\n", + (void*)xbt_thread_self()); + for (i=1; iused; i++) /* no need to display "xbt_display_backtrace" */ + fprintf(stderr,"---> %s\n",e->bt_strings[i] +4); } - + /* don't fool xbt_ex_free with uninitialized msg field */ e->msg=NULL; e->remote=0; xbt_ex_free(*e); -#else +#else ERROR0("No backtrace on this arch"); #endif @@ -104,12 +104,12 @@ void xbt_ex_display(xbt_ex_t *e) { thrower = bprintf(" on host %s(%d)",e->host,e->pid); fprintf(stderr, - "** SimGrid: UNCAUGHT EXCEPTION received on %s(%d): category: %s; value: %d\n" - "** %s\n" - "** Thrown by %s()%s\n", - gras_os_myname(),(*xbt_getpid)(), - xbt_ex_catname(e->category), e->value, e->msg, - e->procname,thrower?thrower:" in this process"); + "** SimGrid: UNCAUGHT EXCEPTION received on %s(%d): category: %s; value: %d\n" + "** %s\n" + "** Thrown by %s()%s\n", + gras_os_myname(),(*xbt_getpid)(), + xbt_ex_catname(e->category), e->value, e->msg, + e->procname,thrower?thrower:" in this process"); CRITICAL1("%s",e->msg); if (thrower) @@ -122,15 +122,15 @@ void xbt_ex_display(xbt_ex_t *e) { /* We have everything to build neat backtraces */ { int i; - + fprintf(stderr,"\n"); for (i=0; iused; i++) fprintf(stderr,"%s\n",e->bt_strings[i]); - + } #else - fprintf(stderr," at %s:%d:%s (no backtrace available on that arch)\n", - e->file,e->line,e->func); + fprintf(stderr," at %s:%d:%s (no backtrace available on that arch)\n", + e->file,e->line,e->func); #endif xbt_ex_free(*e); } @@ -159,10 +159,10 @@ void xbt_ex_free(xbt_ex_t e) { free(e.host); } - if (e.bt_strings) { - for (i=0; ifirst = cp1; cp2 = mallocex(TOOBIG); @@ -341,7 +341,7 @@ static void bad_example(void) { } #endif typedef struct {char *first;} global_context_t; - + static void good_example(void) { global_context_t *global_context=malloc(sizeof(global_context_t)); xbt_ex_t ex; @@ -362,9 +362,9 @@ static void good_example(void) { } CLEANUP { /*04*/ printf("cp3=%s", cp3 == NULL /*02*/ ? "" : cp3); if (cp3 != NULL) - free(cp3); + free(cp3); if (cp2 != NULL) - free(cp2); + free(cp2); /*05 cp1 was given away */ } CATCH(ex) { /*05 global context untouched */