1 //===-- tsan_symbolize.cc -------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of ThreadSanitizer (TSan), a race detector.
12 //===----------------------------------------------------------------------===//
14 #include "tsan_symbolize.h"
16 #include "sanitizer_common/sanitizer_common.h"
17 #include "sanitizer_common/sanitizer_placement_new.h"
18 #include "sanitizer_common/sanitizer_symbolizer.h"
19 #include "tsan_flags.h"
20 #include "tsan_report.h"
25 void EnterSymbolizer() {
26 ThreadState *thr = cur_thread();
27 CHECK(!thr->in_symbolizer);
28 thr->in_symbolizer = true;
29 thr->ignore_interceptors++;
32 void ExitSymbolizer() {
33 ThreadState *thr = cur_thread();
34 CHECK(thr->in_symbolizer);
35 thr->in_symbolizer = false;
36 thr->ignore_interceptors--;
39 // May be overriden by JIT/JAVA/etc,
40 // whatever produces PCs marked with kExternalPCBit.
41 extern "C" bool __tsan_symbolize_external(uptr pc,
42 char *func_buf, uptr func_siz,
43 char *file_buf, uptr file_siz,
45 SANITIZER_WEAK_ATTRIBUTE;
47 bool __tsan_symbolize_external(uptr pc,
48 char *func_buf, uptr func_siz,
49 char *file_buf, uptr file_siz,
50 int *line, int *col) {
54 SymbolizedStack *SymbolizeCode(uptr addr) {
55 // Check if PC comes from non-native land.
56 if (addr & kExternalPCBit) {
57 // Declare static to not consume too much stack space.
58 // We symbolize reports in a single thread, so this is fine.
59 static char func_buf[1024];
60 static char file_buf[1024];
62 SymbolizedStack *frame = SymbolizedStack::New(addr);
63 if (__tsan_symbolize_external(addr, func_buf, sizeof(func_buf), file_buf,
64 sizeof(file_buf), &line, &col)) {
65 frame->info.function = internal_strdup(func_buf);
66 frame->info.file = internal_strdup(file_buf);
67 frame->info.line = line;
68 frame->info.column = col;
72 return Symbolizer::GetOrInit()->SymbolizePC(addr);
75 ReportLocation *SymbolizeData(uptr addr) {
77 if (!Symbolizer::GetOrInit()->SymbolizeData(addr, &info))
79 ReportLocation *ent = ReportLocation::New(ReportLocationGlobal);
84 void SymbolizeFlush() {
85 Symbolizer::GetOrInit()->Flush();