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
This commit is contained in:
paulc 2004-10-14 16:36:24 +00:00
parent becea2e9e4
commit 1f327de745
4 changed files with 39 additions and 5 deletions

View File

@ -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;

View File

@ -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()

View File

@ -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;

View File

@ -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.
*/