From dd39b6fd12717957dad02bc84e29286db8497cb4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 14 Sep 2009 20:40:40 +0200 Subject: optionally raise trap when encountering inconsistency --- mutrace.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mutrace.c b/mutrace.c index a287541..0b0d147 100644 --- a/mutrace.c +++ b/mutrace.c @@ -19,9 +19,16 @@ /* FIXMES: * * - we probably should cover rwlocks, too + * - and conds, too! * */ +#if defined(__i386__) || defined(__x86_64__) +#define DEBUG_TRAP __asm__("int $3") +#else +#define DEBUG_TRAP raise(SIGTRAP) +#endif + typedef void (*fnptr_t)(void); struct mutex_info { @@ -61,6 +68,8 @@ static unsigned show_n_owner_changed_min = 2; static unsigned show_n_contended_min = 0; static unsigned show_n_max = 10; +static bool raise_trap = false; + static int (*real_pthread_mutex_init)(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr) = NULL; static int (*real_pthread_mutex_destroy)(pthread_mutex_t *mutex) = NULL; static int (*real_pthread_mutex_lock)(pthread_mutex_t *mutex) = NULL; @@ -609,6 +618,9 @@ static void mutex_lock(pthread_mutex_t *mutex, bool busy) { if (mi->n_lock_level > 0 && mi->type != PTHREAD_MUTEX_RECURSIVE) { __sync_fetch_and_add(&n_broken, 1); mi->broken = true; + + if (raise_trap) + DEBUG_TRAP; } mi->n_lock_level++; @@ -695,6 +707,9 @@ static void mutex_unlock(pthread_mutex_t *mutex) { if (mi->n_lock_level <= 0) { __sync_fetch_and_add(&n_broken, 1); mi->broken = true; + + if (raise_trap) + DEBUG_TRAP; } mi->n_lock_level--; -- cgit