From 97774044e527e50a00dddb17e2464f92af7d07f1 Mon Sep 17 00:00:00 2001 From: mquinson Date: Tue, 22 Jan 2008 10:32:48 +0000 Subject: [PATCH] Move a bit of code into the platform-dependent files (to allow their upcoming cleanup) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5206 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/xbt/backtrace_linux.c | 21 ++++++++++++--------- src/xbt/backtrace_windows.c | 10 ++++++---- src/xbt/ex.c | 2 -- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/xbt/backtrace_linux.c b/src/xbt/backtrace_linux.c index e517242a7a..106602136a 100644 --- a/src/xbt/backtrace_linux.c +++ b/src/xbt/backtrace_linux.c @@ -14,7 +14,7 @@ extern char **environ; /* the environment, as specified by the opengroup */ void xbt_ex_setup_backtrace(xbt_ex_t *e) { int i; /* to get the backtrace from the libc */ - char **backtrace = backtrace_symbols (e->bt, e->used); + char **backtrace_syms = backtrace_symbols (e->bt, e->used); /* To build the commandline of addr2line */ char *cmd, *curr; @@ -34,6 +34,9 @@ void xbt_ex_setup_backtrace(xbt_ex_t *e) { struct stat stat_buf; char *binary_name = NULL; + e->used = backtrace((void**)e->bt,XBT_BACKTRACE_SIZE); + e->bt_strings = NULL; + /* Some arches only have stubs of backtrace, no implementation (hppa comes to mind) */ if (!e->used) return; @@ -79,8 +82,8 @@ void xbt_ex_setup_backtrace(xbt_ex_t *e) { for (i=0; iused;i++) { /* retrieve this address */ - DEBUG2("Retrieving address number %d from '%s'", i, backtrace[i]); - snprintf(buff,256,"%s",strchr(backtrace[i],'[')+1); + DEBUG2("Retrieving address number %d from '%s'", i, backtrace_syms[i]); + snprintf(buff,256,"%s",strchr(backtrace_syms[i],'[')+1); p=strchr(buff,']'); *p='\0'; if (strcmp(buff,"(nil)")) @@ -165,8 +168,8 @@ void xbt_ex_setup_backtrace(xbt_ex_t *e) { if (!found) { VERB0("Problem while reading the maps file. Following backtrace will be mangled."); - DEBUG1("No dynamic. Static symbol: %s", backtrace[i]); - e->bt_strings[i] = bprintf("** In ?? (%s)", backtrace[i]); + DEBUG1("No dynamic. Static symbol: %s", backtrace_syms[i]); + e->bt_strings[i] = bprintf("** In ?? (%s)", backtrace_syms[i]); continue; } @@ -180,7 +183,7 @@ void xbt_ex_setup_backtrace(xbt_ex_t *e) { /* Got it. We have our new address. Let's get the library path and we are set */ - p = xbt_strdup(backtrace[i]); + p = xbt_strdup(backtrace_syms[i]); if (p[0]=='[') { /* library path not displayed in the map file either... */ free(p); @@ -214,8 +217,8 @@ void xbt_ex_setup_backtrace(xbt_ex_t *e) { e->bt_strings[i] = bprintf("** In %s() at %s", line_func,line_pos); } else { /* damn, nothing to do here. Let's print the raw address */ - DEBUG1("Dynamic symbol not found. Raw address = %s", backtrace[i]); - e->bt_strings[i] = bprintf("** In ?? at %s", backtrace[i]); + DEBUG1("Dynamic symbol not found. Raw address = %s", backtrace_syms[i]); + e->bt_strings[i] = bprintf("** In ?? at %s", backtrace_syms[i]); } } @@ -239,6 +242,6 @@ void xbt_ex_setup_backtrace(xbt_ex_t *e) { } pclose(pipe); free(addrs); - free(backtrace); + free(backtrace_syms); free(cmd); } diff --git a/src/xbt/backtrace_windows.c b/src/xbt/backtrace_windows.c index 1feb4ce7a1..1537eba542 100644 --- a/src/xbt/backtrace_windows.c +++ b/src/xbt/backtrace_windows.c @@ -101,19 +101,21 @@ backtrace_symbols (void *const *buffer, int size); void xbt_ex_setup_backtrace(xbt_ex_t *e) { int i; -char **backtrace = backtrace_symbols (e->bt, e->used); +char **backtrace_syms = backtrace_symbols (e->bt, e->used); + e->used = backtrace((void**)e->bt,XBT_BACKTRACE_SIZE); + e->bt_strings = NULL; /* parse the output and build a new backtrace */ e->bt_strings = xbt_new(char*,e->used); for(i=0; iused; i++) { - e->bt_strings[i] = xbt_strdup(backtrace[i]); - free(backtrace[i]); + e->bt_strings[i] = xbt_strdup(backtrace_syms[i]); + free(backtrace_syms[i]); } - free(backtrace); + free(backtrace_syms); } int diff --git a/src/xbt/ex.c b/src/xbt/ex.c index 091a4cd46d..1879b8b7ea 100644 --- a/src/xbt/ex.c +++ b/src/xbt/ex.c @@ -57,8 +57,6 @@ void xbt_ex_setup_backtrace(xbt_ex_t *e); void xbt_backtrace_current(xbt_ex_t *e) { #ifdef HAVE_BACKTRACE - e->used = backtrace((void**)e->bt,XBT_BACKTRACE_SIZE); - e->bt_strings = NULL; xbt_ex_setup_backtrace(e); #endif } -- 2.20.1