From ac9b849c157154d379961e139bf8e1a436eb0bc1 Mon Sep 17 00:00:00 2001 From: mquinson Date: Thu, 30 Mar 2006 23:16:27 +0000 Subject: [PATCH 1/1] Tweak things here and there so that we can propagate exceptions across the network on failed RPC git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2027 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/xbt/ex.h | 66 ++++++++++++++++++++++++++---------------------- src/xbt/ex.c | 29 ++++++++++++++++----- 2 files changed, 58 insertions(+), 37 deletions(-) diff --git a/include/xbt/ex.h b/include/xbt/ex.h index e8594e7e8f..1b92377d8d 100644 --- a/include/xbt/ex.h +++ b/include/xbt/ex.h @@ -232,14 +232,16 @@ typedef struct { xbt_errcat_t category; /**< category like HTTP (what went wrong) */ int value; /**< like errno (why did it went wrong) */ /* throw point */ - char *host; /* NULL for localhost; hostname:port if remote */ + char *host; /* NULL for localhost; hostname if remote */ + /* FIXME: host should be hostname:port[#thread] */ char *procname; char *file; /**< to be freed only for remote exceptions */ int line; char *func; /**< to be freed only for remote exceptions */ /* Backtrace */ - void *bt[XBT_BACKTRACE_SIZE]; int used; + char **bt_strings; /* only filed on display (or before the network propagation) */ + void *bt[XBT_BACKTRACE_SIZE]; } xbt_ex_t; /* declare the context type (private) */ @@ -253,30 +255,31 @@ typedef struct { #define XBT_CTX_INITIALIZER \ { NULL, 0, { /* content */ NULL, unknown_error, 0, \ /* throw point*/ NULL, NULL, NULL, 0, NULL,\ - /* backtrace */ {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL},0 } } + /* backtrace */ 0,NULL,{NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL} } } #define XBT_CTX_INITIALIZE(ctx) \ do { \ - (ctx)->ctx_mctx = NULL; \ - (ctx)->ctx_caught = 0; \ - (ctx)->ctx_ex.msg = NULL; \ - (ctx)->ctx_ex.category = unknown_error; \ - (ctx)->ctx_ex.value = 0; \ - (ctx)->ctx_ex.host = NULL; \ - (ctx)->ctx_ex.procname = NULL; \ - (ctx)->ctx_ex.file = NULL; \ - (ctx)->ctx_ex.line = 0; \ - (ctx)->ctx_ex.func = NULL; \ - (ctx)->ctx_ex.bt[0] = NULL; \ - (ctx)->ctx_ex.bt[1] = NULL; \ - (ctx)->ctx_ex.bt[2] = NULL; \ - (ctx)->ctx_ex.bt[3] = NULL; \ - (ctx)->ctx_ex.bt[4] = NULL; \ - (ctx)->ctx_ex.bt[5] = NULL; \ - (ctx)->ctx_ex.bt[6] = NULL; \ - (ctx)->ctx_ex.bt[7] = NULL; \ - (ctx)->ctx_ex.bt[8] = NULL; \ - (ctx)->ctx_ex.bt[9] = NULL; \ - (ctx)->ctx_ex.used = 0; \ + (ctx)->ctx_mctx = NULL; \ + (ctx)->ctx_caught = 0; \ + (ctx)->ctx_ex.msg = NULL; \ + (ctx)->ctx_ex.category = 0; \ + (ctx)->ctx_ex.value = 0; \ + (ctx)->ctx_ex.host = NULL; \ + (ctx)->ctx_ex.procname = NULL; \ + (ctx)->ctx_ex.file = NULL; \ + (ctx)->ctx_ex.line = 0; \ + (ctx)->ctx_ex.func = NULL; \ + (ctx)->ctx_ex.bt[0] = NULL; \ + (ctx)->ctx_ex.bt[1] = NULL; \ + (ctx)->ctx_ex.bt[2] = NULL; \ + (ctx)->ctx_ex.bt[3] = NULL; \ + (ctx)->ctx_ex.bt[4] = NULL; \ + (ctx)->ctx_ex.bt[5] = NULL; \ + (ctx)->ctx_ex.bt[6] = NULL; \ + (ctx)->ctx_ex.bt[7] = NULL; \ + (ctx)->ctx_ex.bt[8] = NULL; \ + (ctx)->ctx_ex.bt[9] = NULL; \ + (ctx)->ctx_ex.used = 0; \ + (ctx)->ctx_ex.bt_strings = NULL; \ } while (0) /* the exception context */ @@ -348,6 +351,14 @@ extern void __xbt_ex_terminate_default(xbt_ex_t *e); } \ else +#define DO_THROW(e) \ + /* deal with the exception */ \ + if (__xbt_ex_ctx()->ctx_mctx == NULL) \ + __xbt_ex_terminate((xbt_ex_t *)&(e)); /* not catched */\ + else \ + __ex_mctx_restore(__xbt_ex_ctx()->ctx_mctx); /* catched somewhere */ \ + abort()/* nope, stupid GCC, we won't survive a THROW (this won't be reached) */ + /** @brief Helper macro for THROWS0-6 * @hideinitializer * @@ -378,12 +389,7 @@ extern void __xbt_ex_terminate_default(xbt_ex_t *e); __xbt_ex_ctx()->ctx_ex.line = __LINE__; \ __xbt_ex_ctx()->ctx_ex.func = (char*)_XBT_FUNCTION; \ __xbt_ex_ctx()->ctx_ex.used = backtrace((void**)__xbt_ex_ctx()->ctx_ex.bt,XBT_BACKTRACE_SIZE);\ - /* deal with the exception */ \ - if (__xbt_ex_ctx()->ctx_mctx == NULL) \ - __xbt_ex_terminate((xbt_ex_t *)&(__xbt_ex_ctx()->ctx_ex)); /* not catched */\ - else \ - __ex_mctx_restore(__xbt_ex_ctx()->ctx_mctx); /* catched somewhere */ \ - abort();/* nope, stupid GCC, we won't survive a THROW (this won't be reached) */ \ + DO_THROW(__xbt_ex_ctx()->ctx_ex);\ } while (0) /** @brief Builds and throws an exception with a string taking no arguments diff --git a/src/xbt/ex.c b/src/xbt/ex.c index 8be446d5e3..18de35efee 100644 --- a/src/xbt/ex.c +++ b/src/xbt/ex.c @@ -35,6 +35,8 @@ #include "portable.h" /* execinfo when available */ #include "xbt/ex.h" +#include "gras/Virtu/virtu_interface.h" /* gras_os_myname */ + /* default __ex_ctx callback function */ ex_ctx_t *__xbt_ex_ctx_default(void) { static ex_ctx_t ctx = XBT_CTX_INITIALIZER; @@ -46,25 +48,24 @@ ex_ctx_t *__xbt_ex_ctx_default(void) { void xbt_ex_display(xbt_ex_t *e) { fprintf(stderr, - "** SimGrid: UNCAUGHT EXCEPTION: category: %s; value: %d\n" + "** SimGrid: UNCAUGHT EXCEPTION on %s: category: %s; value: %d\n" "** %s\n" "** Thrown by %s%s%s at %s:%d:%s\n", + gras_os_myname(), xbt_ex_catname(e->category), e->value, e->msg, - e->procname, (e->host?"@":""),(e->host?e->host:"localhost"), + e->procname, (e->host?"@":""),(e->host?e->host:""),//localhost"), e->file,e->line,e->func); #ifdef HAVE_EXECINFO_H { - char **strings; int i; fprintf(stderr,"** Backtrace:\n"); - strings = backtrace_symbols (e->bt, e->used); + if (!e->bt_strings) + e->bt_strings = backtrace_symbols (e->bt, e->used); for (i = 0; i < e->used; i++) - printf (" %s\n", strings[i]); - - free (strings); + printf (" %s\n", e->bt_strings[i]); } #endif } @@ -82,8 +83,22 @@ ex_ctx_cb_t __xbt_ex_ctx = &__xbt_ex_ctx_default; ex_term_cb_t __xbt_ex_terminate = &__xbt_ex_terminate_default; void xbt_ex_free(xbt_ex_t e) { + int i; + if (e.msg) free(e.msg); free(e.procname); + if (e.host) { + free(e.file); + free(e.func); + for (i=0; i