X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/7c49d0269c4163c8b4d8232dd7d43f21abea3a44..2a98e22685f02a89ca5ac78e20afa994ac36489a:/src/xbt/ex.c diff --git a/src/xbt/ex.c b/src/xbt/ex.c index cfd8991891..3cbbbcd9db 100644 --- a/src/xbt/ex.c +++ b/src/xbt/ex.c @@ -2,7 +2,7 @@ /* ex - Exception Handling (modified to fit into SimGrid from OSSP version) */ -/* Copyright (c) 2005-2006 Martin Quinson */ +/* Copyright (c) 2005, 2006, 2007 Martin Quinson */ /* Copyright (c) 2002-2004 Ralf S. Engelschall */ /* Copyright (c) 2002-2004 The OSSP Project */ /* Copyright (c) 2002-2004 Cable & Wireless */ @@ -17,41 +17,70 @@ #include "portable.h" /* execinfo when available */ #include "xbt/ex.h" #include "xbt/module.h" /* xbt_binary_name */ -#include "xbt/ex_interface.h" +#include "xbt/synchro.h" /* xbt_thread_self */ #include "gras/Virtu/virtu_interface.h" /* gras_os_myname */ +#include "xbt/ex_interface.h" 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, + there is one setjump container by running entity). + + This default gets overriden in xbt/xbt_os_thread.c so that it works in + real life and in simulation when using threads to implement the simulation + processes (ie, with pthreads and on windows). + + 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; return &ctx; } +/* Change raw libc symbols to file names and line numbers */ +void xbt_ex_setup_backtrace(xbt_ex_t *e); -/** \brief show the backtrace of the current point (lovely while debuging) */ -void xbt_backtrace_display(void) { +void xbt_backtrace_current(xbt_ex_t *e) { #if defined(HAVE_EXECINFO_H) && defined(HAVE_POPEN) && defined(ADDR2LINE) - xbt_ex_t e; - int i; + e->used = backtrace((void**)e->bt,XBT_BACKTRACE_SIZE); + e->bt_strings = NULL; + xbt_ex_setup_backtrace(e); +#endif +} - e.used = backtrace((void**)e.bt,XBT_BACKTRACE_SIZE); - e.bt_strings = NULL; - xbt_ex_setup_backtrace(&e); - for (i=1; iused == 0) { + fprintf(stderr,"(backtrace not set)\n"); + } else { + 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 ERROR0("No backtrace on this arch"); #endif } +/** \brief show the backtrace of the current point (lovely while debuging) */ +void xbt_backtrace_display_current(void) { + xbt_ex_t e; + xbt_backtrace_current(&e); + xbt_backtrace_display(&e); +} + extern char **environ; /* the environment, as specified by the opengroup */ void xbt_ex_setup_backtrace(xbt_ex_t *e) { @@ -294,7 +323,7 @@ void xbt_ex_display(xbt_ex_t *e) { char *thrower=NULL; if (e->remote) - bprintf(" on host %s(%d)",e->host,e->pid); + thrower = bprintf(" on host %s(%d)",e->host,e->pid); fprintf(stderr, "** SimGrid: UNCAUGHT EXCEPTION received on %s(%d): category: %s; value: %d\n" @@ -337,8 +366,8 @@ void __xbt_ex_terminate_default(xbt_ex_t *e) { } /* the externally visible API */ -XBT_PUBLIC_DATA(ex_ctx_cb_t) __xbt_ex_ctx = &__xbt_ex_ctx_default; -XBT_PUBLIC_DATA(ex_term_cb_t) __xbt_ex_terminate = &__xbt_ex_terminate_default; +XBT_EXPORT_NO_IMPORT(ex_ctx_cb_t) __xbt_ex_ctx = &__xbt_ex_ctx_default; +XBT_EXPORT_NO_IMPORT(ex_term_cb_t) __xbt_ex_terminate = &__xbt_ex_terminate_default; void xbt_ex_free(xbt_ex_t e) {