From d3e3876751b6becc9084b5508fd0a48178f30b1b Mon Sep 17 00:00:00 2001 From: Dwight Date: Fri, 27 Jun 2008 14:35:05 -0400 Subject: stack traces --- db/db.cpp | 2 +- db/makefile | 2 +- db/pdfile.cpp | 1 + db/tests.cpp | 3 +++ stdafx.h | 2 ++ util/goodies.h | 20 ++++++++++++++++++++ 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/db/db.cpp b/db/db.cpp index 7986980ec72..130636ca23a 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -347,7 +347,7 @@ public: 115 replay, opLogging */ void listen(int port) { - const char *Version = "db version: 117 24jun2008"; + const char *Version = "db version: 118 27jun2008"; problem() << Version << endl; cout << Version << endl; pdfileInit(); diff --git a/db/makefile b/db/makefile index 7ddbcfcb1f1..76d8cbfdb2f 100644 --- a/db/makefile +++ b/db/makefile @@ -1,6 +1,6 @@ # makefile for our db project -FLAGS= ${CFLAGS} -fPIC -ggdb -pthread -O3 -I .. -Isrc/p -I/src/p/db -L/usr/local/lib -L/usr/lib +FLAGS= ${CFLAGS} -fPIC -ggdb -pthread -O3 -I .. -Isrc/p -I/src/p/db -L/usr/local/lib -L/usr/lib -rdynamic LIB_DEPS = -lpcrecpp -lpcre LIB_BOOST = -lboost_thread -lboost_filesystem diff --git a/db/pdfile.cpp b/db/pdfile.cpp index c39191d42a7..1ec6a11142d 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -40,6 +40,7 @@ void sayDbContext(const char *errmsg) { cout << " op:" << curOp << ' ' << callDepth << endl; if( client ) cout << " ns: " << curNs << endl; + printStackTrace(); } JSObj::JSObj(Record *r) { diff --git a/db/tests.cpp b/db/tests.cpp index 3d07fcf1aed..1fac4d76573 100644 --- a/db/tests.cpp +++ b/db/tests.cpp @@ -8,6 +8,9 @@ int test2() { cout << "test2" << endl; + printStackTrace(); + if( 1 ) + return 1; MemoryMappedFile f; diff --git a/stdafx.h b/stdafx.h index 502f91aa0f2..d2c5effcd6d 100644 --- a/stdafx.h +++ b/stdafx.h @@ -140,3 +140,5 @@ void dbexit(int resultcode); #define assert xassert #define yassert 1 using namespace boost::filesystem; + +#include "util/goodies.h" diff --git a/util/goodies.h b/util/goodies.h index 7f2a4f7cb34..8bb25f31afa 100644 --- a/util/goodies.h +++ b/util/goodies.h @@ -8,6 +8,26 @@ #if !defined(_WIN32) #include inline pthread_t GetCurrentThreadId() { return pthread_self(); } +#include +/* use "addr2line -CFe " to parse. */ +inline void printStackTrace() { + void *b[12]; + size_t size; + char **strings; + size_t i; + + size = backtrace(b, 12); + strings = backtrace_symbols(b, size); + + for (i = 0; i < size; i++) + cout << ' ' << hex << b[i] << '\n'; + for (i = 0; i < size; i++) + cout << ' ' << strings[i] << '\n'; + + free (strings); +} +#else +inline void printStackTrace() { } #endif /* set to TRUE if we are exiting */ -- cgit v1.2.1