Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Sanitize backtrace naming space
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 14 Jul 2007 09:11:06 +0000 (09:11 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 14 Jul 2007 09:11:06 +0000 (09:11 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3782 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/xbt/context.c
src/xbt/ex.c
src/xbt/ex_interface.h
src/xbt/log.c
src/xbt/xbt_log_layout_format.c

index d332492..f0d1de3 100644 (file)
@@ -14,6 +14,7 @@
 #include "xbt/log.h"
 #include "xbt/dynar.h"
 #include "xbt/xbt_os_thread.h"
+#include "xbt/ex_interface.h"
 
 #ifdef CONTEXT_THREADS
  /* This file (context.c) is only loaded in libsimgrid, not libgras.
index cfd8991..c2e2e59 100644 (file)
@@ -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 <rse@engelschall.com>       */
 /*  Copyright (c) 2002-2004 The OSSP Project <http://www.ossp.org/>         */
 /*  Copyright (c) 2002-2004 Cable & Wireless <http://www.cw.com/>           */
 #include "portable.h" /* execinfo when available */
 #include "xbt/ex.h"
 #include "xbt/module.h" /* xbt_binary_name */
-#include "xbt/ex_interface.h"
 
 #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) {
     static ex_ctx_t ctx = XBT_CTX_INITIALIZER;
@@ -31,27 +30,45 @@ ex_ctx_t *__xbt_ex_ctx_default(void) {
     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; i<e.used; i++) /* no need to display "xbt_display_backtrace" */
-    fprintf(stderr,"%s\n",e.bt_strings[i]);
+void xbt_backtrace_display(xbt_ex_t *e) {
+#if defined(HAVE_EXECINFO_H) && defined(HAVE_POPEN) && defined(ADDR2LINE)
+  int i;
 
-  e.msg=NULL;
-  e.remote=0;
-  xbt_ex_free(e);
+  if (e->used == 0) {
+     fprintf(stderr,"(backtrace not set)\n");
+  } else {     
+     fprintf(stderr,"Backtrace:\n");
+     for (i=1; i<e->used; 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)  {
index e5cb172..89ebbcf 100644 (file)
@@ -1,9 +1,10 @@
 /* $Id$ */
 
 /* ex -- exception handling                                                 */
-/* This file is not to be loaded from anywhere but ex.c                     */
+/* This file is to loaded in any location defining exception handlers       */
+/* (such as context.c) or in gras transport layer, to exchange them.        */
 
-/* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
+/* Copyright (c) 2003, 2004, 2007 Martin Quinson. All rights reserved.      */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 #ifndef _XBT_EX_INTERFACE_H_
 #define _XBT_EX_INTERFACE_H_
 
+#include "xbt/ex.h"
+/* The display made by an uncatched exception */
+void xbt_ex_display(xbt_ex_t *e);
+
+/* Change raw libc symbols to file names and line numbers */
 void xbt_ex_setup_backtrace(xbt_ex_t *e);
 
 #endif  /* _XBT_EX_INTERFACE_H_ */
index 80b97c1..dafba20 100644 (file)
@@ -571,7 +571,7 @@ void _xbt_log_event_log( xbt_log_event_t ev, const char *fmt, ...) {
      va_start(ev->ap, fmt);
      vfprintf(stderr,fmt,ev->ap);
      va_end(ev->ap);
-     xbt_backtrace_display();
+     xbt_backtrace_display_current();
      return;
   }
    
index 27ac36b..fc206f1 100644 (file)
@@ -12,7 +12,6 @@
 #include "xbt/log.h"
 #include "gras/virtu.h"
 #include <stdio.h>
-#include "xbt/ex_interface.h" /* backtraces */
 
 extern const char *xbt_log_priority_names[7];
 
@@ -139,7 +138,7 @@ static char *xbt_log_layout_format_doit(xbt_log_layout_t l,
          e.bt_strings = NULL;
          e.msg=NULL;
          e.remote=0;
-         xbt_ex_setup_backtrace(&e);
+         xbt_backtrace_current(&e);
          if (*q=='B') {
             if (precision == -1)
               p += sprintf(p,"%s",e.bt_strings[2]+8);