Skip to content

Commit 2e6c3e3

Browse files
committed
add debug code to chase down a rare crash in asan/lsan google/sanitizers#1193
Summary: add debug code to chase down a rare crash in asan/lsan google/sanitizers#1193 Reviewers: vitalybuka Subscribers: #sanitizers, llvm-commits Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D80967
1 parent 8a8d703 commit 2e6c3e3

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

compiler-rt/lib/asan/asan_allocator.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,19 @@ uptr PointsIntoChunk(void* p) {
10371037
return 0;
10381038
}
10391039

1040+
// Debug code. Delete once issue #1193 is chased down.
1041+
extern "C" SANITIZER_WEAK_ATTRIBUTE const char *__lsan_current_stage;
1042+
10401043
uptr GetUserBegin(uptr chunk) {
10411044
__asan::AsanChunk *m = __asan::instance.GetAsanChunkByAddrFastLocked(chunk);
1045+
if (!m)
1046+
Printf(
1047+
"ASAN is about to crash with a CHECK failure.\n"
1048+
"The ASAN developers are trying to chaise down this bug,\n"
1049+
"so if you've encountered this bug please let us know.\n"
1050+
"See also: https://github.com/google/sanitizers/issues/1193\n"
1051+
"chunk: %p caller %p __lsan_current_stage %s\n",
1052+
chunk, GET_CALLER_PC(), __lsan_current_stage);
10421053
CHECK(m);
10431054
return m->Beg();
10441055
}

compiler-rt/lib/lsan/lsan_common.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "sanitizer_common/sanitizer_thread_registry.h"
2626
#include "sanitizer_common/sanitizer_tls_get_addr.h"
2727

28+
extern "C" const char *__lsan_current_stage = "unknown";
29+
2830
#if CAN_SANITIZE_LEAKS
2931
namespace __lsan {
3032

@@ -34,6 +36,7 @@ BlockingMutex global_mutex(LINKER_INITIALIZED);
3436

3537
Flags lsan_flags;
3638

39+
3740
void DisableCounterUnderflow() {
3841
if (common_flags()->detect_leaks) {
3942
Report("Unmatched call to __lsan_enable().\n");
@@ -363,6 +366,7 @@ static void FloodFillTag(Frontier *frontier, ChunkTag tag) {
363366
// ForEachChunk callback. If the chunk is marked as leaked, marks all chunks
364367
// which are reachable from it as indirectly leaked.
365368
static void MarkIndirectlyLeakedCb(uptr chunk, void *arg) {
369+
__lsan_current_stage = "MarkIndirectlyLeakedCb";
366370
chunk = GetUserBegin(chunk);
367371
LsanMetadata m(chunk);
368372
if (m.allocated() && m.tag() != kReachable) {
@@ -375,6 +379,7 @@ static void MarkIndirectlyLeakedCb(uptr chunk, void *arg) {
375379
// frontier.
376380
static void CollectIgnoredCb(uptr chunk, void *arg) {
377381
CHECK(arg);
382+
__lsan_current_stage = "CollectIgnoredCb";
378383
chunk = GetUserBegin(chunk);
379384
LsanMetadata m(chunk);
380385
if (m.allocated() && m.tag() == kIgnored) {
@@ -404,6 +409,7 @@ struct InvalidPCParam {
404409
static void MarkInvalidPCCb(uptr chunk, void *arg) {
405410
CHECK(arg);
406411
InvalidPCParam *param = reinterpret_cast<InvalidPCParam *>(arg);
412+
__lsan_current_stage = "MarkInvalidPCCb";
407413
chunk = GetUserBegin(chunk);
408414
LsanMetadata m(chunk);
409415
if (m.allocated() && m.tag() != kReachable && m.tag() != kIgnored) {
@@ -479,6 +485,7 @@ static void ClassifyAllChunks(SuspendedThreadsList const &suspended_threads,
479485
// ForEachChunk callback. Resets the tags to pre-leak-check state.
480486
static void ResetTagsCb(uptr chunk, void *arg) {
481487
(void)arg;
488+
__lsan_current_stage = "ResetTagsCb";
482489
chunk = GetUserBegin(chunk);
483490
LsanMetadata m(chunk);
484491
if (m.allocated() && m.tag() != kIgnored)
@@ -495,6 +502,7 @@ static void PrintStackTraceById(u32 stack_trace_id) {
495502
static void CollectLeaksCb(uptr chunk, void *arg) {
496503
CHECK(arg);
497504
LeakReport *leak_report = reinterpret_cast<LeakReport *>(arg);
505+
__lsan_current_stage = "CollectLeaksCb";
498506
chunk = GetUserBegin(chunk);
499507
LsanMetadata m(chunk);
500508
if (!m.allocated()) return;

0 commit comments

Comments
 (0)