]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/tsan/rtl/tsan_symbolize.cc
MFV r284234:
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / tsan / rtl / tsan_symbolize.cc
1 //===-- tsan_symbolize.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 "tsan_symbolize.h"
15
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"
21 #include "tsan_rtl.h"
22
23 namespace __tsan {
24
25 void EnterSymbolizer() {
26   ThreadState *thr = cur_thread();
27   CHECK(!thr->in_symbolizer);
28   thr->in_symbolizer = true;
29   thr->ignore_interceptors++;
30 }
31
32 void ExitSymbolizer() {
33   ThreadState *thr = cur_thread();
34   CHECK(thr->in_symbolizer);
35   thr->in_symbolizer = false;
36   thr->ignore_interceptors--;
37 }
38
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,
44                                int *line, int *col)
45                                SANITIZER_WEAK_ATTRIBUTE;
46
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) {
51   return false;
52 }
53
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];
61     int line, col;
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;
69     }
70     return frame;
71   }
72   return Symbolizer::GetOrInit()->SymbolizePC(addr);
73 }
74
75 ReportLocation *SymbolizeData(uptr addr) {
76   DataInfo info;
77   if (!Symbolizer::GetOrInit()->SymbolizeData(addr, &info))
78     return 0;
79   ReportLocation *ent = ReportLocation::New(ReportLocationGlobal);
80   ent->global = info;
81   return ent;
82 }
83
84 void SymbolizeFlush() {
85   Symbolizer::GetOrInit()->Flush();
86 }
87
88 }  // namespace __tsan