Print stacktrace when asserting a lock is held

This commit is contained in:
Duke
2024-09-11 23:31:44 -04:00
parent 726191cad4
commit aa75877cd6

View File

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