Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into vmtrace
[simgrid.git] / src / xbt / backtrace_windows.c
index e658216..0ad381d 100644 (file)
@@ -86,27 +86,29 @@ void xbt_backtrace_preinit(void)
 
   /* get the pointers to debug help library exported functions */
   fun_initialize =
-    (fun_initialize_t) GetProcAddress(hlp_dbg_instance, "SymInitialize");
+      (fun_initialize_t) GetProcAddress(hlp_dbg_instance, "SymInitialize");
   fun_cleanup =
-    (fun_cleanup_t) GetProcAddress(hlp_dbg_instance, "SymCleanup");
+      (fun_cleanup_t) GetProcAddress(hlp_dbg_instance, "SymCleanup");
   fun_function_table_access =
-    (fun_function_table_access_t) GetProcAddress(hlp_dbg_instance,
-                                                 "SymFunctionTableAccess");
+      (fun_function_table_access_t) GetProcAddress(hlp_dbg_instance,
+                                                   "SymFunctionTableAccess");
   fun_get_line_from_addr =
-    (fun_get_line_from_addr_t) GetProcAddress(hlp_dbg_instance,
-                                              "SymGetLineFromAddr");
+      (fun_get_line_from_addr_t) GetProcAddress(hlp_dbg_instance,
+                                                "SymGetLineFromAddr");
   fun_get_module_base =
-    (fun_get_module_base_t) GetProcAddress(hlp_dbg_instance,
-                                           "SymGetModuleBase");
+      (fun_get_module_base_t) GetProcAddress(hlp_dbg_instance,
+                                             "SymGetModuleBase");
   fun_get_options =
-    (fun_get_options_t) GetProcAddress(hlp_dbg_instance, "SymGetOptions");
+      (fun_get_options_t) GetProcAddress(hlp_dbg_instance,
+                                         "SymGetOptions");
   fun_get_sym_from_addr =
-    (fun_get_sym_from_addr_t) GetProcAddress(hlp_dbg_instance,
-                                             "SymGetSymFromAddr");
+      (fun_get_sym_from_addr_t) GetProcAddress(hlp_dbg_instance,
+                                               "SymGetSymFromAddr");
   fun_set_options =
-    (fun_set_options_t) GetProcAddress(hlp_dbg_instance, "SymSetOptions");
+      (fun_set_options_t) GetProcAddress(hlp_dbg_instance,
+                                         "SymSetOptions");
   fun_stack_walk =
-    (fun_stack_walk_t) GetProcAddress(hlp_dbg_instance, "StackWalk");
+      (fun_stack_walk_t) GetProcAddress(hlp_dbg_instance, "StackWalk");
 
   /* Check that everything worked well */
   if (!fun_initialize ||
@@ -121,10 +123,10 @@ void xbt_backtrace_preinit(void)
     return;
   }
 
-  (*fun_set_options) ((*fun_get_options) () |
+  fun_set_options(fun_get_options() |
                       SYMOPT_LOAD_LINES | SYMOPT_DEFERRED_LOADS);
 
-  if (!(*fun_initialize) (process_handle, 0, 1)) {
+  if (!fun_initialize(process_handle, 0, 1)) {
     FreeLibrary(hlp_dbg_instance);
     hlp_dbg_instance = NULL;
   }
@@ -135,7 +137,7 @@ void xbt_backtrace_postexit(void)
   if (!hlp_dbg_instance)
     return;
 
-  if ((*fun_cleanup) (process_handle))
+  if (fun_cleanup(process_handle))
     FreeLibrary(hlp_dbg_instance);
 
   hlp_dbg_instance = NULL;
@@ -177,16 +179,16 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e)
   int i;
   char **backtrace_syms;
 
-  xbt_assert0(e
-              && e->used,
-              "Backtrace not setup yet, cannot set it up for display");
+  xbt_assert(e, "Backtrace not setup yet, cannot set it up for display");
+
+  if (!e->used)
+    return;
 
   backtrace_syms = backtrace_symbols(e->bt, e->used);
   e->bt_strings = NULL;
   /* parse the output and build a new backtrace */
   e->bt_strings = xbt_new(char *, e->used);
 
-
   for (i = 0; i < e->used; i++)
     e->bt_strings[i] = backtrace_syms[i];
 
@@ -202,9 +204,8 @@ int backtrace(void **buffer, int size)
   IMAGEHLP_SYMBOL *pSym;
   unsigned long offset = 0;
   IMAGEHLP_LINE line_info = { 0 };
-  byte
-    __buffer[(sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR) +
-              sizeof(ULONG64) - 1) / sizeof(ULONG64)];
+  byte __buffer[(sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR) +
+                 sizeof(ULONG64) - 1) / sizeof(ULONG64)];
 
   CONTEXT context = { CONTEXT_FULL };
   GetThreadContext(GetCurrentThread(), &context);
@@ -212,12 +213,12 @@ int backtrace(void **buffer, int size)
   /* ebp points on stack base */
   /* esp points on stack pointer, ie on last stacked element (current element) */
   _asm call $ + 5
-    _asm pop eax
-    _asm mov context.Eip, eax
-    _asm mov eax, esp
-    _asm mov context.Esp, eax
-    _asm mov context.Ebp, ebp
-    if ((NULL == hlp_dbg_instance) || (size <= 0) || (NULL == buffer)) {
+      _asm pop eax
+      _asm mov context.Eip, eax
+      _asm mov eax, esp
+      _asm mov context.Esp, eax
+      _asm mov context.Ebp, ebp
+      if ((NULL == hlp_dbg_instance) || (size <= 0) || (NULL == buffer)) {
     errno = EINVAL;
     return 0;
   }
@@ -293,9 +294,8 @@ char **backtrace_symbols(void *const *buffer, int size)
   unsigned long offset = 0;
   IMAGEHLP_LINE line_info = { 0 };
   IMAGEHLP_MODULE module = { 0 };
-  byte
-    __buffer[(sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR) +
-              sizeof(ULONG64) - 1) / sizeof(ULONG64)];
+  byte __buffer[(sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR) +
+                 sizeof(ULONG64) - 1) / sizeof(ULONG64)];
 
   if ((NULL == hlp_dbg_instance) || (size <= 0) || (NULL == buffer)) {
     errno = EINVAL;
@@ -318,13 +318,14 @@ char **backtrace_symbols(void *const *buffer, int size)
 
     if (NULL != stack_frame) {
 
-      if ((*fun_get_sym_from_addr)
+      if (fun_get_sym_from_addr
           (process_handle, stack_frame->AddrPC.Offset, &offset, pSym)) {
-        if ((*fun_get_line_from_addr)
-            (process_handle, stack_frame->AddrPC.Offset, &offset, &line_info)) {
+        if (fun_get_line_from_addr
+            (process_handle, stack_frame->AddrPC.Offset, &offset,
+             &line_info)) {
           strings[pos] =
-            bprintf("**   In %s() at %s:%d", pSym->Name, line_info.FileName,
-                    (int) line_info.LineNumber);
+              bprintf("**   In %s() at %s:%d", pSym->Name,
+                      line_info.FileName, (int) line_info.LineNumber);
         } else {
           strings[pos] = bprintf("**   In %s()", pSym->Name);
         }