Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
define out backtrace related stuff for portability
[simgrid.git] / include / error.h
index 58c89ad..8505083 100644 (file)
@@ -15,8 +15,9 @@
 #include <stddef.h>    /* offsetof() */
 #include <sys/types.h>  /* size_t */
 #include <stdarg.h>
+#ifdef HAVE_EXECINFO_H
 #include <execinfo.h>  /* to print the backtrace */
-
+#endif
 
 /* C++ users need love */
 #ifndef BEGIN_DECL
@@ -52,11 +53,19 @@ typedef enum {
 
 /*@observer@*/ const char *gras_error_name(gras_error_t errcode);
 
-#define TRY(a) if ((errcode=a) != no_error) return errcode
+#define TRY(a) do {                                     \
+  if ((errcode=a) != no_error) {                        \
+     fprintf (stderr, "%s:%d: '%s' error raising...\n", \
+            __FILE__,__LINE__,                         \
+             gras_error_name(errcode));                 \
+     return errcode;                                    \
+  } } while (0)
+   
 #define TRYCATCH(a,b) if ((errcode=a) != no_error && errcode !=b) return errcode
 #define TRYFAIL(a) do {                                        \
   if ((errcode=a) != no_error) {                               \
-     fprintf(stderr,"Got '%s' error !\n",                      \
+     fprintf(stderr,"%s:%d: Got '%s' error !\n",               \
+            __FILE__,__LINE__,                                \
              gras_error_name(errcode));                        \
      fflush(stdout);                                           \
      abort();                                                  \
@@ -80,6 +89,7 @@ typedef enum {
   }                                                            \
 } while(0)
 
+#if 0 /* FIXME: We don't use backtrace. Drop it? */
 #define _GRAS_ERR_PRE do {                                     \
  void *_gs_array[30];                                          \
   size_t _gs_size= backtrace (_gs_array, 30);                  \
@@ -93,6 +103,12 @@ typedef enum {
   return code;                                                 \
 } while (0)
 
+#else
+#define _GRAS_ERR_PRE do {
+#define _GRAS_ERR_POST(code)                                   \
+  return code;                                                 \
+} while (0)
+#endif
 
 #define RAISE0(code,fmt) _GRAS_ERR_PRE     \
   fprintf(stderr,"%s:%d:%s: " fmt "\n",    \