blob: 3beb44f7ad3b8a7fe7f9e116b8fa57d32c7bdd4b [file] [log] [blame]
Alexey Samsonovbc12f5d2012-07-05 07:18:29 +00001//===-- 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"
Dmitry Vyukov4e81d0e2013-01-29 13:03:07 +000021#include "tsan_rtl.h"
Alexey Samsonovbc12f5d2012-07-05 07:18:29 +000022
23namespace __tsan {
24
Alexey Samsonov66d91e32013-10-31 21:44:07 +000025void EnterSymbolizer() {
26 ThreadState *thr = cur_thread();
27 CHECK(!thr->in_symbolizer);
28 thr->in_symbolizer = true;
Stephen Hines2d1fdb22014-05-28 23:58:16 -070029 thr->ignore_interceptors++;
Alexey Samsonov66d91e32013-10-31 21:44:07 +000030}
Dmitry Vyukov4e81d0e2013-01-29 13:03:07 +000031
Alexey Samsonov66d91e32013-10-31 21:44:07 +000032void ExitSymbolizer() {
33 ThreadState *thr = cur_thread();
34 CHECK(thr->in_symbolizer);
35 thr->in_symbolizer = false;
Stephen Hines2d1fdb22014-05-28 23:58:16 -070036 thr->ignore_interceptors--;
Alexey Samsonov66d91e32013-10-31 21:44:07 +000037}
Dmitry Vyukov4e81d0e2013-01-29 13:03:07 +000038
Dmitry Vyukov2d2dc462013-09-22 00:14:57 +000039// May be overriden by JIT/JAVA/etc,
40// whatever produces PCs marked with kExternalPCBit.
41extern "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
47bool __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
Stephen Hines86277eb2015-03-23 12:06:32 -070054SymbolizedStack *SymbolizeCode(uptr addr) {
Dmitry Vyukov2d2dc462013-09-22 00:14:57 +000055 // 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;
Stephen Hines86277eb2015-03-23 12:06:32 -070062 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;
Dmitry Vyukov2d2dc462013-09-22 00:14:57 +000071 }
Stephen Hines86277eb2015-03-23 12:06:32 -070072 return Symbolizer::GetOrInit()->SymbolizePC(addr);
Alexey Samsonovbc12f5d2012-07-05 07:18:29 +000073}
74
Dmitry Vyukov5a1f2332013-01-11 07:23:51 +000075ReportLocation *SymbolizeData(uptr addr) {
Dmitry Vyukov5a1f2332013-01-11 07:23:51 +000076 DataInfo info;
Stephen Hines6d186232014-11-26 17:56:19 -080077 if (!Symbolizer::GetOrInit()->SymbolizeData(addr, &info))
Dmitry Vyukov5a1f2332013-01-11 07:23:51 +000078 return 0;
Stephen Hines6d186232014-11-26 17:56:19 -080079 ReportLocation *ent = ReportLocation::New(ReportLocationGlobal);
80 ent->global = info;
Dmitry Vyukov5a1f2332013-01-11 07:23:51 +000081 return ent;
Alexey Samsonovbc12f5d2012-07-05 07:18:29 +000082}
83
Dmitry Vyukov723e24f2013-03-19 10:24:01 +000084void SymbolizeFlush() {
Stephen Hines6d186232014-11-26 17:56:19 -080085 Symbolizer::GetOrInit()->Flush();
Dmitry Vyukov723e24f2013-03-19 10:24:01 +000086}
87
Alexey Samsonovbc12f5d2012-07-05 07:18:29 +000088} // namespace __tsan