From 8daa211041cd957fdb2787e7ad3c1ab57d883159 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 13 Oct 2008 13:49:15 -0700 Subject: [PATCH] assert: include rudimentary stack dump --- src/Makefile.am | 4 ++-- src/common/assert.cc | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index e0d9dfaaffb91..1f203bee258af 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 = \ diff --git a/src/common/assert.cc b/src/common/assert.cc index 71fd43b4e7e2c..0d8c4ee283b50 100644 --- a/src/common/assert.cc +++ b/src/common/assert.cc @@ -2,14 +2,40 @@ #include "include/assert.h" #include "config.h" +#include + +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 ` 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. -- 2.39.5