2012-11-22 23:03:11 +01:00
|
|
|
//===-- tsan_symbolize.cc -------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of ThreadSanitizer (TSan), a race detector.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "tsan_symbolize.h"
|
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
|
|
|
#include "sanitizer_common/sanitizer_placement_new.h"
|
|
|
|
#include "sanitizer_common/sanitizer_symbolizer.h"
|
|
|
|
#include "tsan_flags.h"
|
|
|
|
#include "tsan_report.h"
|
2013-02-13 11:46:01 +01:00
|
|
|
#include "tsan_rtl.h"
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
namespace __tsan {
|
|
|
|
|
2013-12-05 10:18:38 +01:00
|
|
|
void EnterSymbolizer() {
|
|
|
|
ThreadState *thr = cur_thread();
|
|
|
|
CHECK(!thr->in_symbolizer);
|
|
|
|
thr->in_symbolizer = true;
|
2014-05-22 09:09:21 +02:00
|
|
|
thr->ignore_interceptors++;
|
2013-12-05 10:18:38 +01:00
|
|
|
}
|
2013-02-13 11:46:01 +01:00
|
|
|
|
2013-12-05 10:18:38 +01:00
|
|
|
void ExitSymbolizer() {
|
|
|
|
ThreadState *thr = cur_thread();
|
|
|
|
CHECK(thr->in_symbolizer);
|
|
|
|
thr->in_symbolizer = false;
|
2014-05-22 09:09:21 +02:00
|
|
|
thr->ignore_interceptors--;
|
2013-12-05 10:18:38 +01:00
|
|
|
}
|
2013-02-13 11:46:01 +01:00
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
// May be overriden by JIT/JAVA/etc,
|
|
|
|
// whatever produces PCs marked with kExternalPCBit.
|
2016-11-08 23:04:09 +01:00
|
|
|
SANITIZER_WEAK_DEFAULT_IMPL
|
|
|
|
bool __tsan_symbolize_external(uptr pc, char *func_buf, uptr func_siz,
|
|
|
|
char *file_buf, uptr file_siz, int *line,
|
|
|
|
int *col) {
|
2013-11-04 22:33:31 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
SymbolizedStack *SymbolizeCode(uptr addr) {
|
2013-11-04 22:33:31 +01:00
|
|
|
// Check if PC comes from non-native land.
|
|
|
|
if (addr & kExternalPCBit) {
|
|
|
|
// Declare static to not consume too much stack space.
|
|
|
|
// We symbolize reports in a single thread, so this is fine.
|
|
|
|
static char func_buf[1024];
|
|
|
|
static char file_buf[1024];
|
|
|
|
int line, col;
|
2015-10-21 09:32:45 +02:00
|
|
|
SymbolizedStack *frame = SymbolizedStack::New(addr);
|
|
|
|
if (__tsan_symbolize_external(addr, func_buf, sizeof(func_buf), file_buf,
|
|
|
|
sizeof(file_buf), &line, &col)) {
|
|
|
|
frame->info.function = internal_strdup(func_buf);
|
|
|
|
frame->info.file = internal_strdup(file_buf);
|
|
|
|
frame->info.line = line;
|
|
|
|
frame->info.column = col;
|
|
|
|
}
|
|
|
|
return frame;
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
return Symbolizer::GetOrInit()->SymbolizePC(addr);
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
|
2013-01-23 12:41:33 +01:00
|
|
|
ReportLocation *SymbolizeData(uptr addr) {
|
|
|
|
DataInfo info;
|
2014-09-23 19:59:53 +02:00
|
|
|
if (!Symbolizer::GetOrInit()->SymbolizeData(addr, &info))
|
2013-01-23 12:41:33 +01:00
|
|
|
return 0;
|
2014-11-13 21:41:38 +01:00
|
|
|
ReportLocation *ent = ReportLocation::New(ReportLocationGlobal);
|
2016-11-08 23:04:09 +01:00
|
|
|
internal_memcpy(&ent->global, &info, sizeof(info));
|
2013-01-23 12:41:33 +01:00
|
|
|
return ent;
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
void SymbolizeFlush() {
|
2014-09-23 19:59:53 +02:00
|
|
|
Symbolizer::GetOrInit()->Flush();
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
} // namespace __tsan
|