From: cherierm Date: Mon, 7 Jan 2008 14:31:27 +0000 (+0000) Subject: Add the backtrace in the table of string only if the symbol and the line information... X-Git-Tag: v3.3~693 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/85b2987dcff719252ce8fcece5b27e51ef9b4d5a?ds=sidebyside Add the backtrace in the table of string only if the symbol and the line information exist. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5161 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/xbt/ex.c b/src/xbt/ex.c index c8d593be17..c542ce5fca 100644 --- a/src/xbt/ex.c +++ b/src/xbt/ex.c @@ -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(""); + } + } + else + { + strings[pos] = strdup(""); } free(stack_frame);