From: Martin Willi Date: Wed, 19 Jun 2013 14:00:14 +0000 (+0200) Subject: backtrace: use backtrace_symbols() only if we have backtrace() and dladdr() fails X-Git-Tag: 5.1.0dr1~110 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad58246f5306e7989d69205f95f38ad631fff0f4;p=thirdparty%2Fstrongswan.git backtrace: use backtrace_symbols() only if we have backtrace() and dladdr() fails --- diff --git a/src/libstrongswan/utils/backtrace.c b/src/libstrongswan/utils/backtrace.c index 820dba44be..9477d4352a 100644 --- a/src/libstrongswan/utils/backtrace.c +++ b/src/libstrongswan/utils/backtrace.c @@ -382,9 +382,7 @@ METHOD(backtrace_t, log_, void, { #if defined(HAVE_BACKTRACE) || defined(HAVE_LIBUNWIND_H) size_t i; - char **strings; - - strings = backtrace_symbols(this->frames, this->frame_count); + char **strings = NULL; println(file, " dumping %d stack frame addresses:", this->frame_count); for (i = 0; i < this->frame_count; i++) @@ -424,10 +422,23 @@ METHOD(backtrace_t, log_, void, else #endif /* HAVE_DLADDR */ { - println(file, " %s", strings[i]); +#ifdef HAVE_BACKTRACE + if (!strings) + { + strings = backtrace_symbols(this->frames, this->frame_count); + } + if (strings) + { + println(file, " %s", strings[i]); + } + else +#endif /* HAVE_BACKTRACE */ + { + println(file, " %p", this->frames[i]); + } } } - free (strings); + free(strings); #else /* !HAVE_BACKTRACE && !HAVE_LIBUNWIND_H */ println(file, "no support for backtrace()/libunwind"); #endif /* HAVE_BACKTRACE/HAVE_LIBUNWIND_H */