X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ec16845133f5f1b5262d2d77d8ba22824fa8a446..9a444de20a7545d1c3d10bd242f317febded25c4:/src/xbt/backtrace_linux.c diff --git a/src/xbt/backtrace_linux.c b/src/xbt/backtrace_linux.c index 9cfea876db..e4eda28d87 100644 --- a/src/xbt/backtrace_linux.c +++ b/src/xbt/backtrace_linux.c @@ -28,6 +28,12 @@ void xbt_backtrace_postexit(void) void xbt_backtrace_current(xbt_ex_t * e) { e->used = backtrace((void **) e->bt, XBT_BACKTRACE_SIZE); + if (e->used == 0) { + fprintf(stderr, "The backtrace() function failed, which probably means that the memory is exhausted. Here is a crude dump of the exception that I was trying to build:"); + fprintf(stderr, "%s:%s(%d) [%s:%d] %s", e->host,e->procname,e->pid, e->file,e->line,e->msg); + fprintf(stderr, "Bailing out now since there is nothing I can do without a decent amount of memory. Please go fix the memleaks\n"); + exit(1); + } } @@ -56,7 +62,7 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) struct stat stat_buf; char *binary_name = NULL; - xbt_assert0(e + xbt_assert(e && e->used, "Backtrace not setup yet, cannot set it up for display"); @@ -185,10 +191,8 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) maps_name = bprintf("/proc/%d/maps", (int) getpid()); maps = fopen(maps_name, "r"); - sscanf(addrs[i], "%lx", &addr); - sprintf(maps_buff, "%#lx", addr); - - if (strcmp(addrs[i], maps_buff)) { + addr = strtol(addrs[i], &p, 16); + if (*p != '\0') { XBT_CRITICAL("Cannot parse backtrace address '%s' (addr=%#lx)", addrs[i], addr); }