Skip to content

Commit

Permalink
[NFC][Asan] Remove Debug code
Browse files Browse the repository at this point in the history
Used for google/sanitizers#1193

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D86933
  • Loading branch information
vitalybuka committed Sep 8, 2020
1 parent c05095c commit 27650a5
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 76 deletions.
38 changes: 0 additions & 38 deletions compiler-rt/lib/asan/asan_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,26 +750,6 @@ struct Allocator {
return reinterpret_cast<AsanChunk *>(alloc_beg);
}

AsanChunk *GetAsanChunkDebug(void *alloc_beg) {
if (!alloc_beg)
return nullptr;
if (!allocator.FromPrimary(alloc_beg)) {
uptr *meta = reinterpret_cast<uptr *>(allocator.GetMetaData(alloc_beg));
AsanChunk *m = reinterpret_cast<AsanChunk *>(meta[1]);
Printf("GetAsanChunkDebug1 alloc_beg %p meta %p m %p\n", alloc_beg, meta,
m);
return m;
}
uptr *alloc_magic = reinterpret_cast<uptr *>(alloc_beg);
Printf(
"GetAsanChunkDebug2 alloc_beg %p alloc_magic %p alloc_magic[0] %p "
"alloc_magic[1] %p\n",
alloc_beg, alloc_magic, alloc_magic[0], alloc_magic[1]);
if (alloc_magic[0] == kAllocBegMagic)
return reinterpret_cast<AsanChunk *>(alloc_magic[1]);
return reinterpret_cast<AsanChunk *>(alloc_beg);
}

