From: g0dil Date: Wed, 2 Apr 2008 09:16:16 +0000 (+0000) Subject: Utils: Add backtrace to exception message in SENF_DEBUG builds X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=8ec0b7ed2df36144b52df5aa40497fc5409c31f7;hp=18ebf1e9edb34f1aa8a32173275421a5d54400f7;p=senf.git Utils: Add backtrace to exception message in SENF_DEBUG builds git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@774 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Utils/Exception.cc b/Utils/Exception.cc index f94be75..c86dade 100644 --- a/Utils/Exception.cc +++ b/Utils/Exception.cc @@ -27,6 +27,10 @@ //#include "Exception.ih" // Custom includes +#include +#include +#include "../config.hh" +#include "impl/demangle.h" #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// @@ -44,6 +48,38 @@ prefix_ char const * senf::Exception::what() return message_.c_str(); } +#ifdef SENF_DEBUG +prefix_ void senf::Exception::addBacktrace() +{ + void * entries[SENF_DEBUG_BACKTRACE_NUMCALLERS]; + unsigned nEntries( ::backtrace(entries, SENF_DEBUG_BACKTRACE_NUMCALLERS) ); + char ** symbols = ::backtrace_symbols(entries, nEntries); + + std::stringstream ss; + ss << "\nException at\n"; + for (unsigned i=0; i-rdynamic option to all link commands. This feature depends on gcc and + the GNU-libc. */ namespace senf { @@ -117,6 +122,9 @@ namespace senf { exceptions. */ private: +#ifdef SENF_DEBUG + void addBacktrace(); +#endif std::string message_; }; diff --git a/Utils/Exception.test.cc b/Utils/Exception.test.cc index d390062..9a29f71 100644 --- a/Utils/Exception.test.cc +++ b/Utils/Exception.test.cc @@ -51,7 +51,11 @@ BOOST_AUTO_UNIT_TEST(errnoException) catch (senf::SystemException & e) { BOOST_CHECK_EQUAL( e.errorNumber(), ENOENT ); BOOST_CHECK_EQUAL( e.errorString(), "No such file or directory" ); - BOOST_CHECK_EQUAL( e.what(), "[No such file or directory] ::open()\nmore\nx=1\ny=2" ); + std::string what (e.what()); + std::string::size_type pos (what.find("-- \n")); + if (pos != std::string::npos) + what = std::string(what, pos+4); + BOOST_CHECK_EQUAL( what, "[No such file or directory] ::open()\nmore\nx=1\ny=2" ); } } diff --git a/config.hh b/config.hh index 44dddeb..c4459cd 100644 --- a/config.hh +++ b/config.hh @@ -76,6 +76,10 @@ # define SENF_SENFLOG_LIMIT senf::log::NOTICE # endif # endif +# +# ifndef SENF_DEBUG_BACKTRACE_NUMCALLERS +# define SENF_DEBUG_BACKTRACE_NUMCALLERS 64 +# endif # # ///////////////////////////////hh.e//////////////////////////////////////// # endif diff --git a/senfscons/SENFSCons.py b/senfscons/SENFSCons.py index 7956bc3..d31c844 100644 --- a/senfscons/SENFSCons.py +++ b/senfscons/SENFSCons.py @@ -253,7 +253,7 @@ def MakeEnvironment(): # CPPDEFINES = [ '_GLIBCXX_DEBUG' ], env.Append(CXXFLAGS = [ '-O0', '-g', '-fno-inline' ], CPPDEFINES = [ 'SENF_DEBUG' ], - LINKFLAGS = [ '-g' ]) + LINKFLAGS = [ '-g', '-rdynamic' ]) env.Append(CPPDEFINES = [ '$EXTRA_DEFINES' ], LIBS = [ '$EXTRA_LIBS' ],