From 17382b40fae13629d0a7c77806bd9e73972f061d Mon Sep 17 00:00:00 2001 From: Sunny King Date: Fri, 30 Mar 2012 23:41:08 +0100 Subject: [PATCH] PPCoin: Stack trace dump for ReadCompactSize() exception --- src/makefile.unix | 2 +- src/serialize.h | 13 ++++++++++--- src/util.cpp | 23 +++++++++++++++++++---- src/util.h | 11 +++++++++-- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/makefile.unix b/src/makefile.unix index 22a5f8f..3aced5b 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -138,7 +138,7 @@ obj/nogui/%.o: %.cpp rm -f $(@:%.o=%.d) ppcoind: $(OBJS:obj/%=obj/nogui/%) - $(CXX) $(xCXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) + $(CXX) $(xCXXFLAGS) -rdynamic -o $@ $^ $(LDFLAGS) $(LIBS) obj/test/%.o: test/%.cpp $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $< diff --git a/src/serialize.h b/src/serialize.h index 78cff43..8357c2e 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2011 The Bitcoin developers +// Copyright (c) 2012 The PPCoin developers // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_SERIALIZE_H @@ -186,8 +187,14 @@ template inline void Unserialize(Stream& s, bool& a, int, int=0 - - +#ifndef THROW_WITH_STACKTRACE +#define THROW_WITH_STACKTRACE(exception) \ +{ \ + LogStackTrace(); \ + throw (exception); \ +} +void LogStackTrace(); +#endif // // Compact size @@ -265,7 +272,7 @@ uint64 ReadCompactSize(Stream& is) nSizeRet = xSize; } if (nSizeRet > (uint64)MAX_SIZE) - throw std::ios_base::failure("ReadCompactSize() : size too large"); + THROW_WITH_STACKTRACE(std::ios_base::failure("ReadCompactSize() : size too large")); return nSizeRet; } diff --git a/src/util.cpp b/src/util.cpp index e0ed34c..1082899 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2011 The Bitcoin developers -// Copyright (c) 2011 The PPCoin developers +// Copyright (c) 2011-2012 The PPCoin developers // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. #include "headers.h" @@ -13,6 +13,10 @@ #include #include +#ifndef WIN32 +#include +#endif + using namespace std; using namespace boost; @@ -154,7 +158,7 @@ int GetRandInt(int nMax) - +static FILE* fileout = NULL; inline int OutputDebugStringF(const char* pszFormat, ...) { @@ -170,8 +174,6 @@ inline int OutputDebugStringF(const char* pszFormat, ...) else { // print to debug.log - static FILE* fileout = NULL; - if (!fileout) { char pszFile[MAX_PATH+100]; @@ -681,6 +683,19 @@ void PrintException(std::exception* pex, const char* pszThread) throw; } +void LogStackTrace() { + printf("\n\n******* exception encountered *******\n"); + if (fileout) + { +#ifndef WIN32 + void* pszBuffer[32]; + size_t size; + size = backtrace(pszBuffer, 32); + backtrace_symbols_fd(pszBuffer, size, fileno(fileout)); +#endif + } +} + void ThreadOneMessageBox(string strMessage) { // Skip message boxes if one is already open diff --git a/src/util.h b/src/util.h index 1ef0e6f..467b417 100644 --- a/src/util.h +++ b/src/util.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2011 The Bitcoin developers +// Copyright (c) 2012 The PPCoin developers // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_UTIL_H @@ -139,8 +140,14 @@ inline const char* _(const char* psz) } #endif - - +#ifndef THROW_WITH_STACKTRACE +#define THROW_WITH_STACKTRACE(exception) \ +{ \ + LogStackTrace(); \ + throw (exception); \ +} +void LogStackTrace(); +#endif -- 1.7.1