AsanChunk *GetAsanChunkByAddr(uptr p) {
void *alloc_beg = allocator.GetBlockBegin(reinterpret_cast<void *>(p));
return GetAsanChunk(alloc_beg);
Expand All @@ -782,14 +762,6 @@ struct Allocator {
return GetAsanChunk(alloc_beg);
}

AsanChunk *GetAsanChunkByAddrFastLockedDebug(uptr p) {
void *alloc_beg =
allocator.GetBlockBeginFastLockedDebug(reinterpret_cast<void *>(p));
Printf("GetAsanChunkByAddrFastLockedDebug p %p alloc_beg %p\n", p,
alloc_beg);
return GetAsanChunkDebug(alloc_beg);
}

uptr AllocationSize(uptr p) {
AsanChunk *m = GetAsanChunkByAddr(p);
if (!m) return 0;
Expand Down Expand Up @@ -1093,16 +1065,6 @@ uptr PointsIntoChunk(void* p) {
return 0;
}

// Debug code. Delete once issue #1193 is chased down.
extern "C" SANITIZER_WEAK_ATTRIBUTE const char *__lsan_current_stage;

void GetUserBeginDebug(uptr chunk) {
Printf("GetUserBeginDebug1 chunk %p\n", chunk);
__asan::AsanChunk *m =
__asan::instance.GetAsanChunkByAddrFastLockedDebug(chunk);
Printf("GetUserBeginDebug2 m %p\n", m);
}

uptr GetUserBegin(uptr chunk) {
__asan::AsanChunk *m = __asan::instance.GetAsanChunkByAddrFastLocked(chunk);
return m ? m->Beg() : 0;
Expand Down
7 changes: 0 additions & 7 deletions compiler-rt/lib/lsan/lsan_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include "sanitizer_common/sanitizer_thread_registry.h"
#include "sanitizer_common/sanitizer_tls_get_addr.h"

extern "C" const char *__lsan_current_stage = "unknown";

#if CAN_SANITIZE_LEAKS
namespace __lsan {

Expand Down Expand Up @@ -362,7 +360,6 @@ static void FloodFillTag(Frontier *frontier, ChunkTag tag) {
// ForEachChunk callback. If the chunk is marked as leaked, marks all chunks
// which are reachable from it as indirectly leaked.
static void MarkIndirectlyLeakedCb(uptr chunk, void *arg) {
__lsan_current_stage = "MarkIndirectlyLeakedCb";
chunk = GetUserBegin(chunk);
LsanMetadata m(chunk);
if (m.allocated() && m.tag() != kReachable) {
Expand All @@ -375,7 +372,6 @@ static void MarkIndirectlyLeakedCb(uptr chunk, void *arg) {
// frontier.
static void CollectIgnoredCb(uptr chunk, void *arg) {
CHECK(arg);
__lsan_current_stage = "CollectIgnoredCb";
chunk = GetUserBegin(chunk);
LsanMetadata m(chunk);
if (m.allocated() && m.tag() == kIgnored) {
Expand Down Expand Up @@ -405,7 +401,6 @@ struct InvalidPCParam {
static void MarkInvalidPCCb(uptr chunk, void *arg) {
CHECK(arg);
InvalidPCParam *param = reinterpret_cast<InvalidPCParam *>(arg);
__lsan_current_stage = "MarkInvalidPCCb";
chunk = GetUserBegin(chunk);
LsanMetadata m(chunk);
if (m.allocated() && m.tag() != kReachable && m.tag() != kIgnored) {
Expand Down Expand Up @@ -481,7 +476,6 @@ static void ClassifyAllChunks(SuspendedThreadsList const &suspended_threads,
// ForEachChunk callback. Resets the tags to pre-leak-check state.
static void ResetTagsCb(uptr chunk, void *arg) {
(void)arg;
__lsan_current_stage = "ResetTagsCb";
chunk = GetUserBegin(chunk);
LsanMetadata m(chunk);
if (m.allocated() && m.tag() != kIgnored)
Expand All @@ -498,7 +492,6 @@ static void PrintStackTraceById(u32 stack_trace_id) {
static void CollectLeaksCb(uptr chunk, void *arg) {
CHECK(arg);
LeakReport *leak_report = reinterpret_cast<LeakReport *>(arg);
__lsan_current_stage = "CollectLeaksCb";
chunk = GetUserBegin(chunk);
LsanMetadata m(chunk);
if (!m.allocated()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,6 @@ class CombinedAllocator {
return secondary_.GetBlockBeginFastLocked(p);
}

void *GetBlockBeginFastLockedDebug(void *p) {
if (primary_.PointerIsMine(p))
return primary_.GetBlockBeginDebug(p);
return secondary_.GetBlockBeginFastLocked(p);
}

uptr GetActuallyAllocatedSize(void *p) {
if (primary_.PointerIsMine(p))
return primary_.GetActuallyAllocatedSize(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ class SizeClassAllocator32 {
uptr res = beg + (n * (u32)size);
return reinterpret_cast<void*>(res);
}
void *GetBlockBeginDebug(const void *p) { return GetBlockBegin(p); }

uptr GetActuallyAllocatedSize(void *p) {
CHECK(PointerIsMine(p));
Expand Down
24 changes: 0 additions & 24 deletions compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,30 +199,6 @@ class SizeClassAllocator64 {
return nullptr;
}

void *GetBlockBeginDebug(const void *p) {
uptr class_id = GetSizeClass(p);
uptr size = ClassIdToSize(class_id);
Printf("GetBlockBeginDebug1 p %p class_id %p size %p\n", p, class_id, size);
if (!size)
return nullptr;
uptr chunk_idx = GetChunkIdx((uptr)p, size);
uptr reg_beg = GetRegionBegin(p);
uptr beg = chunk_idx * size;
uptr next_beg = beg + size;
Printf(
"GetBlockBeginDebug2 chunk_idx %p reg_beg %p beg %p next_beg %p "
"kNumClasses %p\n",
chunk_idx, reg_beg, beg, next_beg, kNumClasses);
if (class_id >= kNumClasses)
return nullptr;
const RegionInfo *region = AddressSpaceView::Load(GetRegionInfo(class_id));
Printf("GetBlockBeginDebug3 region %p region->mapped_user %p\n", region,
region->mapped_user);
if (region->mapped_user >= next_beg)
return reinterpret_cast<void *>(reg_beg + beg);
return nullptr;
}

uptr GetActuallyAllocatedSize(void *p) {
CHECK(PointerIsMine(p));
return ClassIdToSize(GetSizeClass(p));
Expand Down

0 comments on commit 27650a5

Please sign in to comment.