Added mutex debug flag.

When mutex debugging is enabled now a stack trace
is logged, if a mutex is locked on destruction.
This commit is contained in:
Armin Novak 2015-04-28 08:55:26 +02:00
parent 3fb8bb7890
commit ac15ce2da8
3 changed files with 30 additions and 0 deletions

View File

@ -115,6 +115,7 @@ option(WITH_DEBUG_SND "Print rdpsnd debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_SVC "Print static virtual channel debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_TRANSPORT "Print transport debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_THREADS "Print thread debug messages, enables handle dump" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_MUTEX "Print mutex debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_TIMEZONE "Print timezone debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_WND "Print window order debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_X11_CLIPRDR "Print X11 clipboard redirection debug messages" ${DEFAULT_DEBUG_OPTION})

View File

@ -88,6 +88,7 @@
#cmakedefine WITH_DEBUG_RDPEI
#cmakedefine WITH_DEBUG_TIMEZONE
#cmakedefine WITH_DEBUG_THREADS
#cmakedefine WITH_DEBUG_MUTEX
#cmakedefine WITH_DEBUG_TRANSPORT
#cmakedefine WITH_DEBUG_WND
#cmakedefine WITH_DEBUG_X11

View File

@ -22,12 +22,18 @@
#endif
#include <winpr/synch.h>
#include <winpr/debug.h>
#include <winpr/wlog.h>
#include "synch.h"
#ifndef _WIN32
#include "../handle/handle.h"
#include "../log.h"
#define TAG WINPR_TAG("sync.mutex")
static BOOL MutexCloseHandle(HANDLE handle);
static BOOL MutexIsHandled(HANDLE handle)
@ -61,6 +67,28 @@ BOOL MutexCloseHandle(HANDLE handle)
if (!MutexIsHandled(handle))
return FALSE;
#if defined(WITH_DEBUG_MUTEX)
if (pthread_mutex_trylock(&mutex->mutex))
{
size_t used = 0, i;
void* stack = winpr_backtrace(20);
char **msg = NULL;
if (stack)
msg = winpr_backtrace_symbols(stack, &used);
if (msg)
{
for(i=0; i<used; i++)
WLog_ERR(TAG, "%2d: %s", i, msg[i]);
}
free (msg);
winpr_backtrace_free(stack);
}
else
pthread_mutex_unlock(&mutex->mutex);
#endif
if (!pthread_mutex_destroy(&mutex->mutex))
return FALSE;