backtrace: use backtrace_symbols() only if we have backtrace() and dladdr() fails
authorMartin Willi <martin@revosec.ch>
Wed, 19 Jun 2013 14:00:14 +0000 (16:00 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 19 Jun 2013 14:09:31 +0000 (16:09 +0200)
src/libstrongswan/utils/backtrace.c

index 820dba4..9477d43 100644 (file)
@@ -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 */