Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add Doxygen documentation for mallocators
[simgrid.git] / src / xbt / ex.c
index 3fc0eb4..48ab1de 100644 (file)
@@ -48,7 +48,7 @@ void xbt_backtrace_display(void) {
   e.remote=0;
   xbt_ex_free(e);
 #else 
-  fprintf(stderr,"No backtrace on this arch");
+  ERROR0("No backtrace on this arch");
 #endif
 }
 
@@ -72,7 +72,11 @@ void xbt_ex_setup_backtrace(xbt_ex_t *e)  {
 
   /* size (in char) of pointers on this arch */
   int addr_len=0;
-  
+
+  /* Some arches only have stubs of backtrace, no implementation (hppa comes to mind) */
+  if (!e->used)
+     return;
+   
   /* build the commandline */
   curr += sprintf(curr,"%s -f -e %s ",ADDR2LINE,xbt_binary_name);
   for (i=0; i<e->used;i++) {
@@ -109,7 +113,7 @@ void xbt_ex_setup_backtrace(xbt_ex_t *e)  {
       FILE *maps;
       char maps_buff[512];
 
-      long int addr,offset;
+      long int addr,offset=0;
       char *p,*p2;
 
       char *subcmd;
@@ -147,12 +151,15 @@ void xbt_ex_setup_backtrace(xbt_ex_t *e)  {
        DEBUG4("%#lx %s [%#lx-%#lx]",
               addr, found? "in":"out of",first,last);
       }
-      if (!found) 
-       CRITICAL0("Problem while reading the maps file");
-
       fclose(maps);
       free(maps_name);
 
+      if (!found) {
+       VERB0("Problem while reading the maps file. Following backtrace will be mangled.");
+       e->bt_strings[i] = bprintf("**   In ?? (%s)", backtrace[i]);
+       continue;
+      }
+
       /* Ok, Found the offset of the maps line containing the searched symbol. 
         We now need to substract this from the address we got from backtrace.
       */
@@ -209,10 +216,11 @@ void xbt_ex_display(xbt_ex_t *e)  {
   if (e->remote)
     bprintf(" on host %s(%ld)",e->host,e->pid);
 
+  CRITICAL1("%s",e->msg);
   fprintf(stderr,
          "** SimGrid: UNCAUGHT EXCEPTION received on %s(%ld): category: %s; value: %d\n"
          "** %s\n"
-         "** Thrown by %s()%s",
+         "** Thrown by %s()%s\n",
          gras_os_myname(),gras_os_getpid(),
          xbt_ex_catname(e->category), e->value, e->msg,
          e->procname,thrower?thrower:" in this process");
@@ -450,9 +458,10 @@ static void bad_example(void) {
   /* end_of_bad_example */
 }
 #endif
-
+typedef struct {char *first;} global_context_t;
+   
 static void good_example(void) {
-  struct {char*first;} *globalcontext;
+  global_context_t *global_context=malloc(sizeof(global_context_t));
   xbt_ex_t ex;
 
   /* GOOD_EXAMPLE */
@@ -462,7 +471,7 @@ static void good_example(void) {
     char * volatile /*03*/ cp3 = NULL /*02*/;
     TRY {
       cp1 = mallocex(SMALLAMOUNT);
-      globalcontext->first = cp1;
+      global_context->first = cp1;
       cp1 = NULL /*05 give away*/;
       cp2 = mallocex(TOOBIG);
       cp3 = mallocex(SMALLAMOUNT);