From 42e50b8071b803a440b39d6b2767b4c5e7a80aa8 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Tue, 18 Feb 2014 14:56:19 +0000 Subject: [sanitizer] when reporting a deadlock also report the lock cycle git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@201576 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/sanitizer_common/sanitizer_deadlock_detector.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib/sanitizer_common/sanitizer_deadlock_detector.h') diff --git a/lib/sanitizer_common/sanitizer_deadlock_detector.h b/lib/sanitizer_common/sanitizer_deadlock_detector.h index 48ea022a5..0bbaea53e 100644 --- a/lib/sanitizer_common/sanitizer_deadlock_detector.h +++ b/lib/sanitizer_common/sanitizer_deadlock_detector.h @@ -137,11 +137,31 @@ class DeadlockDetector { return is_reachable; } + // Finds a path between the lock 'cur_node' (which is currently held in dtls) + // and some other currently held lock, returns the length of the path + // or 0 on failure. + uptr findPathToHeldLock(DeadlockDetectorTLS *dtls, uptr cur_node, + uptr *path, uptr path_size) { + tmp_bv_.copyFrom(dtls->getLocks()); + uptr idx = nodeToIndex(cur_node); + CHECK(tmp_bv_.clearBit(idx)); + uptr res = g_.findShortestPath(idx, tmp_bv_, path, path_size); + for (uptr i = 0; i < res; i++) + path[i] = indexToNode(path[i]); + if (res) + CHECK_EQ(path[0], cur_node); + return res; + } + // Handle the unlock event. void onUnlock(DeadlockDetectorTLS *dtls, uptr node) { dtls->removeLock(nodeToIndex(node), current_epoch_); } + bool isHeld(DeadlockDetectorTLS *dtls, uptr node) const { + return dtls->getLocks().getBit(nodeToIndex(node)); + } + uptr testOnlyGetEpoch() const { return current_epoch_; } void Print() { @@ -178,6 +198,7 @@ class DeadlockDetector { uptr current_epoch_; BV available_nodes_; BV recycled_nodes_; + BV tmp_bv_; BVGraph g_; uptr data_[BV::kSize]; }; -- cgit v1.2.3