From 675e20867bd0c61ca1b3d5d003e1ed23a6c00137 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Tue, 9 Aug 2016 11:49:55 +0200 Subject: [PATCH] In Backtrace, prevent looping when an error occur inside itself. * Bug: In Hurricane, in Backtrace, under RHEL 6 when the package is *not* installed, Backtrace uses the wrong "bfd.h" from the system instead of the one from the devtoolset2, causing itself to core. The Backtrace, then try to create a second Backtrace from this error, generating an infinite loop. To prevent this situation add a counter so that only one Backtrace can be created at a any time. And incidentally display a more meaningful error message along with --- hurricane/src/hurricane/Backtrace.cpp | 18 +++++++++++++++++- hurricane/src/hurricane/hurricane/Backtrace.h | 8 +++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/hurricane/src/hurricane/Backtrace.cpp b/hurricane/src/hurricane/Backtrace.cpp index 77a0bd61..c91aa02a 100644 --- a/hurricane/src/hurricane/Backtrace.cpp +++ b/hurricane/src/hurricane/Backtrace.cpp @@ -262,7 +262,6 @@ namespace { return; } } - } } @@ -414,6 +413,7 @@ namespace Hurricane { // Class : "Hurricane::Backtrace". + int Backtrace::_callCount = 0; TextTranslator Backtrace::_textTranslator = TextTranslator::toTextTranslator(); const size_t Backtrace::_stackSize = 50; @@ -428,6 +428,18 @@ namespace Hurricane { Backtrace::Backtrace () : _stack() { + if (_callCount > 0) { + _stack.push_back( "[BUG] Backtrace::Backtrace(): An error occurred in the backtace *istself*." ); + _stack.push_back( "" ); + _stack.push_back( " Under RHEL 6, this may be due to a link with a wrong version of ," ); + _stack.push_back( " please check that you have the package" ); + _stack.push_back( " installed." ); + _stack.push_back( "" ); + _stack.push_back( " For other OSs, check for any problems related to BFD." ); + return; + } + ++_callCount; + #if (defined __linux__ || defined __FreeBSD__ || defined __APPLE__) void* rawStack [ _stackSize ]; size_t depth = backtrace ( rawStack, _stackSize ); @@ -498,6 +510,10 @@ namespace Hurricane { } + Backtrace::~Backtrace () + { --_callCount; } + + string Backtrace::htmlWhere () const { ostringstream where; diff --git a/hurricane/src/hurricane/hurricane/Backtrace.h b/hurricane/src/hurricane/hurricane/Backtrace.h index 48045240..8d4178a6 100644 --- a/hurricane/src/hurricane/hurricane/Backtrace.h +++ b/hurricane/src/hurricane/hurricane/Backtrace.h @@ -43,15 +43,17 @@ namespace Hurricane { class Backtrace { public: Backtrace (); + ~Backtrace (); inline std::string where () const; inline std::string textWhere () const; std::string htmlWhere () const; inline std::string _getTypeName () const; inline std::string _getString () const; private: - static TextTranslator _textTranslator; - static const size_t _stackSize; - std::vector _stack; + static int _callCount; + static TextTranslator _textTranslator; + static const size_t _stackSize; + std::vector _stack; };