tsan_rtl_report.cc revision 2bbd8bec77c2fdb41c5f5b6cb0d83d22bc576650
1//===-- tsan_rtl_report.cc ------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file is a part of ThreadSanitizer (TSan), a race detector. 11// 12//===----------------------------------------------------------------------===// 13 14#include "sanitizer_common/sanitizer_libc.h" 15#include "sanitizer_common/sanitizer_placement_new.h" 16#include "sanitizer_common/sanitizer_stackdepot.h" 17#include "sanitizer_common/sanitizer_common.h" 18#include "sanitizer_common/sanitizer_stacktrace.h" 19#include "tsan_platform.h" 20#include "tsan_rtl.h" 21#include "tsan_suppressions.h" 22#include "tsan_symbolize.h" 23#include "tsan_report.h" 24#include "tsan_sync.h" 25#include "tsan_mman.h" 26#include "tsan_flags.h" 27#include "tsan_fd.h" 28 29namespace __tsan { 30 31using namespace __sanitizer; // NOLINT 32 33static ReportStack *SymbolizeStack(const StackTrace& trace); 34 35void TsanCheckFailed(const char *file, int line, const char *cond, 36 u64 v1, u64 v2) { 37 ScopedInRtl in_rtl; 38 Printf("FATAL: ThreadSanitizer CHECK failed: " 39 "%s:%d \"%s\" (0x%zx, 0x%zx)\n", 40 file, line, cond, (uptr)v1, (uptr)v2); 41 PrintCurrentStackSlow(); 42 Die(); 43} 44 45// Can be overriden by an application/test to intercept reports. 46#ifdef TSAN_EXTERNAL_HOOKS 47bool OnReport(const ReportDesc *rep, bool suppressed); 48#else 49SANITIZER_INTERFACE_ATTRIBUTE 50bool WEAK OnReport(const ReportDesc *rep, bool suppressed) { 51 (void)rep; 52 return suppressed; 53} 54#endif 55 56static void StackStripMain(ReportStack *stack) { 57 ReportStack *last_frame = 0; 58 ReportStack *last_frame2 = 0; 59 const char *prefix = "__interceptor_"; 60 uptr prefix_len = internal_strlen(prefix); 61 const char *path_prefix = flags()->strip_path_prefix; 62 uptr path_prefix_len = internal_strlen(path_prefix); 63 char *pos; 64 for (ReportStack *ent = stack; ent; ent = ent->next) { 65 if (ent->func && 0 == internal_strncmp(ent->func, prefix, prefix_len)) 66 ent->func += prefix_len; 67 if (ent->file && (pos = internal_strstr(ent->file, path_prefix))) 68 ent->file = pos + path_prefix_len; 69 if (ent->file && ent->file[0] == '.' && ent->file[1] == '/') 70 ent->file += 2; 71 last_frame2 = last_frame; 72 last_frame = ent; 73 } 74 75 if (last_frame2 == 0) 76 return; 77 const char *last = last_frame->func; 78#ifndef TSAN_GO 79 const char *last2 = last_frame2->func; 80 // Strip frame above 'main' 81 if (last2 && 0 == internal_strcmp(last2, "main")) { 82 last_frame2->next = 0; 83 // Strip our internal thread start routine. 84 } else if (last && 0 == internal_strcmp(last, "__tsan_thread_start_func")) { 85 last_frame2->next = 0; 86 // Strip global ctors init. 87 } else if (last && 0 == internal_strcmp(last, "__do_global_ctors_aux")) { 88 last_frame2->next = 0; 89 // If both are 0, then we probably just failed to symbolize. 90 } else if (last || last2) { 91 // Ensure that we recovered stack completely. Trimmed stack 92 // can actually happen if we do not instrument some code, 93 // so it's only a debug print. However we must try hard to not miss it 94 // due to our fault. 95 DPrintf("Bottom stack frame of stack %zx is missed\n", stack->pc); 96 } 97#else 98 if (last && 0 == internal_strcmp(last, "schedunlock")) 99 last_frame2->next = 0; 100#endif 101} 102 103static ReportStack *SymbolizeStack(const StackTrace& trace) { 104 if (trace.IsEmpty()) 105 return 0; 106 ReportStack *stack = 0; 107 for (uptr si = 0; si < trace.Size(); si++) { 108 // We obtain the return address, that is, address of the next instruction, 109 // so offset it by 1 byte. 110 bool is_last = (si == trace.Size() - 1); 111 ReportStack *ent = SymbolizeCode(trace.Get(si) - !is_last); 112 CHECK_NE(ent, 0); 113 ReportStack *last = ent; 114 while (last->next) { 115 last->pc += !is_last; 116 last = last->next; 117 } 118 last->pc += !is_last; 119 last->next = stack; 120 stack = ent; 121 } 122 StackStripMain(stack); 123 return stack; 124} 125 126ScopedReport::ScopedReport(ReportType typ) { 127 ctx_ = CTX(); 128 ctx_->thread_registry->CheckLocked(); 129 void *mem = internal_alloc(MBlockReport, sizeof(ReportDesc)); 130 rep_ = new(mem) ReportDesc; 131 rep_->typ = typ; 132 ctx_->report_mtx.Lock(); 133} 134 135ScopedReport::~ScopedReport() { 136 ctx_->report_mtx.Unlock(); 137 DestroyAndFree(rep_); 138} 139 140void ScopedReport::AddStack(const StackTrace *stack) { 141 ReportStack **rs = rep_->stacks.PushBack(); 142 *rs = SymbolizeStack(*stack); 143} 144 145void ScopedReport::AddMemoryAccess(uptr addr, Shadow s, 146 const StackTrace *stack, const MutexSet *mset) { 147 void *mem = internal_alloc(MBlockReportMop, sizeof(ReportMop)); 148 ReportMop *mop = new(mem) ReportMop; 149 rep_->mops.PushBack(mop); 150 mop->tid = s.tid(); 151 mop->addr = addr + s.addr0(); 152 mop->size = s.size(); 153 mop->write = s.IsWrite(); 154 mop->atomic = s.IsAtomic(); 155 mop->stack = SymbolizeStack(*stack); 156 for (uptr i = 0; i < mset->Size(); i++) { 157 MutexSet::Desc d = mset->Get(i); 158 u64 uid = 0; 159 uptr addr = SyncVar::SplitId(d.id, &uid); 160 SyncVar *s = ctx_->synctab.GetIfExistsAndLock(addr, false); 161 // Check that the mutex is still alive. 162 // Another mutex can be created at the same address, 163 // so check uid as well. 164 if (s && s->CheckId(uid)) { 165 ReportMopMutex mtx = {s->uid, d.write}; 166 mop->mset.PushBack(mtx); 167 AddMutex(s); 168 } else { 169 ReportMopMutex mtx = {d.id, d.write}; 170 mop->mset.PushBack(mtx); 171 AddMutex(d.id); 172 } 173 if (s) 174 s->mtx.ReadUnlock(); 175 } 176} 177 178void ScopedReport::AddThread(const ThreadContext *tctx) { 179 for (uptr i = 0; i < rep_->threads.Size(); i++) { 180 if ((u32)rep_->threads[i]->id == tctx->tid) 181 return; 182 } 183 void *mem = internal_alloc(MBlockReportThread, sizeof(ReportThread)); 184 ReportThread *rt = new(mem) ReportThread(); 185 rep_->threads.PushBack(rt); 186 rt->id = tctx->tid; 187 rt->pid = tctx->os_id; 188 rt->running = (tctx->status == ThreadStatusRunning); 189 rt->name = tctx->name ? internal_strdup(tctx->name) : 0; 190 rt->parent_tid = tctx->parent_tid; 191 rt->stack = SymbolizeStack(tctx->creation_stack); 192} 193 194#ifndef TSAN_GO 195static ThreadContext *FindThreadLocked(int unique_id) { 196 Context *ctx = CTX(); 197 ctx->thread_registry->CheckLocked(); 198 for (unsigned i = 0; i < kMaxTid; i++) { 199 ThreadContext *tctx = static_cast<ThreadContext*>( 200 ctx->thread_registry->GetThreadLocked(i)); 201 if (tctx && tctx->unique_id == (u32)unique_id) { 202 return tctx; 203 } 204 } 205 return 0; 206} 207 208ThreadContext *IsThreadStackOrTls(uptr addr, bool *is_stack) { 209 Context *ctx = CTX(); 210 ctx->thread_registry->CheckLocked(); 211 for (unsigned i = 0; i < kMaxTid; i++) { 212 ThreadContext *tctx = static_cast<ThreadContext*>( 213 ctx->thread_registry->GetThreadLocked(i)); 214 if (tctx == 0 || tctx->status != ThreadStatusRunning) 215 continue; 216 ThreadState *thr = tctx->thr; 217 CHECK(thr); 218 if (addr >= thr->stk_addr && addr < thr->stk_addr + thr->stk_size) { 219 *is_stack = true; 220 return tctx; 221 } 222 if (addr >= thr->tls_addr && addr < thr->tls_addr + thr->tls_size) { 223 *is_stack = false; 224 return tctx; 225 } 226 } 227 return 0; 228} 229#endif 230 231void ScopedReport::AddMutex(const SyncVar *s) { 232 for (uptr i = 0; i < rep_->mutexes.Size(); i++) { 233 if (rep_->mutexes[i]->id == s->uid) 234 return; 235 } 236 void *mem = internal_alloc(MBlockReportMutex, sizeof(ReportMutex)); 237 ReportMutex *rm = new(mem) ReportMutex(); 238 rep_->mutexes.PushBack(rm); 239 rm->id = s->uid; 240 rm->destroyed = false; 241 rm->stack = SymbolizeStack(s->creation_stack); 242} 243 244void ScopedReport::AddMutex(u64 id) { 245 for (uptr i = 0; i < rep_->mutexes.Size(); i++) { 246 if (rep_->mutexes[i]->id == id) 247 return; 248 } 249 void *mem = internal_alloc(MBlockReportMutex, sizeof(ReportMutex)); 250 ReportMutex *rm = new(mem) ReportMutex(); 251 rep_->mutexes.PushBack(rm); 252 rm->id = id; 253 rm->destroyed = true; 254 rm->stack = 0; 255} 256 257void ScopedReport::AddLocation(uptr addr, uptr size) { 258 if (addr == 0) 259 return; 260#ifndef TSAN_GO 261 int fd = -1; 262 int creat_tid = -1; 263 u32 creat_stack = 0; 264 if (FdLocation(addr, &fd, &creat_tid, &creat_stack) 265 || FdLocation(AlternativeAddress(addr), &fd, &creat_tid, &creat_stack)) { 266 void *mem = internal_alloc(MBlockReportLoc, sizeof(ReportLocation)); 267 ReportLocation *loc = new(mem) ReportLocation(); 268 rep_->locs.PushBack(loc); 269 loc->type = ReportLocationFD; 270 loc->fd = fd; 271 loc->tid = creat_tid; 272 uptr ssz = 0; 273 const uptr *stack = StackDepotGet(creat_stack, &ssz); 274 if (stack) { 275 StackTrace trace; 276 trace.Init(stack, ssz); 277 loc->stack = SymbolizeStack(trace); 278 } 279 ThreadContext *tctx = FindThreadLocked(creat_tid); 280 if (tctx) 281 AddThread(tctx); 282 return; 283 } 284 if (allocator()->PointerIsMine((void*)addr)) { 285 MBlock *b = user_mblock(0, (void*)addr); 286 ThreadContext *tctx = FindThreadLocked(b->alloc_tid); 287 void *mem = internal_alloc(MBlockReportLoc, sizeof(ReportLocation)); 288 ReportLocation *loc = new(mem) ReportLocation(); 289 rep_->locs.PushBack(loc); 290 loc->type = ReportLocationHeap; 291 loc->addr = (uptr)allocator()->GetBlockBegin((void*)addr); 292 loc->size = b->size; 293 loc->tid = tctx ? tctx->tid : b->alloc_tid; 294 loc->name = 0; 295 loc->file = 0; 296 loc->line = 0; 297 loc->stack = 0; 298 uptr ssz = 0; 299 const uptr *stack = StackDepotGet(b->alloc_stack_id, &ssz); 300 if (stack) { 301 StackTrace trace; 302 trace.Init(stack, ssz); 303 loc->stack = SymbolizeStack(trace); 304 } 305 if (tctx) 306 AddThread(tctx); 307 return; 308 } 309 bool is_stack = false; 310 if (ThreadContext *tctx = IsThreadStackOrTls(addr, &is_stack)) { 311 void *mem = internal_alloc(MBlockReportLoc, sizeof(ReportLocation)); 312 ReportLocation *loc = new(mem) ReportLocation(); 313 rep_->locs.PushBack(loc); 314 loc->type = is_stack ? ReportLocationStack : ReportLocationTLS; 315 loc->tid = tctx->tid; 316 AddThread(tctx); 317 } 318 ReportLocation *loc = SymbolizeData(addr); 319 if (loc) { 320 rep_->locs.PushBack(loc); 321 return; 322 } 323#endif 324} 325 326#ifndef TSAN_GO 327void ScopedReport::AddSleep(u32 stack_id) { 328 uptr ssz = 0; 329 const uptr *stack = StackDepotGet(stack_id, &ssz); 330 if (stack) { 331 StackTrace trace; 332 trace.Init(stack, ssz); 333 rep_->sleep = SymbolizeStack(trace); 334 } 335} 336#endif 337 338const ReportDesc *ScopedReport::GetReport() const { 339 return rep_; 340} 341 342void RestoreStack(int tid, const u64 epoch, StackTrace *stk, MutexSet *mset) { 343 // This function restores stack trace and mutex set for the thread/epoch. 344 // It does so by getting stack trace and mutex set at the beginning of 345 // trace part, and then replaying the trace till the given epoch. 346 Context *ctx = CTX(); 347 ctx->thread_registry->CheckLocked(); 348 ThreadContext *tctx = static_cast<ThreadContext*>( 349 ctx->thread_registry->GetThreadLocked(tid)); 350 if (tctx == 0) 351 return; 352 Trace* trace = 0; 353 if (tctx->status == ThreadStatusRunning) { 354 CHECK(tctx->thr); 355 trace = &tctx->thr->trace; 356 } else if (tctx->status == ThreadStatusFinished 357 || tctx->status == ThreadStatusDead) { 358 if (tctx->dead_info == 0) 359 return; 360 trace = &tctx->dead_info->trace; 361 } else { 362 return; 363 } 364 Lock l(&trace->mtx); 365 const int partidx = (epoch / kTracePartSize) % TraceParts(); 366 TraceHeader* hdr = &trace->headers[partidx]; 367 if (epoch < hdr->epoch0) 368 return; 369 const u64 epoch0 = RoundDown(epoch, TraceSize()); 370 const u64 eend = epoch % TraceSize(); 371 const u64 ebegin = RoundDown(eend, kTracePartSize); 372 DPrintf("#%d: RestoreStack epoch=%zu ebegin=%zu eend=%zu partidx=%d\n", 373 tid, (uptr)epoch, (uptr)ebegin, (uptr)eend, partidx); 374 InternalScopedBuffer<uptr> stack(1024); // FIXME: de-hardcode 1024 375 for (uptr i = 0; i < hdr->stack0.Size(); i++) { 376 stack[i] = hdr->stack0.Get(i); 377 DPrintf2(" #%02lu: pc=%zx\n", i, stack[i]); 378 } 379 if (mset) 380 *mset = hdr->mset0; 381 uptr pos = hdr->stack0.Size(); 382 Event *events = (Event*)GetThreadTrace(tid); 383 for (uptr i = ebegin; i <= eend; i++) { 384 Event ev = events[i]; 385 EventType typ = (EventType)(ev >> 61); 386 uptr pc = (uptr)(ev & ((1ull << 61) - 1)); 387 DPrintf2(" %zu typ=%d pc=%zx\n", i, typ, pc); 388 if (typ == EventTypeMop) { 389 stack[pos] = pc; 390 } else if (typ == EventTypeFuncEnter) { 391 stack[pos++] = pc; 392 } else if (typ == EventTypeFuncExit) { 393 if (pos > 0) 394 pos--; 395 } 396 if (mset) { 397 if (typ == EventTypeLock) { 398 mset->Add(pc, true, epoch0 + i); 399 } else if (typ == EventTypeUnlock) { 400 mset->Del(pc, true); 401 } else if (typ == EventTypeRLock) { 402 mset->Add(pc, false, epoch0 + i); 403 } else if (typ == EventTypeRUnlock) { 404 mset->Del(pc, false); 405 } 406 } 407 for (uptr j = 0; j <= pos; j++) 408 DPrintf2(" #%zu: %zx\n", j, stack[j]); 409 } 410 if (pos == 0 && stack[0] == 0) 411 return; 412 pos++; 413 stk->Init(stack.data(), pos); 414} 415 416static bool HandleRacyStacks(ThreadState *thr, const StackTrace (&traces)[2], 417 uptr addr_min, uptr addr_max) { 418 Context *ctx = CTX(); 419 bool equal_stack = false; 420 RacyStacks hash; 421 if (flags()->suppress_equal_stacks) { 422 hash.hash[0] = md5_hash(traces[0].Begin(), traces[0].Size() * sizeof(uptr)); 423 hash.hash[1] = md5_hash(traces[1].Begin(), traces[1].Size() * sizeof(uptr)); 424 for (uptr i = 0; i < ctx->racy_stacks.Size(); i++) { 425 if (hash == ctx->racy_stacks[i]) { 426 DPrintf("ThreadSanitizer: suppressing report as doubled (stack)\n"); 427 equal_stack = true; 428 break; 429 } 430 } 431 } 432 bool equal_address = false; 433 RacyAddress ra0 = {addr_min, addr_max}; 434 if (flags()->suppress_equal_addresses) { 435 for (uptr i = 0; i < ctx->racy_addresses.Size(); i++) { 436 RacyAddress ra2 = ctx->racy_addresses[i]; 437 uptr maxbeg = max(ra0.addr_min, ra2.addr_min); 438 uptr minend = min(ra0.addr_max, ra2.addr_max); 439 if (maxbeg < minend) { 440 DPrintf("ThreadSanitizer: suppressing report as doubled (addr)\n"); 441 equal_address = true; 442 break; 443 } 444 } 445 } 446 if (equal_stack || equal_address) { 447 if (!equal_stack) 448 ctx->racy_stacks.PushBack(hash); 449 if (!equal_address) 450 ctx->racy_addresses.PushBack(ra0); 451 return true; 452 } 453 return false; 454} 455 456static void AddRacyStacks(ThreadState *thr, const StackTrace (&traces)[2], 457 uptr addr_min, uptr addr_max) { 458 Context *ctx = CTX(); 459 if (flags()->suppress_equal_stacks) { 460 RacyStacks hash; 461 hash.hash[0] = md5_hash(traces[0].Begin(), traces[0].Size() * sizeof(uptr)); 462 hash.hash[1] = md5_hash(traces[1].Begin(), traces[1].Size() * sizeof(uptr)); 463 ctx->racy_stacks.PushBack(hash); 464 } 465 if (flags()->suppress_equal_addresses) { 466 RacyAddress ra0 = {addr_min, addr_max}; 467 ctx->racy_addresses.PushBack(ra0); 468 } 469} 470 471bool OutputReport(Context *ctx, 472 const ScopedReport &srep, 473 const ReportStack *suppress_stack1, 474 const ReportStack *suppress_stack2) { 475 const ReportDesc *rep = srep.GetReport(); 476 uptr suppress_pc = IsSuppressed(rep->typ, suppress_stack1); 477 if (suppress_pc == 0) 478 suppress_pc = IsSuppressed(rep->typ, suppress_stack2); 479 if (suppress_pc != 0) { 480 FiredSuppression supp = {srep.GetReport()->typ, suppress_pc}; 481 ctx->fired_suppressions.PushBack(supp); 482 } 483 if (OnReport(rep, suppress_pc != 0)) 484 return false; 485 PrintReport(rep); 486 CTX()->nreported++; 487 return true; 488} 489 490bool IsFiredSuppression(Context *ctx, 491 const ScopedReport &srep, 492 const StackTrace &trace) { 493 for (uptr k = 0; k < ctx->fired_suppressions.Size(); k++) { 494 if (ctx->fired_suppressions[k].type != srep.GetReport()->typ) 495 continue; 496 for (uptr j = 0; j < trace.Size(); j++) { 497 if (trace.Get(j) == ctx->fired_suppressions[k].pc) 498 return true; 499 } 500 } 501 return false; 502} 503 504bool FrameIsInternal(const ReportStack *frame) { 505 return frame != 0 && frame->file != 0 506 && (internal_strstr(frame->file, "tsan_interceptors.cc") || 507 internal_strstr(frame->file, "sanitizer_common_interceptors.inc") || 508 internal_strstr(frame->file, "tsan_interface_")); 509} 510 511// On programs that use Java we see weird reports like: 512// WARNING: ThreadSanitizer: data race (pid=22512) 513// Read of size 8 at 0x7d2b00084318 by thread 100: 514// #0 memcpy tsan_interceptors.cc:406 (foo+0x00000d8dfae3) 515// #1 <null> <null>:0 (0x7f7ad9b40193) 516// Previous write of size 8 at 0x7d2b00084318 by thread 105: 517// #0 strncpy tsan_interceptors.cc:501 (foo+0x00000d8e0919) 518// #1 <null> <null>:0 (0x7f7ad9b42707) 519static bool IsJavaNonsense(const ReportDesc *rep) { 520#ifndef TSAN_GO 521 for (uptr i = 0; i < rep->mops.Size(); i++) { 522 ReportMop *mop = rep->mops[i]; 523 ReportStack *frame = mop->stack; 524 if (frame == 0 525 || (frame->func == 0 && frame->file == 0 && frame->line == 0 526 && frame->module == 0)) { 527 return true; 528 } 529 if (FrameIsInternal(frame)) { 530 frame = frame->next; 531 if (frame == 0 532 || (frame->func == 0 && frame->file == 0 && frame->line == 0 533 && frame->module == 0)) { 534 if (frame) { 535 FiredSuppression supp = {rep->typ, frame->pc}; 536 CTX()->fired_suppressions.PushBack(supp); 537 } 538 return true; 539 } 540 } 541 } 542#endif 543 return false; 544} 545 546static bool RaceBetweenAtomicAndFree(ThreadState *thr) { 547 Shadow s0(thr->racy_state[0]); 548 Shadow s1(thr->racy_state[1]); 549 CHECK(!(s0.IsAtomic() && s1.IsAtomic())); 550 if (!s0.IsAtomic() && !s1.IsAtomic()) 551 return true; 552 if (s0.IsAtomic() && s1.IsFreed()) 553 return true; 554 if (s1.IsAtomic() && thr->is_freeing) 555 return true; 556 return false; 557} 558 559void ReportRace(ThreadState *thr) { 560 if (!flags()->report_bugs) 561 return; 562 ScopedInRtl in_rtl; 563 564 if (!flags()->report_atomic_races && !RaceBetweenAtomicAndFree(thr)) 565 return; 566 567 if (thr->in_signal_handler) 568 Printf("ThreadSanitizer: printing report from signal handler." 569 " Can crash or hang.\n"); 570 571 bool freed = false; 572 { 573 Shadow s(thr->racy_state[1]); 574 freed = s.GetFreedAndReset(); 575 thr->racy_state[1] = s.raw(); 576 } 577 578 uptr addr = ShadowToMem((uptr)thr->racy_shadow_addr); 579 uptr addr_min = 0; 580 uptr addr_max = 0; 581 { 582 uptr a0 = addr + Shadow(thr->racy_state[0]).addr0(); 583 uptr a1 = addr + Shadow(thr->racy_state[1]).addr0(); 584 uptr e0 = a0 + Shadow(thr->racy_state[0]).size(); 585 uptr e1 = a1 + Shadow(thr->racy_state[1]).size(); 586 addr_min = min(a0, a1); 587 addr_max = max(e0, e1); 588 if (IsExpectedReport(addr_min, addr_max - addr_min)) 589 return; 590 } 591 592 Context *ctx = CTX(); 593 ThreadRegistryLock l0(ctx->thread_registry); 594 595 ScopedReport rep(freed ? ReportTypeUseAfterFree : ReportTypeRace); 596 const uptr kMop = 2; 597 StackTrace traces[kMop]; 598 const uptr toppc = TraceTopPC(thr); 599 traces[0].ObtainCurrent(thr, toppc); 600 if (IsFiredSuppression(ctx, rep, traces[0])) 601 return; 602 InternalScopedBuffer<MutexSet> mset2(1); 603 new(mset2.data()) MutexSet(); 604 Shadow s2(thr->racy_state[1]); 605 RestoreStack(s2.tid(), s2.epoch(), &traces[1], mset2.data()); 606 607 if (HandleRacyStacks(thr, traces, addr_min, addr_max)) 608 return; 609 610 for (uptr i = 0; i < kMop; i++) { 611 Shadow s(thr->racy_state[i]); 612 rep.AddMemoryAccess(addr, s, &traces[i], 613 i == 0 ? &thr->mset : mset2.data()); 614 } 615 616 if (flags()->suppress_java && IsJavaNonsense(rep.GetReport())) 617 return; 618 619 for (uptr i = 0; i < kMop; i++) { 620 FastState s(thr->racy_state[i]); 621 ThreadContext *tctx = static_cast<ThreadContext*>( 622 ctx->thread_registry->GetThreadLocked(s.tid())); 623 if (s.epoch() < tctx->epoch0 || s.epoch() > tctx->epoch1) 624 continue; 625 rep.AddThread(tctx); 626 } 627 628 rep.AddLocation(addr_min, addr_max - addr_min); 629 630#ifndef TSAN_GO 631 { // NOLINT 632 Shadow s(thr->racy_state[1]); 633 if (s.epoch() <= thr->last_sleep_clock.get(s.tid())) 634 rep.AddSleep(thr->last_sleep_stack_id); 635 } 636#endif 637 638 if (!OutputReport(ctx, rep, rep.GetReport()->mops[0]->stack, 639 rep.GetReport()->mops[1]->stack)) 640 return; 641 642 AddRacyStacks(thr, traces, addr_min, addr_max); 643} 644 645void PrintCurrentStack(ThreadState *thr, uptr pc) { 646 StackTrace trace; 647 trace.ObtainCurrent(thr, pc); 648 PrintStack(SymbolizeStack(trace)); 649} 650 651void PrintCurrentStackSlow() { 652#ifndef TSAN_GO 653 __sanitizer::StackTrace *ptrace = new(internal_alloc(MBlockStackTrace, 654 sizeof(__sanitizer::StackTrace))) __sanitizer::StackTrace; 655 ptrace->SlowUnwindStack(__sanitizer::StackTrace::GetCurrentPc(), 656 kStackTraceMax); 657 StackTrace trace; 658 trace.Init(ptrace->trace, ptrace->size); 659 PrintStack(SymbolizeStack(trace)); 660#endif 661} 662 663} // namespace __tsan 664