forked from OSchip/llvm-project
[sanitizer] Fix StackDepotPrintAll
unlock corrupted backets by using s set by loop to nullptr. Also StackDepot supports iterating without locking. Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D111599
This commit is contained in:
parent
86a4a93a1c
commit
b4db2a500d
|
@ -180,14 +180,12 @@ template <class Node, int kReservedBits, int kTabSizeLog>
|
|||
void StackDepotBase<Node, kReservedBits, kTabSizeLog>::PrintAll() {
|
||||
for (int i = 0; i < kTabSize; ++i) {
|
||||
atomic_uintptr_t *p = &tab[i];
|
||||
lock(p);
|
||||
uptr v = atomic_load(p, memory_order_relaxed);
|
||||
uptr v = atomic_load(p, memory_order_consume);
|
||||
Node *s = (Node *)(v & ~1UL);
|
||||
for (; s; s = s->link) {
|
||||
Printf("Stack for id %u:\n", s->id);
|
||||
s->load().Print();
|
||||
}
|
||||
unlock(p, s);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,22 @@ TEST(SanitizerCommon, Maybe_StackDepotPrint) {
|
|||
"Stack for id .*#0 0x1.*#1 0x2.*#2 0x3.*#3 0x4.*#4 0x8.*#5 0x9.*");
|
||||
}
|
||||
|
||||
TEST(SanitizerCommon, StackDepotPrintNoLock) {
|
||||
u32 n = 2000;
|
||||
std::vector<u32> idx2id(n);
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
uptr array[] = {0x111, 0x222, i, 0x444, 0x777};
|
||||
StackTrace s(array, ARRAY_SIZE(array));
|
||||
idx2id[i] = StackDepotPut(s);
|
||||
}
|
||||
StackDepotPrintAll();
|
||||
for (u32 i = 1; i < n; ++i) {
|
||||
uptr array[] = {0x111, 0x222, i, 0x444, 0x777};
|
||||
StackTrace s(array, ARRAY_SIZE(array));
|
||||
CHECK_EQ(idx2id[i], StackDepotPut(s));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SanitizerCommon, StackDepotReverseMap) {
|
||||
uptr array1[] = {1, 2, 3, 4, 5};
|
||||
uptr array2[] = {7, 1, 3, 0};
|
||||
|
|
Loading…
Reference in New Issue