]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
assert: include rudimentary stack dump
authorSage Weil <sage@newdream.net>
Mon, 13 Oct 2008 20:49:15 +0000 (13:49 -0700)
committerSage Weil <sage@newdream.net>
Mon, 13 Oct 2008 20:49:15 +0000 (13:49 -0700)
src/Makefile.am
src/common/assert.cc

index e0d9dfaaffb9156d14ed7e272813bdfc17853db3..1f203bee258af3196728b3200a800c8122e0ae50 100644 (file)
@@ -142,8 +142,8 @@ libhadoopcephfs.so: client/hadoop/CephFSInterface.cc libcephclient_so.a
 INCLUDES = 
 LDADD = -lpthread 
 
-AM_CXXFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_THREAD_SAFE
-AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_THREAD_SAFE
+AM_CXXFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_THREAD_SAFE -rdynamic
+AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_THREAD_SAFE -rdynamic
 AM_LDFLAGS =
 
 noinst_LIBRARIES = \
index 71fd43b4e7e2cffd3688ae36d025cd7166fe5843..0d8c4ee283b50410e678eb04762cb4df934d1663 100644 (file)
@@ -2,14 +2,40 @@
 #include "include/assert.h"
 #include "config.h"
 
+#include <execinfo.h>
+
+void print_trace (ostream& out)
+{
+  int max = 100;
+  void *array[max];
+  size_t size;
+  char **strings;
+  size_t i;
+  
+  size = backtrace(array, max);
+  strings = backtrace_symbols(array, size);
+
+  int skip = 2;  // skip print_trace and assert
+  out << " --- BACKTRACE " << (size-skip) << " frames ---" << std::endl;
+
+  for (i = skip; i < size; i++)
+    out << " " << (i-skip+1) << ": " << strings[i] << std::endl;
+  out << " NOTE: a copy of the executable, or `objdump -rdS <executable>` is needed to interpret this." << std::endl;
+  free(strings);
+}
+
 void __ceph_assert_fail(const char *assertion, const char *file, int line, const char *func)
 {
   _dout_lock.TryLock();
   *_dout << file << ":" << line << ": FAILED assert in \'" << func << "\': " << assertion << std::endl;
-  cerr   << file << ":" << line << ": FAILED assert in \'" << func << "\': " << assertion << std::endl;
+  print_trace(*_dout);
   _dout->flush();
+
+  cerr   << file << ":" << line << ": FAILED assert in \'" << func << "\': " << assertion << std::endl;
+  print_trace(cerr);
   cerr.flush();
 
+
   char *p = 0;
   while (1)
     *p-- = 0;  // make myself core dump.