Print stacktrace when asserting a lock is held
This commit is contained in:
15
src/sync.cpp
15
src/sync.cpp
@@ -25,6 +25,10 @@
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include <execinfo.h> /* backtrace, backtrace_symbols_fd */
|
||||
#include <unistd.h> /* STDOUT_FILENO */
|
||||
|
||||
|
||||
#ifdef DEBUG_LOCKCONTENTION
|
||||
void PrintLockContention(const char* pszName, const char* pszFile, int nLine)
|
||||
{
|
||||
@@ -177,12 +181,23 @@ std::string LocksHeld()
|
||||
return result;
|
||||
}
|
||||
|
||||
void print_stacktrace(void) {
|
||||
size_t size;
|
||||
enum Constexpr { MAX_SIZE = 1024 };
|
||||
void *array[MAX_SIZE];
|
||||
size = backtrace(array, MAX_SIZE);
|
||||
backtrace_symbols_fd(array, size, STDERR_FILENO);
|
||||
}
|
||||
|
||||
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs)
|
||||
{
|
||||
BOOST_FOREACH (const PAIRTYPE(void*, CLockLocation) & i, *lockstack)
|
||||
if (i.first == cs)
|
||||
return;
|
||||
fprintf(stderr, "Assertion failed: lock %s not held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld().c_str());
|
||||
|
||||
print_stacktrace();
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user