diff --git a/src/sync.cpp b/src/sync.cpp --- a/src/sync.cpp +++ b/src/sync.cpp @@ -46,8 +46,9 @@ m_thread_name(thread_name), sourceLine(nLine) {} std::string ToString() const { - return strprintf("%s %s:%s%s (in thread %s)", mutexName, sourceFile, - sourceLine, (fTry ? " (TRY)" : ""), m_thread_name); + return strprintf("'%s' in %s:%s%s (in thread '%s')", mutexName, + sourceFile, sourceLine, (fTry ? " (TRY)" : ""), + m_thread_name); } std::string Name() const { return mutexName; } @@ -90,7 +91,7 @@ const LockStack &s2) { LogPrintf("POTENTIAL DEADLOCK DETECTED\n"); LogPrintf("Previous lock order was:\n"); - for (const LockStackItem &i : s2) { + for (const LockStackItem &i : s1) { if (i.first == mismatch.first) { LogPrintfToBeContinued(" (1)"); } @@ -99,25 +100,31 @@ } LogPrintf(" %s\n", i.second.ToString()); } + + std::string mutex_a, mutex_b; LogPrintf("Current lock order is:\n"); - for (const LockStackItem &i : s1) { + for (const LockStackItem &i : s2) { if (i.first == mismatch.first) { LogPrintfToBeContinued(" (1)"); + mutex_a = i.second.Name(); } if (i.first == mismatch.second) { LogPrintfToBeContinued(" (2)"); + mutex_b = i.second.Name(); } LogPrintf(" %s\n", i.second.ToString()); } if (g_debug_lockorder_abort) { tfm::format( std::cerr, - "Assertion failed: detected inconsistent lock order at %s:%i, " + "Assertion failed: detected inconsistent lock order for %s, " "details in debug log.\n", - __FILE__, __LINE__); + s2.back().second.ToString()); abort(); } - throw std::logic_error("potential deadlock detected"); + throw std::logic_error( + strprintf("potential deadlock detected: %s -> %s -> %s", mutex_b, + mutex_a, mutex_b)); } static void push_lock(void *c, const CLockLocation &locklocation) { diff --git a/src/test/sync_tests.cpp b/src/test/sync_tests.cpp --- a/src/test/sync_tests.cpp +++ b/src/test/sync_tests.cpp @@ -15,7 +15,9 @@ try { LOCK2(mutex2, mutex1); } catch (const std::logic_error &e) { - BOOST_CHECK_EQUAL(e.what(), "potential deadlock detected"); + BOOST_CHECK_EQUAL( + e.what(), + "potential deadlock detected: mutex1 -> mutex2 -> mutex1"); error_thrown = true; } #ifdef DEBUG_LOCKORDER