Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Separate the dummy implementation of the backtraces into its own file (backtrace_dumm...
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 22 Jan 2008 16:13:34 +0000 (16:13 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 22 Jan 2008 16:13:34 +0000 (16:13 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5213 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/Makefile.am
src/xbt/backtrace_dummy.c [new file with mode: 0644]
src/xbt/backtrace_linux.c
src/xbt/backtrace_windows.c
src/xbt/ex.c
src/xbt/xbt_main.c

index 4a6794a..02fdd3e 100644 (file)
@@ -36,7 +36,7 @@ EXTRA_DIST= \
         xbt/xbt_jcontext.h \
        xbt/log_private.h \
        xbt/ex_interface.h \
-        xbt/backtrace_linux.c xbt/backtrace_windows.c \
+        xbt/backtrace_linux.c xbt/backtrace_windows.c xbt/backtrace_dummy.c \
         \
        surf/maxmin_private.h \
        surf/trace_mgr_private.h \
diff --git a/src/xbt/backtrace_dummy.c b/src/xbt/backtrace_dummy.c
new file mode 100644 (file)
index 0000000..8efe729
--- /dev/null
@@ -0,0 +1,20 @@
+/* $Id: ex_interface.h 3782 2007-07-14 09:11:06Z mquinson $ */
+
+/* backtrace_dummy -- stubs of this module for non-supported archs          */
+
+/* Copyright (c) 2003-2008, Da SimGrid team. 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. */
+
+#include "xbt/ex.h"
+#include "xbt/ex_private.h"
+
+/* Module creation/destruction */
+void xbt_backtrace_init(void) { }
+
+void xbt_backtrace_exit(void) { }
+
+/* create a backtrace in the given exception */
+void xbt_ex_setup_backtrace(xbt_ex_t *e)  { }
+
index 2bc22c5..a74a129 100644 (file)
 
 extern char **environ;          /* the environment, as specified by the opengroup */
 
+/* Module creation/destruction: nothing to do on linux */
+void xbt_backtrace_init(void) { }
+void xbt_backtrace_exit(void) { }
+
 void xbt_ex_setup_backtrace(xbt_ex_t * e)
 {
   int i;
index 3d06697..a6e2ded 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <dbghelp.h>
 
+
 /* Pointer function to SymInitialize() */
 typedef BOOL(WINAPI * xbt_pfn_sym_initialize_t) (HANDLE, PSTR, BOOL);
 
@@ -70,11 +71,94 @@ typedef struct s_xbt_debug_help {
 /* the address to the unique reference to the debug help library interface */
 static xbt_debug_hlp_t dbg_hlp = NULL;
 
-/* initialize the debug help library */
-static int dbg_hlp_init(HANDLE process_handle);
+/* Module creation/destruction: nothing to do on linux */
+void xbt_backtrace_init(void) { 
+  HANDLE process_handle = GetCurrentProcess();
+
+  if (dbg_hlp) {
+    /* debug help is already loaded */
+    return;
+  }
+
+  /* allocation */
+  dbg_hlp = xbt_new0(s_xbt_debug_hlp_t, 1);
+
+  /* load the library */
+  dbg_hlp->instance = LoadLibraryA("Dbghelp.dll");
+
+  if (!dbg_hlp->instance) {
+    free(dbg_hlp);
+    dbg_hlp = NULL;
+    return;
+  }
+  /* get the pointers to debug help library exported functions */
+  dbg_hlp->sym_initialize =
+    (xbt_pfn_sym_initialize_t) GetProcAddress(dbg_hlp->instance, "SymInitialize");
+
+  dbg_hlp->sym_cleanup = 
+    (xbt_pfn_sym_cleanup_t) GetProcAddress(dbg_hlp->instance, "SymCleanup");
 
-/* finalize the debug help library */
-static int dbg_hlp_finalize(void);
+  dbg_hlp->sym_function_table_access =
+    (xbt_pfn_sym_function_table_access_t) GetProcAddress(dbg_hlp->instance, "SymFunctionTableAccess");
+
+  dbg_hlp->sym_get_line_from_addr =
+    (xbt_pfn_sym_get_line_from_addr_t) GetProcAddress(dbg_hlp->instance, "SymGetLineFromAddr");
+
+  dbg_hlp->sym_get_module_base =
+    (xbt_pfn_sym_get_module_base_t) GetProcAddress(dbg_hlp->instance, "SymGetModuleBase");
+
+  dbg_hlp->sym_get_options =
+    (xbt_pfn_sym_get_options_t) GetProcAddress(dbg_hlp->instance, "SymGetOptions");
+
+  dbg_hlp->sym_get_sym_from_addr =
+    (xbt_pfn_sym_get_sym_from_addr_t) GetProcAddress(dbg_hlp->instance, "SymGetSymFromAddr");
+
+  dbg_hlp->sym_set_options =
+    (xbt_pfn_sym_set_options_t) GetProcAddress(dbg_hlp->instance, "SymSetOptions");
+
+  dbg_hlp->stack_walk =
+    (xbt_pfn_stack_walk_t) GetProcAddress(dbg_hlp->instance, "StackWalk");
+
+  /* Check that everything worked well */
+  if (!dbg_hlp->sym_initialize ||
+      !dbg_hlp->sym_cleanup ||
+      !dbg_hlp->sym_function_table_access || 
+      !dbg_hlp->sym_get_line_from_addr ||
+      !dbg_hlp->sym_get_module_base ||
+      !dbg_hlp->sym_get_options ||
+      !dbg_hlp->sym_get_sym_from_addr ||
+      !dbg_hlp->sym_set_options ||
+      !dbg_hlp->stack_walk
+      ) {
+    FreeLibrary(dbg_hlp->instance);
+    free(dbg_hlp);
+    dbg_hlp = NULL;
+    return;
+  }
+
+  dbg_hlp->process_handle = process_handle;
+
+  (*(dbg_hlp->sym_set_options)) ((*(dbg_hlp->sym_get_options)) () |
+                                 SYMOPT_LOAD_LINES | SYMOPT_DEFERRED_LOADS);
+
+  if (!(*(dbg_hlp->sym_initialize)) (dbg_hlp->process_handle, 0, 1)) {
+    FreeLibrary(dbg_hlp->instance);
+    free(dbg_hlp);
+    dbg_hlp = NULL;
+  }
+}
+void xbt_backtrace_exit(void) { 
+  if (!dbg_hlp)
+    return;
+
+  if ((dbg_hlp->sym_cleanup) (dbg_hlp->process_handle))
+    FreeLibrary(dbg_hlp->instance);
+
+
+  free(dbg_hlp);
+  dbg_hlp = NULL;
+}
 
 /*
  * backtrace() function.
@@ -145,8 +229,6 @@ int backtrace(void **buffer, int size)
   _asm mov context.Esp, eax
   _asm mov context.Ebp, ebp 
 
-  dbg_hlp_init(GetCurrentProcess());
-
   if ((NULL == dbg_hlp) || (size <= 0) || (NULL == buffer)) {
     errno = EINVAL;
     return 0;
@@ -280,100 +362,3 @@ char **backtrace_symbols(void *const *buffer, int size)
 
   return strings;
 }
-
-static int dbg_hlp_init(HANDLE process_handle)
-{
-  if (dbg_hlp) {
-    /* debug help is already loaded */
-    return 0;
-  }
-
-  /* allocation */
-  dbg_hlp = xbt_new0(s_xbt_debug_hlp_t, 1);
-
-  /* load the library */
-  dbg_hlp->instance = LoadLibraryA("Dbghelp.dll");
-
-  if (!dbg_hlp->instance) {
-    free(dbg_hlp);
-    dbg_hlp = NULL;
-    return (int) GetLastError();
-  }
-  /* get the pointers to debug help library exported functions */
-  dbg_hlp->sym_initialize =
-    (xbt_pfn_sym_initialize_t) GetProcAddress(dbg_hlp->instance, "SymInitialize");
-
-  dbg_hlp->sym_cleanup = 
-    (xbt_pfn_sym_cleanup_t) GetProcAddress(dbg_hlp->instance, "SymCleanup");
-
-  dbg_hlp->sym_function_table_access =
-    (xbt_pfn_sym_function_table_access_t) GetProcAddress(dbg_hlp->instance, "SymFunctionTableAccess");
-
-  dbg_hlp->sym_get_line_from_addr =
-    (xbt_pfn_sym_get_line_from_addr_t) GetProcAddress(dbg_hlp->instance, "SymGetLineFromAddr");
-
-  dbg_hlp->sym_get_module_base =
-    (xbt_pfn_sym_get_module_base_t) GetProcAddress(dbg_hlp->instance, "SymGetModuleBase");
-
-  dbg_hlp->sym_get_options =
-    (xbt_pfn_sym_get_options_t) GetProcAddress(dbg_hlp->instance, "SymGetOptions");
-
-  dbg_hlp->sym_get_sym_from_addr =
-    (xbt_pfn_sym_get_sym_from_addr_t) GetProcAddress(dbg_hlp->instance, "SymGetSymFromAddr");
-
-  dbg_hlp->sym_set_options =
-    (xbt_pfn_sym_set_options_t) GetProcAddress(dbg_hlp->instance, "SymSetOptions");
-
-  dbg_hlp->stack_walk =
-    (xbt_pfn_stack_walk_t) GetProcAddress(dbg_hlp->instance, "StackWalk");
-
-  /* Check that everything worked well */
-  if (!dbg_hlp->sym_initialize ||
-      !dbg_hlp->sym_cleanup ||
-      !dbg_hlp->sym_function_table_access || 
-      !dbg_hlp->sym_get_line_from_addr ||
-      !dbg_hlp->sym_get_module_base ||
-      !dbg_hlp->sym_get_options ||
-      !dbg_hlp->sym_get_sym_from_addr ||
-      !dbg_hlp->sym_set_options ||
-      !dbg_hlp->stack_walk
-      ) {
-    FreeLibrary(dbg_hlp->instance);
-    free(dbg_hlp);
-    dbg_hlp = NULL;
-    return (int) GetLastError();
-  }
-
-  dbg_hlp->process_handle = process_handle;
-
-  (*(dbg_hlp->sym_set_options)) ((*(dbg_hlp->sym_get_options)) () |
-                                 SYMOPT_LOAD_LINES | SYMOPT_DEFERRED_LOADS);
-
-  if (!(*(dbg_hlp->sym_initialize)) (dbg_hlp->process_handle, 0, 1)) {
-    FreeLibrary(dbg_hlp->instance);
-    free(dbg_hlp);
-    dbg_hlp = NULL;
-    return (int) GetLastError();
-  }
-
-
-  return 0;
-}
-
-static int dbg_hlp_finalize(void)
-{
-  if (!dbg_hlp)
-    return EINVAL;
-
-  if (!(*(dbg_hlp->sym_cleanup)) (dbg_hlp->process_handle))
-    return (int) GetLastError();
-
-  if (!FreeLibrary(dbg_hlp->instance))
-    return (int) GetLastError();
-
-  free(dbg_hlp);
-  dbg_hlp = NULL;
-
-  return 0;
-}
index 1879b8b..365c922 100644 (file)
@@ -18,6 +18,7 @@
 #include "xbt/ex.h"
 #include "xbt/str.h"
 #include "xbt/module.h" /* xbt_binary_name */
+#include "xbt_modinter.h" /* backtrace initialization headers */
 #include "xbt/synchro.h" /* xbt_thread_self */
 
 #include "gras/Virtu/virtu_interface.h" /* gras_os_myname */
@@ -96,8 +97,7 @@ void xbt_backtrace_display_current(void) {
 #elif (defined(WIN32) && defined (_M_IX86))
 # include "backtrace_windows.c"
 #else
-void xbt_ex_setup_backtrace(xbt_ex_t *e)  {
-}
+# include "backtrace_dummy.c"
 #endif
 
 /** @brief shows an exception content and the associated stack if available */
index 6023ad0..bba945c 100644 (file)
@@ -35,6 +35,7 @@ xbt_init(int *argc, char **argv) {
   srand((unsigned int)time(NULL));
   VERB0("Initialize XBT");
   
+  xbt_backtrace_init();
   xbt_log_init(argc,argv);
   xbt_os_thread_mod_init();
   xbt_context_mod_init();
@@ -50,6 +51,7 @@ xbt_exit(){
     xbt_context_mod_exit();
     xbt_os_thread_mod_exit();
     xbt_log_exit();
+    xbt_backtrace_exit();
   }
    
   if (xbt_initialized == 0)