summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_deadlock_detector.h
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2014-02-18 14:56:19 +0000
committerKostya Serebryany <kcc@google.com>2014-02-18 14:56:19 +0000
commit42e50b8071b803a440b39d6b2767b4c5e7a80aa8 (patch)
tree3eb2cddbc6bd5e4be1c9472c1075479b9dad19b1 /lib/sanitizer_common/sanitizer_deadlock_detector.h
parenta52e2dc237ebe66e0ee014cf44ed8e562ceb3f88 (diff)
[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
Diffstat (limited to 'lib/sanitizer_common/sanitizer_deadlock_detector.h')
-rw-r--r--lib/sanitizer_common/sanitizer_deadlock_detector.h21
1 files changed, 21 insertions, 0 deletions
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<BV> *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<BV> *dtls, uptr node) {
dtls->removeLock(nodeToIndex(node), current_epoch_);
}
+ bool isHeld(DeadlockDetectorTLS<BV> *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<BV> g_;
uptr data_[BV::kSize];
};