Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add the backtrace in the table of string only if the symbol and the line information...
authorcherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 7 Jan 2008 14:31:27 +0000 (14:31 +0000)
committercherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 7 Jan 2008 14:31:27 +0000 (14:31 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5161 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/xbt/ex.c

index c8d593b..c542ce5 100644 (file)
@@ -424,8 +424,7 @@ void xbt_ex_setup_backtrace(xbt_ex_t *e)  {
   free(cmd);
 #elif (defined(WIN32) && defined (_M_IX86))
 int i;
-  /* to get the backtrace from the libc */
-  char **backtrace = backtrace_symbols (e->bt, e->used);
+char **backtrace = backtrace_symbols (e->bt, e->used);
   
   /* parse the output and build a new backtrace */
   e->bt_strings = xbt_new(char*,e->used);
@@ -536,6 +535,11 @@ backtrace (void **buffer, int size)
        STACKFRAME* stack_frame;
        int first = 1;
 
+       IMAGEHLP_SYMBOL * pSym;
+       unsigned long displacement = 0;
+       IMAGEHLP_LINE line_info = {0};
+       byte __buffer[(sizeof(SYMBOL_INFO) +MAX_SYM_NAME * sizeof(TCHAR) + sizeof(ULONG64) - 1) / sizeof(ULONG64)];
+
        CONTEXT context = {CONTEXT_FULL};
        GetThreadContext(GetCurrentThread(), &context);
        
@@ -561,6 +565,15 @@ backtrace (void **buffer, int size)
        
        pos = 0;
 
+       pSym = (IMAGEHLP_SYMBOL*)__buffer;
+
+       pSym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL);
+       pSym->MaxNameLength = MAX_SYM_NAME;
+
+
+       line_info.SizeOfStruct = sizeof(IMAGEHLP_LINE);
+       
+
     while(pos < size)
     {
                stack_frame = (void*)calloc(1,sizeof(STACKFRAME));
@@ -593,10 +606,17 @@ backtrace (void **buffer, int size)
                        && !first) 
                {
                        if(stack_frame->AddrReturn.Offset)
-                               buffer[pos++] = (void*)stack_frame;
+                       {
+
+                               if((*(dbg_hlp->sym_get_sym_from_addr))(dbg_hlp->process_handle,stack_frame->AddrPC.Offset, &displacement,pSym))
+                               {       
+                                       if((*(dbg_hlp->sym_get_line_from_addr))(dbg_hlp->process_handle,stack_frame->AddrPC.Offset, &displacement,&line_info))
+                                               buffer[pos++] = (void*)stack_frame;
+                               }
+                       }
                        else
                        {
-                               free(stack_frame); /* no symbol */
+                               free(stack_frame); /* no symbol or no line info */
                                break;
                        }
                }
@@ -670,6 +690,14 @@ backtrace_symbols (void *const *buffer, int size)
                                        
                                                success = 1;
                                }
+                               else
+                               {
+                                       strings[pos] = strdup("<no line>");
+                               }
+                       }
+                       else
+                       {
+                               strings[pos] = strdup("<no symbole>");
                        }
 
                        free(stack_frame);