From 1f327de745dbbb943b86a81be8e83386adeed65f Mon Sep 17 00:00:00 2001 From: paulc Date: Thu, 14 Oct 2004 16:36:24 +0000 Subject: [PATCH] Added abort-on-bug flag and command line option. git-svn-id: http://yate.null.ro/svn/yate/trunk@80 acf43c95-373e-0410-b603-e72c3f656dc1 --- engine/Engine.cpp | 4 ++++ engine/Mutex.cpp | 10 +++++----- engine/TelEngine.cpp | 18 ++++++++++++++++++ yatengine.h | 12 ++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/engine/Engine.cpp b/engine/Engine.cpp index 329c1546..11f48f4d 100644 --- a/engine/Engine.cpp +++ b/engine/Engine.cpp @@ -393,6 +393,7 @@ static void usage(FILE *f) " -m pathname Path to modules directory (" MOD_PATH ")\n" #ifndef NDEBUG " -D[options] Special debugging options\n" +" a Abort if bugs are encountered\n" " c Call dlclose() until it gets an error\n" " i Reinitialize after 1st initialization\n" " x Exit immediately after initialization\n" @@ -490,6 +491,9 @@ int Engine::main(int argc, const char **argv, const char **environ) case 'D': while (*++pc) { switch (*pc) { + case 'a': + abortOnBug(true); + break; case 'c': s_keepclosing = true; break; diff --git a/engine/Mutex.cpp b/engine/Mutex.cpp index 69a99f0e..c3eaa8b5 100644 --- a/engine/Mutex.cpp +++ b/engine/Mutex.cpp @@ -20,8 +20,8 @@ public: { if (!--m_refcount) delete this; } bool lock(long long int maxwait); void unlock(); - static int s_count; - static int s_locks; + static volatile int s_count; + static volatile int s_locks; private: pthread_mutex_t m_mutex; int m_refcount; @@ -32,8 +32,8 @@ private: using namespace TelEngine; -int MutexPrivate::s_count = 0; -int MutexPrivate::s_locks = 0; +volatile int MutexPrivate::s_count = 0; +volatile int MutexPrivate::s_locks = 0; // WARNING!!! // No debug messages are allowed in mutexes since the debug output itself @@ -93,7 +93,7 @@ void MutexPrivate::unlock() } else // Hope we don't hit a bug related to the debug mutex! - Debug(DebugGoOn,"MutexPrivate::unlock called on unlocked mutex"); + Debug(DebugFail,"MutexPrivate::unlock called on unlocked mutex"); } Mutex::Mutex() diff --git a/engine/TelEngine.cpp b/engine/TelEngine.cpp index 506cee8f..2adcf3eb 100644 --- a/engine/TelEngine.cpp +++ b/engine/TelEngine.cpp @@ -19,6 +19,7 @@ namespace TelEngine { static int s_debug = DebugWarn; static int s_indent = 0; static bool s_debugging = true; +static bool s_abort = false; static void dbg_stderr_func(const char *buf) { @@ -93,6 +94,8 @@ bool Debug(int level, const char *format, ...) va_start(va,format); dbg_output(buf,format,va); va_end(va); + if (s_abort && (level == DebugFail)) + abort(); return true; } return false; @@ -111,11 +114,26 @@ bool Debug(const char *facility, int level, const char *format, ...) va_start(va,format); dbg_output(buf,format,va); va_end(va); + if (s_abort && (level == DebugFail)) + abort(); return true; } return false; } +void abortOnBug() +{ + if (s_abort) + abort(); +} + +bool abortOnBug(bool doAbort) +{ + bool tmp = s_abort; + s_abort = doAbort; + return tmp; +} + int debugLevel() { return s_debug; diff --git a/yatengine.h b/yatengine.h index df14fbf4..cd541cee 100644 --- a/yatengine.h +++ b/yatengine.h @@ -22,6 +22,18 @@ namespace TelEngine { #define FORMAT_CHECK(f) #endif +/** + * Abort execution (and coredump if allowed) if the abort flag is set. + * This function may not return. + */ +void abortOnBug(); + +/** + * Set the abort on bug flag. The default flag state is false. + * @return The old state of the flag. + */ +bool abortOnBug(bool doAbort); + /** * Standard debugging levels. */