blob: b2423951795f2e92c2bba35d24ce5b9a9a2b8ed1 [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.
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080041SANITIZER_WEAK_DEFAULT_IMPL
42bool __tsan_symbolize_external(uptr pc, char *func_buf, uptr func_siz,
43 char *file_buf, uptr file_siz, int *line,
44 int *col) {
Dmitry Vyukov2d2dc462013-09-22 00:14:57 +000045 return false;
46}
47
Stephen Hines86277eb2015-03-23 12:06:32 -070048SymbolizedStack *SymbolizeCode(uptr addr) {
Dmitry Vyukov2d2dc462013-09-22 00:14:57 +000049 // Check if PC comes from non-native land.
50 if (addr & kExternalPCBit) {
51 // Declare static to not consume too much stack space.
52 // We symbolize reports in a single thread, so this is fine.
53 static char func_buf[1024];
54 static char file_buf[1024];
55 int line, col;
Stephen Hines86277eb2015-03-23 12:06:32 -070056 SymbolizedStack *frame = SymbolizedStack::New(addr);
57 if (__tsan_symbolize_external(addr, func_buf, sizeof(func_buf), file_buf,
58 sizeof(file_buf), &line, &col)) {
59 frame->info.function = internal_strdup(func_buf);
60 frame->info.file = internal_strdup(file_buf);
61 frame->info.line = line;
62 frame->info.column = col;
63 }
64 return frame;
Dmitry Vyukov2d2dc462013-09-22 00:14:57 +000065 }
Stephen Hines86277eb2015-03-23 12:06:32 -070066 return Symbolizer::GetOrInit()->SymbolizePC(addr);
Alexey Samsonovbc12f5d2012-07-05 07:18:29 +000067}
68
Dmitry Vyukov5a1f2332013-01-11 07:23:51 +000069ReportLocation *SymbolizeData(uptr addr) {
Dmitry Vyukov5a1f2332013-01-11 07:23:51 +000070 DataInfo info;
Stephen Hines6d186232014-11-26 17:56:19 -080071 if (!Symbolizer::GetOrInit()->SymbolizeData(addr, &info))
Dmitry Vyukov5a1f2332013-01-11 07:23:51 +000072 return 0;
Stephen Hines6d186232014-11-26 17:56:19 -080073 ReportLocation *ent = ReportLocation::New(ReportLocationGlobal);
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080074 internal_memcpy(&ent->global, &info, sizeof(info));
Dmitry Vyukov5a1f2332013-01-11 07:23:51 +000075 return ent;
Alexey Samsonovbc12f5d2012-07-05 07:18:29 +000076}
77
Dmitry Vyukov723e24f2013-03-19 10:24:01 +000078void SymbolizeFlush() {
Stephen Hines6d186232014-11-26 17:56:19 -080079 Symbolizer::GetOrInit()->Flush();
Dmitry Vyukov723e24f2013-03-19 10:24:01 +000080}
81
Alexey Samsonovbc12f5d2012-07-05 07:18:29 +000082} // namespace __tsan