Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Improve compilation time by epsilon by sharpening the includes (str.h loads dynar...
[simgrid.git] / src / xbt / ex.c
index c2e2e59..428080b 100644 (file)
@@ -16,7 +16,9 @@
 
 #include "portable.h" /* execinfo when available */
 #include "xbt/ex.h"
+#include "xbt/str.h"
 #include "xbt/module.h" /* xbt_binary_name */
+#include "xbt/synchro.h" /* xbt_thread_self */
 
 #include "gras/Virtu/virtu_interface.h" /* gras_os_myname */
 #include "xbt/ex_interface.h"
@@ -25,6 +27,16 @@ 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;
@@ -48,7 +60,8 @@ void xbt_backtrace_display(xbt_ex_t *e) {
   if (e->used == 0) {
      fprintf(stderr,"(backtrace not set)\n");
   } else {     
-     fprintf(stderr,"Backtrace:\n");
+     fprintf(stderr,"Backtrace (displayed in thread %p):\n",
+            (void*)xbt_thread_self());
      for (i=1; i<e->used; i++) /* no need to display "xbt_display_backtrace" */
        fprintf(stderr,"---> %s\n",e->bt_strings[i] +4);
   }
@@ -69,7 +82,9 @@ void xbt_backtrace_display_current(void) {
   xbt_backtrace_display(&e);
 }
 
+#ifndef WIN32
 extern char **environ; /* the environment, as specified by the opengroup */
+#endif
 
 void xbt_ex_setup_backtrace(xbt_ex_t *e)  {
 #if defined(HAVE_EXECINFO_H) && defined(HAVE_POPEN) && defined(ADDR2LINE)
@@ -106,7 +121,7 @@ void xbt_ex_setup_backtrace(xbt_ex_t *e)  {
     for (i=0; environ[i]; i++) {
       if (!strncmp("PATH=",environ[i], 5)) {   
        xbt_dynar_t path=xbt_str_split(environ[i] + 5, ":");
-       int cpt;
+       unsigned int cpt;
        char *data;
        xbt_dynar_foreach(path, cpt, data) {
          if (binary_name)
@@ -283,18 +298,17 @@ void xbt_ex_setup_backtrace(xbt_ex_t *e)  {
     free(addrs[i]);
      
     /* Mask the bottom of the stack */    
-    if (!strncmp("main",line_func,strlen("main"))) {
-       int j;
-       for (j=i+1; j<e->used; j++)
-        free(addrs[j]);
-       e->used = i+1;
-    }
-     
-    if (!strncmp("__context_wrapper",line_func,strlen("__context_wrapper"))) {
+    if (!strncmp("main",line_func,strlen("main")) ||
+       !strncmp("xbt_thread_context_wrapper",line_func,strlen("xbt_thread_context_wrapper"))) {
        int j;
        for (j=i+1; j<e->used; j++)
         free(addrs[j]);
        e->used = i;
+
+       if (!strncmp("xbt_thread_context_wrapper",line_func,strlen("xbt_thread_context_wrapper"))) {
+         e->used++;
+         e->bt_strings[i] = bprintf("**   (in a separate thread)");
+       }       
     }
      
     
@@ -311,7 +325,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"
@@ -354,8 +368,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) {