1 //===-- tsan_rtl_report.cc ------------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
10 //===----------------------------------------------------------------------===//
12 #include "sanitizer_common/sanitizer_libc.h"
13 #include "sanitizer_common/sanitizer_placement_new.h"
14 #include "sanitizer_common/sanitizer_stackdepot.h"
15 #include "sanitizer_common/sanitizer_common.h"
16 #include "sanitizer_common/sanitizer_stacktrace.h"
17 #include "tsan_platform.h"
19 #include "tsan_suppressions.h"
20 #include "tsan_symbolize.h"
21 #include "tsan_report.h"
22 #include "tsan_sync.h"
23 #include "tsan_mman.h"
24 #include "tsan_flags.h"
29 using namespace __sanitizer
; // NOLINT
31 static ReportStack
*SymbolizeStack(const StackTrace
& trace
);
33 void TsanCheckFailed(const char *file
, int line
, const char *cond
,
35 // There is high probability that interceptors will check-fail as well,
36 // on the other hand there is no sense in processing interceptors
37 // since we are going to die soon.
38 ScopedIgnoreInterceptors ignore
;
39 Printf("FATAL: ThreadSanitizer CHECK failed: "
40 "%s:%d \"%s\" (0x%zx, 0x%zx)\n",
41 file
, line
, cond
, (uptr
)v1
, (uptr
)v2
);
42 PrintCurrentStackSlow();
46 // Can be overriden by an application/test to intercept reports.
47 #ifdef TSAN_EXTERNAL_HOOKS
48 bool OnReport(const ReportDesc
*rep
, bool suppressed
);
50 SANITIZER_INTERFACE_ATTRIBUTE
51 bool WEAK
OnReport(const ReportDesc
*rep
, bool suppressed
) {
57 static void StackStripMain(ReportStack
*stack
) {
58 ReportStack
*last_frame
= 0;
59 ReportStack
*last_frame2
= 0;
60 const char *prefix
= "__interceptor_";
61 uptr prefix_len
= internal_strlen(prefix
);
62 const char *path_prefix
= common_flags()->strip_path_prefix
;
63 uptr path_prefix_len
= internal_strlen(path_prefix
);
65 for (ReportStack
*ent
= stack
; ent
; ent
= ent
->next
) {
66 if (ent
->func
&& 0 == internal_strncmp(ent
->func
, prefix
, prefix_len
))
67 ent
->func
+= prefix_len
;
68 if (ent
->file
&& (pos
= internal_strstr(ent
->file
, path_prefix
)))
69 ent
->file
= pos
+ path_prefix_len
;
70 if (ent
->file
&& ent
->file
[0] == '.' && ent
->file
[1] == '/')
72 last_frame2
= last_frame
;
78 const char *last
= last_frame
->func
;
80 const char *last2
= last_frame2
->func
;
81 // Strip frame above 'main'
82 if (last2
&& 0 == internal_strcmp(last2
, "main")) {
83 last_frame2
->next
= 0;
84 // Strip our internal thread start routine.
85 } else if (last
&& 0 == internal_strcmp(last
, "__tsan_thread_start_func")) {
86 last_frame2
->next
= 0;
87 // Strip global ctors init.
88 } else if (last
&& 0 == internal_strcmp(last
, "__do_global_ctors_aux")) {
89 last_frame2
->next
= 0;
90 // If both are 0, then we probably just failed to symbolize.
91 } else if (last
|| last2
) {
92 // Ensure that we recovered stack completely. Trimmed stack
93 // can actually happen if we do not instrument some code,
94 // so it's only a debug print. However we must try hard to not miss it
96 DPrintf("Bottom stack frame of stack %zx is missed\n", stack
->pc
);
99 // The last frame always point into runtime (gosched0, goexit0, runtime.main).
100 last_frame2
->next
= 0;
105 ReportStack
*SymbolizeStackId(u32 stack_id
) {
109 const uptr
*stack
= StackDepotGet(stack_id
, &ssz
);
113 trace
.Init(stack
, ssz
);
114 return SymbolizeStack(trace
);
117 static ReportStack
*SymbolizeStack(const StackTrace
& trace
) {
120 ReportStack
*stack
= 0;
121 for (uptr si
= 0; si
< trace
.Size(); si
++) {
122 const uptr pc
= trace
.Get(si
);
124 // We obtain the return address, that is, address of the next instruction,
125 // so offset it by 1 byte.
126 const uptr pc1
= __sanitizer::StackTrace::GetPreviousInstructionPc(pc
);
128 // FIXME(dvyukov): Go sometimes uses address of a function as top pc.
130 if (si
!= trace
.Size() - 1)
133 ReportStack
*ent
= SymbolizeCode(pc1
);
135 ReportStack
*last
= ent
;
137 last
->pc
= pc
; // restore original pc for report
140 last
->pc
= pc
; // restore original pc for report
144 StackStripMain(stack
);
148 ScopedReport::ScopedReport(ReportType typ
) {
149 ctx
->thread_registry
->CheckLocked();
150 void *mem
= internal_alloc(MBlockReport
, sizeof(ReportDesc
));
151 rep_
= new(mem
) ReportDesc
;
153 ctx
->report_mtx
.Lock();
154 CommonSanitizerReportMutex
.Lock();
157 ScopedReport::~ScopedReport() {
158 CommonSanitizerReportMutex
.Unlock();
159 ctx
->report_mtx
.Unlock();
160 DestroyAndFree(rep_
);
163 void ScopedReport::AddStack(const StackTrace
*stack
, bool suppressable
) {
164 ReportStack
**rs
= rep_
->stacks
.PushBack();
165 *rs
= SymbolizeStack(*stack
);
166 (*rs
)->suppressable
= suppressable
;
169 void ScopedReport::AddMemoryAccess(uptr addr
, Shadow s
,
170 const StackTrace
*stack
, const MutexSet
*mset
) {
171 void *mem
= internal_alloc(MBlockReportMop
, sizeof(ReportMop
));
172 ReportMop
*mop
= new(mem
) ReportMop
;
173 rep_
->mops
.PushBack(mop
);
175 mop
->addr
= addr
+ s
.addr0();
176 mop
->size
= s
.size();
177 mop
->write
= s
.IsWrite();
178 mop
->atomic
= s
.IsAtomic();
179 mop
->stack
= SymbolizeStack(*stack
);
181 mop
->stack
->suppressable
= true;
182 for (uptr i
= 0; i
< mset
->Size(); i
++) {
183 MutexSet::Desc d
= mset
->Get(i
);
184 u64 mid
= this->AddMutex(d
.id
);
185 ReportMopMutex mtx
= {mid
, d
.write
};
186 mop
->mset
.PushBack(mtx
);
190 void ScopedReport::AddUniqueTid(int unique_tid
) {
191 rep_
->unique_tids
.PushBack(unique_tid
);
194 void ScopedReport::AddThread(const ThreadContext
*tctx
, bool suppressable
) {
195 for (uptr i
= 0; i
< rep_
->threads
.Size(); i
++) {
196 if ((u32
)rep_
->threads
[i
]->id
== tctx
->tid
)
199 void *mem
= internal_alloc(MBlockReportThread
, sizeof(ReportThread
));
200 ReportThread
*rt
= new(mem
) ReportThread();
201 rep_
->threads
.PushBack(rt
);
203 rt
->pid
= tctx
->os_id
;
204 rt
->running
= (tctx
->status
== ThreadStatusRunning
);
205 rt
->name
= internal_strdup(tctx
->name
);
206 rt
->parent_tid
= tctx
->parent_tid
;
208 rt
->stack
= SymbolizeStackId(tctx
->creation_stack_id
);
210 rt
->stack
->suppressable
= suppressable
;
214 static ThreadContext
*FindThreadByUidLocked(int unique_id
) {
215 ctx
->thread_registry
->CheckLocked();
216 for (unsigned i
= 0; i
< kMaxTid
; i
++) {
217 ThreadContext
*tctx
= static_cast<ThreadContext
*>(
218 ctx
->thread_registry
->GetThreadLocked(i
));
219 if (tctx
&& tctx
->unique_id
== (u32
)unique_id
) {
226 static ThreadContext
*FindThreadByTidLocked(int tid
) {
227 ctx
->thread_registry
->CheckLocked();
228 return static_cast<ThreadContext
*>(
229 ctx
->thread_registry
->GetThreadLocked(tid
));
232 static bool IsInStackOrTls(ThreadContextBase
*tctx_base
, void *arg
) {
233 uptr addr
= (uptr
)arg
;
234 ThreadContext
*tctx
= static_cast<ThreadContext
*>(tctx_base
);
235 if (tctx
->status
!= ThreadStatusRunning
)
237 ThreadState
*thr
= tctx
->thr
;
239 return ((addr
>= thr
->stk_addr
&& addr
< thr
->stk_addr
+ thr
->stk_size
) ||
240 (addr
>= thr
->tls_addr
&& addr
< thr
->tls_addr
+ thr
->tls_size
));
243 ThreadContext
*IsThreadStackOrTls(uptr addr
, bool *is_stack
) {
244 ctx
->thread_registry
->CheckLocked();
245 ThreadContext
*tctx
= static_cast<ThreadContext
*>(
246 ctx
->thread_registry
->FindThreadContextLocked(IsInStackOrTls
,
250 ThreadState
*thr
= tctx
->thr
;
252 *is_stack
= (addr
>= thr
->stk_addr
&& addr
< thr
->stk_addr
+ thr
->stk_size
);
257 void ScopedReport::AddThread(int unique_tid
, bool suppressable
) {
259 AddThread(FindThreadByUidLocked(unique_tid
), suppressable
);
263 void ScopedReport::AddMutex(const SyncVar
*s
) {
264 for (uptr i
= 0; i
< rep_
->mutexes
.Size(); i
++) {
265 if (rep_
->mutexes
[i
]->id
== s
->uid
)
268 void *mem
= internal_alloc(MBlockReportMutex
, sizeof(ReportMutex
));
269 ReportMutex
*rm
= new(mem
) ReportMutex();
270 rep_
->mutexes
.PushBack(rm
);
273 rm
->destroyed
= false;
274 rm
->stack
= SymbolizeStackId(s
->creation_stack_id
);
277 u64
ScopedReport::AddMutex(u64 id
) {
280 uptr addr
= SyncVar::SplitId(id
, &uid
);
281 SyncVar
*s
= ctx
->metamap
.GetIfExistsAndLock(addr
);
282 // Check that the mutex is still alive.
283 // Another mutex can be created at the same address,
284 // so check uid as well.
285 if (s
&& s
->CheckId(uid
)) {
296 void ScopedReport::AddDeadMutex(u64 id
) {
297 for (uptr i
= 0; i
< rep_
->mutexes
.Size(); i
++) {
298 if (rep_
->mutexes
[i
]->id
== id
)
301 void *mem
= internal_alloc(MBlockReportMutex
, sizeof(ReportMutex
));
302 ReportMutex
*rm
= new(mem
) ReportMutex();
303 rep_
->mutexes
.PushBack(rm
);
306 rm
->destroyed
= true;
310 void ScopedReport::AddLocation(uptr addr
, uptr size
) {
317 if (FdLocation(addr
, &fd
, &creat_tid
, &creat_stack
)) {
318 void *mem
= internal_alloc(MBlockReportLoc
, sizeof(ReportLocation
));
319 ReportLocation
*loc
= new(mem
) ReportLocation();
320 rep_
->locs
.PushBack(loc
);
321 loc
->type
= ReportLocationFD
;
323 loc
->tid
= creat_tid
;
324 loc
->stack
= SymbolizeStackId(creat_stack
);
325 ThreadContext
*tctx
= FindThreadByUidLocked(creat_tid
);
331 Allocator
*a
= allocator();
332 if (a
->PointerIsMine((void*)addr
)) {
333 void *block_begin
= a
->GetBlockBegin((void*)addr
);
335 b
= ctx
->metamap
.GetBlock((uptr
)block_begin
);
338 ThreadContext
*tctx
= FindThreadByTidLocked(b
->tid
);
339 void *mem
= internal_alloc(MBlockReportLoc
, sizeof(ReportLocation
));
340 ReportLocation
*loc
= new(mem
) ReportLocation();
341 rep_
->locs
.PushBack(loc
);
342 loc
->type
= ReportLocationHeap
;
343 loc
->addr
= (uptr
)allocator()->GetBlockBegin((void*)addr
);
345 loc
->tid
= tctx
? tctx
->tid
: b
->tid
;
350 loc
->stack
= SymbolizeStackId(b
->stk
);
355 bool is_stack
= false;
356 if (ThreadContext
*tctx
= IsThreadStackOrTls(addr
, &is_stack
)) {
357 void *mem
= internal_alloc(MBlockReportLoc
, sizeof(ReportLocation
));
358 ReportLocation
*loc
= new(mem
) ReportLocation();
359 rep_
->locs
.PushBack(loc
);
360 loc
->type
= is_stack
? ReportLocationStack
: ReportLocationTLS
;
361 loc
->tid
= tctx
->tid
;
364 ReportLocation
*loc
= SymbolizeData(addr
);
366 loc
->suppressable
= true;
367 rep_
->locs
.PushBack(loc
);
374 void ScopedReport::AddSleep(u32 stack_id
) {
375 rep_
->sleep
= SymbolizeStackId(stack_id
);
379 void ScopedReport::SetCount(int count
) {
383 const ReportDesc
*ScopedReport::GetReport() const {
387 void RestoreStack(int tid
, const u64 epoch
, StackTrace
*stk
, MutexSet
*mset
) {
388 // This function restores stack trace and mutex set for the thread/epoch.
389 // It does so by getting stack trace and mutex set at the beginning of
390 // trace part, and then replaying the trace till the given epoch.
391 ctx
->thread_registry
->CheckLocked();
392 ThreadContext
*tctx
= static_cast<ThreadContext
*>(
393 ctx
->thread_registry
->GetThreadLocked(tid
));
396 if (tctx
->status
!= ThreadStatusRunning
397 && tctx
->status
!= ThreadStatusFinished
398 && tctx
->status
!= ThreadStatusDead
)
400 Trace
* trace
= ThreadTrace(tctx
->tid
);
402 const int partidx
= (epoch
/ kTracePartSize
) % TraceParts();
403 TraceHeader
* hdr
= &trace
->headers
[partidx
];
404 if (epoch
< hdr
->epoch0
)
406 const u64 epoch0
= RoundDown(epoch
, TraceSize());
407 const u64 eend
= epoch
% TraceSize();
408 const u64 ebegin
= RoundDown(eend
, kTracePartSize
);
409 DPrintf("#%d: RestoreStack epoch=%zu ebegin=%zu eend=%zu partidx=%d\n",
410 tid
, (uptr
)epoch
, (uptr
)ebegin
, (uptr
)eend
, partidx
);
411 InternalScopedBuffer
<uptr
> stack(kShadowStackSize
);
412 for (uptr i
= 0; i
< hdr
->stack0
.Size(); i
++) {
413 stack
[i
] = hdr
->stack0
.Get(i
);
414 DPrintf2(" #%02lu: pc=%zx\n", i
, stack
[i
]);
418 uptr pos
= hdr
->stack0
.Size();
419 Event
*events
= (Event
*)GetThreadTrace(tid
);
420 for (uptr i
= ebegin
; i
<= eend
; i
++) {
421 Event ev
= events
[i
];
422 EventType typ
= (EventType
)(ev
>> 61);
423 uptr pc
= (uptr
)(ev
& ((1ull << 61) - 1));
424 DPrintf2(" %zu typ=%d pc=%zx\n", i
, typ
, pc
);
425 if (typ
== EventTypeMop
) {
427 } else if (typ
== EventTypeFuncEnter
) {
429 } else if (typ
== EventTypeFuncExit
) {
434 if (typ
== EventTypeLock
) {
435 mset
->Add(pc
, true, epoch0
+ i
);
436 } else if (typ
== EventTypeUnlock
) {
438 } else if (typ
== EventTypeRLock
) {
439 mset
->Add(pc
, false, epoch0
+ i
);
440 } else if (typ
== EventTypeRUnlock
) {
441 mset
->Del(pc
, false);
444 for (uptr j
= 0; j
<= pos
; j
++)
445 DPrintf2(" #%zu: %zx\n", j
, stack
[j
]);
447 if (pos
== 0 && stack
[0] == 0)
450 stk
->Init(stack
.data(), pos
);
453 static bool HandleRacyStacks(ThreadState
*thr
, const StackTrace (&traces
)[2],
454 uptr addr_min
, uptr addr_max
) {
455 bool equal_stack
= false;
457 if (flags()->suppress_equal_stacks
) {
458 hash
.hash
[0] = md5_hash(traces
[0].Begin(), traces
[0].Size() * sizeof(uptr
));
459 hash
.hash
[1] = md5_hash(traces
[1].Begin(), traces
[1].Size() * sizeof(uptr
));
460 for (uptr i
= 0; i
< ctx
->racy_stacks
.Size(); i
++) {
461 if (hash
== ctx
->racy_stacks
[i
]) {
462 DPrintf("ThreadSanitizer: suppressing report as doubled (stack)\n");
468 bool equal_address
= false;
469 RacyAddress ra0
= {addr_min
, addr_max
};
470 if (flags()->suppress_equal_addresses
) {
471 for (uptr i
= 0; i
< ctx
->racy_addresses
.Size(); i
++) {
472 RacyAddress ra2
= ctx
->racy_addresses
[i
];
473 uptr maxbeg
= max(ra0
.addr_min
, ra2
.addr_min
);
474 uptr minend
= min(ra0
.addr_max
, ra2
.addr_max
);
475 if (maxbeg
< minend
) {
476 DPrintf("ThreadSanitizer: suppressing report as doubled (addr)\n");
477 equal_address
= true;
482 if (equal_stack
|| equal_address
) {
484 ctx
->racy_stacks
.PushBack(hash
);
486 ctx
->racy_addresses
.PushBack(ra0
);
492 static void AddRacyStacks(ThreadState
*thr
, const StackTrace (&traces
)[2],
493 uptr addr_min
, uptr addr_max
) {
494 if (flags()->suppress_equal_stacks
) {
496 hash
.hash
[0] = md5_hash(traces
[0].Begin(), traces
[0].Size() * sizeof(uptr
));
497 hash
.hash
[1] = md5_hash(traces
[1].Begin(), traces
[1].Size() * sizeof(uptr
));
498 ctx
->racy_stacks
.PushBack(hash
);
500 if (flags()->suppress_equal_addresses
) {
501 RacyAddress ra0
= {addr_min
, addr_max
};
502 ctx
->racy_addresses
.PushBack(ra0
);
506 bool OutputReport(ThreadState
*thr
, const ScopedReport
&srep
) {
507 atomic_store(&ctx
->last_symbolize_time_ns
, NanoTime(), memory_order_relaxed
);
508 const ReportDesc
*rep
= srep
.GetReport();
509 Suppression
*supp
= 0;
510 uptr suppress_pc
= 0;
511 for (uptr i
= 0; suppress_pc
== 0 && i
< rep
->mops
.Size(); i
++)
512 suppress_pc
= IsSuppressed(rep
->typ
, rep
->mops
[i
]->stack
, &supp
);
513 for (uptr i
= 0; suppress_pc
== 0 && i
< rep
->stacks
.Size(); i
++)
514 suppress_pc
= IsSuppressed(rep
->typ
, rep
->stacks
[i
], &supp
);
515 for (uptr i
= 0; suppress_pc
== 0 && i
< rep
->threads
.Size(); i
++)
516 suppress_pc
= IsSuppressed(rep
->typ
, rep
->threads
[i
]->stack
, &supp
);
517 for (uptr i
= 0; suppress_pc
== 0 && i
< rep
->locs
.Size(); i
++)
518 suppress_pc
= IsSuppressed(rep
->typ
, rep
->locs
[i
], &supp
);
519 if (suppress_pc
!= 0) {
520 FiredSuppression s
= {srep
.GetReport()->typ
, suppress_pc
, supp
};
521 ctx
->fired_suppressions
.push_back(s
);
524 bool old_is_freeing
= thr
->is_freeing
;
525 thr
->is_freeing
= false;
526 bool suppressed
= OnReport(rep
, suppress_pc
!= 0);
527 thr
->is_freeing
= old_is_freeing
;
533 if (flags()->halt_on_error
)
534 internal__exit(flags()->exitcode
);
538 bool IsFiredSuppression(Context
*ctx
,
539 const ScopedReport
&srep
,
540 const StackTrace
&trace
) {
541 for (uptr k
= 0; k
< ctx
->fired_suppressions
.size(); k
++) {
542 if (ctx
->fired_suppressions
[k
].type
!= srep
.GetReport()->typ
)
544 for (uptr j
= 0; j
< trace
.Size(); j
++) {
545 FiredSuppression
*s
= &ctx
->fired_suppressions
[k
];
546 if (trace
.Get(j
) == s
->pc
) {
548 s
->supp
->hit_count
++;
556 static bool IsFiredSuppression(Context
*ctx
,
557 const ScopedReport
&srep
,
559 for (uptr k
= 0; k
< ctx
->fired_suppressions
.size(); k
++) {
560 if (ctx
->fired_suppressions
[k
].type
!= srep
.GetReport()->typ
)
562 FiredSuppression
*s
= &ctx
->fired_suppressions
[k
];
565 s
->supp
->hit_count
++;
572 bool FrameIsInternal(const ReportStack
*frame
) {
573 return frame
!= 0 && frame
->file
!= 0
574 && (internal_strstr(frame
->file
, "tsan_interceptors.cc") ||
575 internal_strstr(frame
->file
, "sanitizer_common_interceptors.inc") ||
576 internal_strstr(frame
->file
, "tsan_interface_"));
579 static bool RaceBetweenAtomicAndFree(ThreadState
*thr
) {
580 Shadow
s0(thr
->racy_state
[0]);
581 Shadow
s1(thr
->racy_state
[1]);
582 CHECK(!(s0
.IsAtomic() && s1
.IsAtomic()));
583 if (!s0
.IsAtomic() && !s1
.IsAtomic())
585 if (s0
.IsAtomic() && s1
.IsFreed())
587 if (s1
.IsAtomic() && thr
->is_freeing
)
592 void ReportRace(ThreadState
*thr
) {
595 // Symbolizer makes lots of intercepted calls. If we try to process them,
596 // at best it will cause deadlocks on internal mutexes.
597 ScopedIgnoreInterceptors ignore
;
599 if (!flags()->report_bugs
)
601 if (!flags()->report_atomic_races
&& !RaceBetweenAtomicAndFree(thr
))
606 Shadow
s(thr
->racy_state
[1]);
607 freed
= s
.GetFreedAndReset();
608 thr
->racy_state
[1] = s
.raw();
611 uptr addr
= ShadowToMem((uptr
)thr
->racy_shadow_addr
);
615 uptr a0
= addr
+ Shadow(thr
->racy_state
[0]).addr0();
616 uptr a1
= addr
+ Shadow(thr
->racy_state
[1]).addr0();
617 uptr e0
= a0
+ Shadow(thr
->racy_state
[0]).size();
618 uptr e1
= a1
+ Shadow(thr
->racy_state
[1]).size();
619 addr_min
= min(a0
, a1
);
620 addr_max
= max(e0
, e1
);
621 if (IsExpectedReport(addr_min
, addr_max
- addr_min
))
625 ThreadRegistryLock
l0(ctx
->thread_registry
);
627 ReportType typ
= ReportTypeRace
;
628 if (thr
->is_vptr_access
)
629 typ
= ReportTypeVptrRace
;
631 typ
= ReportTypeUseAfterFree
;
632 ScopedReport
rep(typ
);
633 if (IsFiredSuppression(ctx
, rep
, addr
))
636 StackTrace traces
[kMop
];
637 const uptr toppc
= TraceTopPC(thr
);
638 traces
[0].ObtainCurrent(thr
, toppc
);
639 if (IsFiredSuppression(ctx
, rep
, traces
[0]))
641 InternalScopedBuffer
<MutexSet
> mset2(1);
642 new(mset2
.data()) MutexSet();
643 Shadow
s2(thr
->racy_state
[1]);
644 RestoreStack(s2
.tid(), s2
.epoch(), &traces
[1], mset2
.data());
645 if (IsFiredSuppression(ctx
, rep
, traces
[1]))
648 if (HandleRacyStacks(thr
, traces
, addr_min
, addr_max
))
651 for (uptr i
= 0; i
< kMop
; i
++) {
652 Shadow
s(thr
->racy_state
[i
]);
653 rep
.AddMemoryAccess(addr
, s
, &traces
[i
],
654 i
== 0 ? &thr
->mset
: mset2
.data());
657 for (uptr i
= 0; i
< kMop
; i
++) {
658 FastState
s(thr
->racy_state
[i
]);
659 ThreadContext
*tctx
= static_cast<ThreadContext
*>(
660 ctx
->thread_registry
->GetThreadLocked(s
.tid()));
661 if (s
.epoch() < tctx
->epoch0
|| s
.epoch() > tctx
->epoch1
)
666 rep
.AddLocation(addr_min
, addr_max
- addr_min
);
670 Shadow
s(thr
->racy_state
[1]);
671 if (s
.epoch() <= thr
->last_sleep_clock
.get(s
.tid()))
672 rep
.AddSleep(thr
->last_sleep_stack_id
);
676 if (!OutputReport(thr
, rep
))
679 AddRacyStacks(thr
, traces
, addr_min
, addr_max
);
682 void PrintCurrentStack(ThreadState
*thr
, uptr pc
) {
684 trace
.ObtainCurrent(thr
, pc
);
685 PrintStack(SymbolizeStack(trace
));
688 void PrintCurrentStackSlow() {
690 __sanitizer::StackTrace
*ptrace
= new(internal_alloc(MBlockStackTrace
,
691 sizeof(__sanitizer::StackTrace
))) __sanitizer::StackTrace
;
692 ptrace
->Unwind(kStackTraceMax
, __sanitizer::StackTrace::GetCurrentPc(), 0, 0,
694 for (uptr i
= 0; i
< ptrace
->size
/ 2; i
++) {
695 uptr tmp
= ptrace
->trace
[i
];
696 ptrace
->trace
[i
] = ptrace
->trace
[ptrace
->size
- i
- 1];
697 ptrace
->trace
[ptrace
->size
- i
- 1] = tmp
;
700 trace
.Init(ptrace
->trace
, ptrace
->size
);
701 PrintStack(SymbolizeStack(trace
));
705 } // namespace __tsan