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(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(StackTrace::GetCurrentPc());
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(SymbolizedStack
*frames
) {
58 SymbolizedStack
*last_frame
= nullptr;
59 SymbolizedStack
*last_frame2
= nullptr;
60 for (SymbolizedStack
*cur
= frames
; cur
; cur
= cur
->next
) {
61 last_frame2
= last_frame
;
68 const char *last
= last_frame
->info
.function
;
69 const char *last2
= last_frame2
->info
.function
;
70 // Strip frame above 'main'
71 if (last2
&& 0 == internal_strcmp(last2
, "main")) {
72 last_frame
->ClearAll();
73 last_frame2
->next
= nullptr;
74 // Strip our internal thread start routine.
75 } else if (last
&& 0 == internal_strcmp(last
, "__tsan_thread_start_func")) {
76 last_frame
->ClearAll();
77 last_frame2
->next
= nullptr;
78 // Strip global ctors init.
79 } else if (last
&& 0 == internal_strcmp(last
, "__do_global_ctors_aux")) {
80 last_frame
->ClearAll();
81 last_frame2
->next
= nullptr;
82 // If both are 0, then we probably just failed to symbolize.
83 } else if (last
|| last2
) {
84 // Ensure that we recovered stack completely. Trimmed stack
85 // can actually happen if we do not instrument some code,
86 // so it's only a debug print. However we must try hard to not miss it
88 DPrintf("Bottom stack frame is missed\n");
91 // The last frame always point into runtime (gosched0, goexit0, runtime.main).
92 last_frame
->ClearAll();
93 last_frame2
->next
= nullptr;
97 ReportStack
*SymbolizeStackId(u32 stack_id
) {
100 StackTrace stack
= StackDepotGet(stack_id
);
101 if (stack
.trace
== nullptr)
103 return SymbolizeStack(stack
);
106 static ReportStack
*SymbolizeStack(StackTrace trace
) {
109 SymbolizedStack
*top
= nullptr;
110 for (uptr si
= 0; si
< trace
.size
; si
++) {
111 const uptr pc
= trace
.trace
[si
];
113 // We obtain the return address, but we're interested in the previous
115 if ((pc
& kExternalPCBit
) == 0)
116 pc1
= StackTrace::GetPreviousInstructionPc(pc
);
117 SymbolizedStack
*ent
= SymbolizeCode(pc1
);
119 SymbolizedStack
*last
= ent
;
121 last
->info
.address
= pc
; // restore original pc for report
124 last
->info
.address
= pc
; // restore original pc for report
130 ReportStack
*stack
= ReportStack::New();
135 ScopedReport::ScopedReport(ReportType typ
) {
136 ctx
->thread_registry
->CheckLocked();
137 void *mem
= internal_alloc(MBlockReport
, sizeof(ReportDesc
));
138 rep_
= new(mem
) ReportDesc
;
140 ctx
->report_mtx
.Lock();
141 CommonSanitizerReportMutex
.Lock();
144 ScopedReport::~ScopedReport() {
145 CommonSanitizerReportMutex
.Unlock();
146 ctx
->report_mtx
.Unlock();
147 DestroyAndFree(rep_
);
150 void ScopedReport::AddStack(StackTrace stack
, bool suppressable
) {
151 ReportStack
**rs
= rep_
->stacks
.PushBack();
152 *rs
= SymbolizeStack(stack
);
153 (*rs
)->suppressable
= suppressable
;
156 void ScopedReport::AddMemoryAccess(uptr addr
, Shadow s
, StackTrace stack
,
157 const MutexSet
*mset
) {
158 void *mem
= internal_alloc(MBlockReportMop
, sizeof(ReportMop
));
159 ReportMop
*mop
= new(mem
) ReportMop
;
160 rep_
->mops
.PushBack(mop
);
162 mop
->addr
= addr
+ s
.addr0();
163 mop
->size
= s
.size();
164 mop
->write
= s
.IsWrite();
165 mop
->atomic
= s
.IsAtomic();
166 mop
->stack
= SymbolizeStack(stack
);
168 mop
->stack
->suppressable
= true;
169 for (uptr i
= 0; i
< mset
->Size(); i
++) {
170 MutexSet::Desc d
= mset
->Get(i
);
171 u64 mid
= this->AddMutex(d
.id
);
172 ReportMopMutex mtx
= {mid
, d
.write
};
173 mop
->mset
.PushBack(mtx
);
177 void ScopedReport::AddUniqueTid(int unique_tid
) {
178 rep_
->unique_tids
.PushBack(unique_tid
);
181 void ScopedReport::AddThread(const ThreadContext
*tctx
, bool suppressable
) {
182 for (uptr i
= 0; i
< rep_
->threads
.Size(); i
++) {
183 if ((u32
)rep_
->threads
[i
]->id
== tctx
->tid
)
186 void *mem
= internal_alloc(MBlockReportThread
, sizeof(ReportThread
));
187 ReportThread
*rt
= new(mem
) ReportThread();
188 rep_
->threads
.PushBack(rt
);
190 rt
->pid
= tctx
->os_id
;
191 rt
->running
= (tctx
->status
== ThreadStatusRunning
);
192 rt
->name
= internal_strdup(tctx
->name
);
193 rt
->parent_tid
= tctx
->parent_tid
;
195 rt
->stack
= SymbolizeStackId(tctx
->creation_stack_id
);
197 rt
->stack
->suppressable
= suppressable
;
201 static ThreadContext
*FindThreadByUidLocked(int unique_id
) {
202 ctx
->thread_registry
->CheckLocked();
203 for (unsigned i
= 0; i
< kMaxTid
; i
++) {
204 ThreadContext
*tctx
= static_cast<ThreadContext
*>(
205 ctx
->thread_registry
->GetThreadLocked(i
));
206 if (tctx
&& tctx
->unique_id
== (u32
)unique_id
) {
213 static ThreadContext
*FindThreadByTidLocked(int tid
) {
214 ctx
->thread_registry
->CheckLocked();
215 return static_cast<ThreadContext
*>(
216 ctx
->thread_registry
->GetThreadLocked(tid
));
219 static bool IsInStackOrTls(ThreadContextBase
*tctx_base
, void *arg
) {
220 uptr addr
= (uptr
)arg
;
221 ThreadContext
*tctx
= static_cast<ThreadContext
*>(tctx_base
);
222 if (tctx
->status
!= ThreadStatusRunning
)
224 ThreadState
*thr
= tctx
->thr
;
226 return ((addr
>= thr
->stk_addr
&& addr
< thr
->stk_addr
+ thr
->stk_size
) ||
227 (addr
>= thr
->tls_addr
&& addr
< thr
->tls_addr
+ thr
->tls_size
));
230 ThreadContext
*IsThreadStackOrTls(uptr addr
, bool *is_stack
) {
231 ctx
->thread_registry
->CheckLocked();
232 ThreadContext
*tctx
= static_cast<ThreadContext
*>(
233 ctx
->thread_registry
->FindThreadContextLocked(IsInStackOrTls
,
237 ThreadState
*thr
= tctx
->thr
;
239 *is_stack
= (addr
>= thr
->stk_addr
&& addr
< thr
->stk_addr
+ thr
->stk_size
);
244 void ScopedReport::AddThread(int unique_tid
, bool suppressable
) {
246 if (const ThreadContext
*tctx
= FindThreadByUidLocked(unique_tid
))
247 AddThread(tctx
, suppressable
);
251 void ScopedReport::AddMutex(const SyncVar
*s
) {
252 for (uptr i
= 0; i
< rep_
->mutexes
.Size(); i
++) {
253 if (rep_
->mutexes
[i
]->id
== s
->uid
)
256 void *mem
= internal_alloc(MBlockReportMutex
, sizeof(ReportMutex
));
257 ReportMutex
*rm
= new(mem
) ReportMutex();
258 rep_
->mutexes
.PushBack(rm
);
261 rm
->destroyed
= false;
262 rm
->stack
= SymbolizeStackId(s
->creation_stack_id
);
265 u64
ScopedReport::AddMutex(u64 id
) {
268 uptr addr
= SyncVar::SplitId(id
, &uid
);
269 SyncVar
*s
= ctx
->metamap
.GetIfExistsAndLock(addr
);
270 // Check that the mutex is still alive.
271 // Another mutex can be created at the same address,
272 // so check uid as well.
273 if (s
&& s
->CheckId(uid
)) {
284 void ScopedReport::AddDeadMutex(u64 id
) {
285 for (uptr i
= 0; i
< rep_
->mutexes
.Size(); i
++) {
286 if (rep_
->mutexes
[i
]->id
== id
)
289 void *mem
= internal_alloc(MBlockReportMutex
, sizeof(ReportMutex
));
290 ReportMutex
*rm
= new(mem
) ReportMutex();
291 rep_
->mutexes
.PushBack(rm
);
294 rm
->destroyed
= true;
298 void ScopedReport::AddLocation(uptr addr
, uptr size
) {
305 if (FdLocation(addr
, &fd
, &creat_tid
, &creat_stack
)) {
306 ReportLocation
*loc
= ReportLocation::New(ReportLocationFD
);
308 loc
->tid
= creat_tid
;
309 loc
->stack
= SymbolizeStackId(creat_stack
);
310 rep_
->locs
.PushBack(loc
);
311 ThreadContext
*tctx
= FindThreadByUidLocked(creat_tid
);
317 Allocator
*a
= allocator();
318 if (a
->PointerIsMine((void*)addr
)) {
319 void *block_begin
= a
->GetBlockBegin((void*)addr
);
321 b
= ctx
->metamap
.GetBlock((uptr
)block_begin
);
324 ThreadContext
*tctx
= FindThreadByTidLocked(b
->tid
);
325 ReportLocation
*loc
= ReportLocation::New(ReportLocationHeap
);
326 loc
->heap_chunk_start
= (uptr
)allocator()->GetBlockBegin((void *)addr
);
327 loc
->heap_chunk_size
= b
->siz
;
328 loc
->tid
= tctx
? tctx
->tid
: b
->tid
;
329 loc
->stack
= SymbolizeStackId(b
->stk
);
330 rep_
->locs
.PushBack(loc
);
335 bool is_stack
= false;
336 if (ThreadContext
*tctx
= IsThreadStackOrTls(addr
, &is_stack
)) {
337 ReportLocation
*loc
=
338 ReportLocation::New(is_stack
? ReportLocationStack
: ReportLocationTLS
);
339 loc
->tid
= tctx
->tid
;
340 rep_
->locs
.PushBack(loc
);
343 if (ReportLocation
*loc
= SymbolizeData(addr
)) {
344 loc
->suppressable
= true;
345 rep_
->locs
.PushBack(loc
);
352 void ScopedReport::AddSleep(u32 stack_id
) {
353 rep_
->sleep
= SymbolizeStackId(stack_id
);
357 void ScopedReport::SetCount(int count
) {
361 const ReportDesc
*ScopedReport::GetReport() const {
365 void RestoreStack(int tid
, const u64 epoch
, VarSizeStackTrace
*stk
,
367 // This function restores stack trace and mutex set for the thread/epoch.
368 // It does so by getting stack trace and mutex set at the beginning of
369 // trace part, and then replaying the trace till the given epoch.
370 Trace
* trace
= ThreadTrace(tid
);
371 ReadLock
l(&trace
->mtx
);
372 const int partidx
= (epoch
/ kTracePartSize
) % TraceParts();
373 TraceHeader
* hdr
= &trace
->headers
[partidx
];
374 if (epoch
< hdr
->epoch0
|| epoch
>= hdr
->epoch0
+ kTracePartSize
)
376 CHECK_EQ(RoundDown(epoch
, kTracePartSize
), hdr
->epoch0
);
377 const u64 epoch0
= RoundDown(epoch
, TraceSize());
378 const u64 eend
= epoch
% TraceSize();
379 const u64 ebegin
= RoundDown(eend
, kTracePartSize
);
380 DPrintf("#%d: RestoreStack epoch=%zu ebegin=%zu eend=%zu partidx=%d\n",
381 tid
, (uptr
)epoch
, (uptr
)ebegin
, (uptr
)eend
, partidx
);
382 Vector
<uptr
> stack(MBlockReportStack
);
383 stack
.Resize(hdr
->stack0
.size
+ 64);
384 for (uptr i
= 0; i
< hdr
->stack0
.size
; i
++) {
385 stack
[i
] = hdr
->stack0
.trace
[i
];
386 DPrintf2(" #%02zu: pc=%zx\n", i
, stack
[i
]);
390 uptr pos
= hdr
->stack0
.size
;
391 Event
*events
= (Event
*)GetThreadTrace(tid
);
392 for (uptr i
= ebegin
; i
<= eend
; i
++) {
393 Event ev
= events
[i
];
394 EventType typ
= (EventType
)(ev
>> 61);
395 uptr pc
= (uptr
)(ev
& ((1ull << 61) - 1));
396 DPrintf2(" %zu typ=%d pc=%zx\n", i
, typ
, pc
);
397 if (typ
== EventTypeMop
) {
399 } else if (typ
== EventTypeFuncEnter
) {
400 if (stack
.Size() < pos
+ 2)
401 stack
.Resize(pos
+ 2);
403 } else if (typ
== EventTypeFuncExit
) {
408 if (typ
== EventTypeLock
) {
409 mset
->Add(pc
, true, epoch0
+ i
);
410 } else if (typ
== EventTypeUnlock
) {
412 } else if (typ
== EventTypeRLock
) {
413 mset
->Add(pc
, false, epoch0
+ i
);
414 } else if (typ
== EventTypeRUnlock
) {
415 mset
->Del(pc
, false);
418 for (uptr j
= 0; j
<= pos
; j
++)
419 DPrintf2(" #%zu: %zx\n", j
, stack
[j
]);
421 if (pos
== 0 && stack
[0] == 0)
424 stk
->Init(&stack
[0], pos
);
427 static bool HandleRacyStacks(ThreadState
*thr
, VarSizeStackTrace traces
[2],
428 uptr addr_min
, uptr addr_max
) {
429 bool equal_stack
= false;
431 bool equal_address
= false;
432 RacyAddress ra0
= {addr_min
, addr_max
};
434 ReadLock
lock(&ctx
->racy_mtx
);
435 if (flags()->suppress_equal_stacks
) {
436 hash
.hash
[0] = md5_hash(traces
[0].trace
, traces
[0].size
* sizeof(uptr
));
437 hash
.hash
[1] = md5_hash(traces
[1].trace
, traces
[1].size
* sizeof(uptr
));
438 for (uptr i
= 0; i
< ctx
->racy_stacks
.Size(); i
++) {
439 if (hash
== ctx
->racy_stacks
[i
]) {
441 "ThreadSanitizer: suppressing report as doubled (stack)\n");
447 if (flags()->suppress_equal_addresses
) {
448 for (uptr i
= 0; i
< ctx
->racy_addresses
.Size(); i
++) {
449 RacyAddress ra2
= ctx
->racy_addresses
[i
];
450 uptr maxbeg
= max(ra0
.addr_min
, ra2
.addr_min
);
451 uptr minend
= min(ra0
.addr_max
, ra2
.addr_max
);
452 if (maxbeg
< minend
) {
453 VPrintf(2, "ThreadSanitizer: suppressing report as doubled (addr)\n");
454 equal_address
= true;
460 if (!equal_stack
&& !equal_address
)
463 Lock
lock(&ctx
->racy_mtx
);
464 ctx
->racy_stacks
.PushBack(hash
);
466 if (!equal_address
) {
467 Lock
lock(&ctx
->racy_mtx
);
468 ctx
->racy_addresses
.PushBack(ra0
);
473 static void AddRacyStacks(ThreadState
*thr
, VarSizeStackTrace traces
[2],
474 uptr addr_min
, uptr addr_max
) {
475 Lock
lock(&ctx
->racy_mtx
);
476 if (flags()->suppress_equal_stacks
) {
478 hash
.hash
[0] = md5_hash(traces
[0].trace
, traces
[0].size
* sizeof(uptr
));
479 hash
.hash
[1] = md5_hash(traces
[1].trace
, traces
[1].size
* sizeof(uptr
));
480 ctx
->racy_stacks
.PushBack(hash
);
482 if (flags()->suppress_equal_addresses
) {
483 RacyAddress ra0
= {addr_min
, addr_max
};
484 ctx
->racy_addresses
.PushBack(ra0
);
488 bool OutputReport(ThreadState
*thr
, const ScopedReport
&srep
) {
489 if (!flags()->report_bugs
)
491 atomic_store_relaxed(&ctx
->last_symbolize_time_ns
, NanoTime());
492 const ReportDesc
*rep
= srep
.GetReport();
493 Suppression
*supp
= 0;
495 for (uptr i
= 0; pc_or_addr
== 0 && i
< rep
->mops
.Size(); i
++)
496 pc_or_addr
= IsSuppressed(rep
->typ
, rep
->mops
[i
]->stack
, &supp
);
497 for (uptr i
= 0; pc_or_addr
== 0 && i
< rep
->stacks
.Size(); i
++)
498 pc_or_addr
= IsSuppressed(rep
->typ
, rep
->stacks
[i
], &supp
);
499 for (uptr i
= 0; pc_or_addr
== 0 && i
< rep
->threads
.Size(); i
++)
500 pc_or_addr
= IsSuppressed(rep
->typ
, rep
->threads
[i
]->stack
, &supp
);
501 for (uptr i
= 0; pc_or_addr
== 0 && i
< rep
->locs
.Size(); i
++)
502 pc_or_addr
= IsSuppressed(rep
->typ
, rep
->locs
[i
], &supp
);
503 if (pc_or_addr
!= 0) {
504 Lock
lock(&ctx
->fired_suppressions_mtx
);
505 FiredSuppression s
= {srep
.GetReport()->typ
, pc_or_addr
, supp
};
506 ctx
->fired_suppressions
.push_back(s
);
509 bool old_is_freeing
= thr
->is_freeing
;
510 thr
->is_freeing
= false;
511 bool suppressed
= OnReport(rep
, pc_or_addr
!= 0);
512 thr
->is_freeing
= old_is_freeing
;
518 if (flags()->halt_on_error
)
523 bool IsFiredSuppression(Context
*ctx
, ReportType type
, StackTrace trace
) {
524 ReadLock
lock(&ctx
->fired_suppressions_mtx
);
525 for (uptr k
= 0; k
< ctx
->fired_suppressions
.size(); k
++) {
526 if (ctx
->fired_suppressions
[k
].type
!= type
)
528 for (uptr j
= 0; j
< trace
.size
; j
++) {
529 FiredSuppression
*s
= &ctx
->fired_suppressions
[k
];
530 if (trace
.trace
[j
] == s
->pc_or_addr
) {
532 atomic_fetch_add(&s
->supp
->hit_count
, 1, memory_order_relaxed
);
540 static bool IsFiredSuppression(Context
*ctx
, ReportType type
, uptr addr
) {
541 ReadLock
lock(&ctx
->fired_suppressions_mtx
);
542 for (uptr k
= 0; k
< ctx
->fired_suppressions
.size(); k
++) {
543 if (ctx
->fired_suppressions
[k
].type
!= type
)
545 FiredSuppression
*s
= &ctx
->fired_suppressions
[k
];
546 if (addr
== s
->pc_or_addr
) {
548 atomic_fetch_add(&s
->supp
->hit_count
, 1, memory_order_relaxed
);
555 static bool RaceBetweenAtomicAndFree(ThreadState
*thr
) {
556 Shadow
s0(thr
->racy_state
[0]);
557 Shadow
s1(thr
->racy_state
[1]);
558 CHECK(!(s0
.IsAtomic() && s1
.IsAtomic()));
559 if (!s0
.IsAtomic() && !s1
.IsAtomic())
561 if (s0
.IsAtomic() && s1
.IsFreed())
563 if (s1
.IsAtomic() && thr
->is_freeing
)
568 void ReportRace(ThreadState
*thr
) {
571 // Symbolizer makes lots of intercepted calls. If we try to process them,
572 // at best it will cause deadlocks on internal mutexes.
573 ScopedIgnoreInterceptors ignore
;
575 if (!flags()->report_bugs
)
577 if (!flags()->report_atomic_races
&& !RaceBetweenAtomicAndFree(thr
))
582 Shadow
s(thr
->racy_state
[1]);
583 freed
= s
.GetFreedAndReset();
584 thr
->racy_state
[1] = s
.raw();
587 uptr addr
= ShadowToMem((uptr
)thr
->racy_shadow_addr
);
591 uptr a0
= addr
+ Shadow(thr
->racy_state
[0]).addr0();
592 uptr a1
= addr
+ Shadow(thr
->racy_state
[1]).addr0();
593 uptr e0
= a0
+ Shadow(thr
->racy_state
[0]).size();
594 uptr e1
= a1
+ Shadow(thr
->racy_state
[1]).size();
595 addr_min
= min(a0
, a1
);
596 addr_max
= max(e0
, e1
);
597 if (IsExpectedReport(addr_min
, addr_max
- addr_min
))
601 ReportType typ
= ReportTypeRace
;
602 if (thr
->is_vptr_access
&& freed
)
603 typ
= ReportTypeVptrUseAfterFree
;
604 else if (thr
->is_vptr_access
)
605 typ
= ReportTypeVptrRace
;
607 typ
= ReportTypeUseAfterFree
;
609 if (IsFiredSuppression(ctx
, typ
, addr
))
613 VarSizeStackTrace traces
[kMop
];
614 const uptr toppc
= TraceTopPC(thr
);
615 ObtainCurrentStack(thr
, toppc
, &traces
[0]);
616 if (IsFiredSuppression(ctx
, typ
, traces
[0]))
619 // MutexSet is too large to live on stack.
620 Vector
<u64
> mset_buffer(MBlockScopedBuf
);
621 mset_buffer
.Resize(sizeof(MutexSet
) / sizeof(u64
) + 1);
622 MutexSet
*mset2
= new(&mset_buffer
[0]) MutexSet();
624 Shadow
s2(thr
->racy_state
[1]);
625 RestoreStack(s2
.tid(), s2
.epoch(), &traces
[1], mset2
);
626 if (IsFiredSuppression(ctx
, typ
, traces
[1]))
629 if (HandleRacyStacks(thr
, traces
, addr_min
, addr_max
))
632 ThreadRegistryLock
l0(ctx
->thread_registry
);
633 ScopedReport
rep(typ
);
634 for (uptr i
= 0; i
< kMop
; i
++) {
635 Shadow
s(thr
->racy_state
[i
]);
636 rep
.AddMemoryAccess(addr
, s
, traces
[i
], i
== 0 ? &thr
->mset
: mset2
);
639 for (uptr i
= 0; i
< kMop
; i
++) {
640 FastState
s(thr
->racy_state
[i
]);
641 ThreadContext
*tctx
= static_cast<ThreadContext
*>(
642 ctx
->thread_registry
->GetThreadLocked(s
.tid()));
643 if (s
.epoch() < tctx
->epoch0
|| s
.epoch() > tctx
->epoch1
)
648 rep
.AddLocation(addr_min
, addr_max
- addr_min
);
652 Shadow
s(thr
->racy_state
[1]);
653 if (s
.epoch() <= thr
->last_sleep_clock
.get(s
.tid()))
654 rep
.AddSleep(thr
->last_sleep_stack_id
);
658 if (!OutputReport(thr
, rep
))
661 AddRacyStacks(thr
, traces
, addr_min
, addr_max
);
664 void PrintCurrentStack(ThreadState
*thr
, uptr pc
) {
665 VarSizeStackTrace trace
;
666 ObtainCurrentStack(thr
, pc
, &trace
);
667 PrintStack(SymbolizeStack(trace
));
670 void PrintCurrentStackSlow(uptr pc
) {
672 BufferedStackTrace
*ptrace
=
673 new(internal_alloc(MBlockStackTrace
, sizeof(BufferedStackTrace
)))
674 BufferedStackTrace();
675 ptrace
->Unwind(kStackTraceMax
, pc
, 0, 0, 0, 0, false);
676 for (uptr i
= 0; i
< ptrace
->size
/ 2; i
++) {
677 uptr tmp
= ptrace
->trace_buffer
[i
];
678 ptrace
->trace_buffer
[i
] = ptrace
->trace_buffer
[ptrace
->size
- i
- 1];
679 ptrace
->trace_buffer
[ptrace
->size
- i
- 1] = tmp
;
681 PrintStack(SymbolizeStack(*ptrace
));
685 } // namespace __tsan
687 using namespace __tsan
;
690 SANITIZER_INTERFACE_ATTRIBUTE
691 void __sanitizer_print_stack_trace() {
692 PrintCurrentStackSlow(StackTrace::GetCurrentPc());