forked from OSchip/llvm-project
[TSan] switch tsan to using InternalScopedBuffer from sanitizer_common
llvm-svn: 162351
This commit is contained in:
parent
6269888166
commit
75e5fc3e57
|
|
@ -65,6 +65,7 @@ class InternalScopedBuffer {
|
||||||
~InternalScopedBuffer() {
|
~InternalScopedBuffer() {
|
||||||
InternalFree(ptr_);
|
InternalFree(ptr_);
|
||||||
}
|
}
|
||||||
|
operator T*() { return ptr_; }
|
||||||
T &operator[](uptr i) { return ptr_[i]; }
|
T &operator[](uptr i) { return ptr_[i]; }
|
||||||
T *data() { return ptr_; }
|
T *data() { return ptr_; }
|
||||||
uptr size() { return cnt_ * sizeof(T); }
|
uptr size() { return cnt_ * sizeof(T); }
|
||||||
|
|
|
||||||
|
|
@ -71,45 +71,5 @@ void DestroyAndFree(T *&p) {
|
||||||
p = 0;
|
p = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class InternalScopedBuf {
|
|
||||||
public:
|
|
||||||
explicit InternalScopedBuf(uptr cnt) {
|
|
||||||
cnt_ = cnt;
|
|
||||||
ptr_ = (T*)internal_alloc(MBlockScopedBuf, cnt * sizeof(T));
|
|
||||||
}
|
|
||||||
|
|
||||||
~InternalScopedBuf() {
|
|
||||||
internal_free(ptr_);
|
|
||||||
}
|
|
||||||
|
|
||||||
operator T *() {
|
|
||||||
return ptr_;
|
|
||||||
}
|
|
||||||
|
|
||||||
T &operator[](uptr i) {
|
|
||||||
return ptr_[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
T *Ptr() {
|
|
||||||
return ptr_;
|
|
||||||
}
|
|
||||||
|
|
||||||
uptr Count() {
|
|
||||||
return cnt_;
|
|
||||||
}
|
|
||||||
|
|
||||||
uptr Size() {
|
|
||||||
return cnt_ * sizeof(T);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
T *ptr_;
|
|
||||||
uptr cnt_;
|
|
||||||
|
|
||||||
InternalScopedBuf(const InternalScopedBuf&);
|
|
||||||
void operator = (const InternalScopedBuf&);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace __tsan
|
} // namespace __tsan
|
||||||
#endif // TSAN_MMAN_H
|
#endif // TSAN_MMAN_H
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "sanitizer_common/sanitizer_common.h"
|
||||||
#include "sanitizer_common/sanitizer_libc.h"
|
#include "sanitizer_common/sanitizer_libc.h"
|
||||||
#include "tsan_defs.h"
|
#include "tsan_defs.h"
|
||||||
#include "tsan_mman.h"
|
#include "tsan_mman.h"
|
||||||
|
|
@ -27,13 +28,13 @@ namespace __tsan {
|
||||||
void TsanPrintf(const char *format, ...) {
|
void TsanPrintf(const char *format, ...) {
|
||||||
ScopedInRtl in_rtl;
|
ScopedInRtl in_rtl;
|
||||||
const uptr kMaxLen = 16 * 1024;
|
const uptr kMaxLen = 16 * 1024;
|
||||||
InternalScopedBuf<char> buffer(kMaxLen);
|
InternalScopedBuffer<char> buffer(kMaxLen);
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
uptr len = VSNPrintf(buffer, buffer.Size(), format, args);
|
uptr len = VSNPrintf(buffer, buffer.size(), format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
internal_write(CTX() ? flags()->log_fileno : 2,
|
internal_write(CTX() ? flags()->log_fileno : 2,
|
||||||
buffer, len < buffer.Size() ? len : buffer.Size() - 1);
|
buffer, len < buffer.size() ? len : buffer.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace __tsan
|
} // namespace __tsan
|
||||||
|
|
|
||||||
|
|
@ -120,9 +120,9 @@ static void MemoryProfileThread(void *arg) {
|
||||||
ScopedInRtl in_rtl;
|
ScopedInRtl in_rtl;
|
||||||
fd_t fd = (fd_t)(uptr)arg;
|
fd_t fd = (fd_t)(uptr)arg;
|
||||||
for (int i = 0; ; i++) {
|
for (int i = 0; ; i++) {
|
||||||
InternalScopedBuf<char> buf(4096);
|
InternalScopedBuffer<char> buf(4096);
|
||||||
WriteMemoryProfile(buf.Ptr(), buf.Size(), i);
|
WriteMemoryProfile(buf, buf.size(), i);
|
||||||
internal_write(fd, buf.Ptr(), internal_strlen(buf.Ptr()));
|
internal_write(fd, buf, internal_strlen(buf));
|
||||||
SleepForSeconds(1);
|
SleepForSeconds(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -130,10 +130,10 @@ static void MemoryProfileThread(void *arg) {
|
||||||
static void InitializeMemoryProfile() {
|
static void InitializeMemoryProfile() {
|
||||||
if (flags()->profile_memory == 0 || flags()->profile_memory[0] == 0)
|
if (flags()->profile_memory == 0 || flags()->profile_memory[0] == 0)
|
||||||
return;
|
return;
|
||||||
InternalScopedBuf<char> filename(4096);
|
InternalScopedBuffer<char> filename(4096);
|
||||||
internal_snprintf(filename.Ptr(), filename.Size(), "%s.%d",
|
internal_snprintf(filename, filename.size(), "%s.%d",
|
||||||
flags()->profile_memory, GetPid());
|
flags()->profile_memory, GetPid());
|
||||||
fd_t fd = internal_open(filename.Ptr(), true);
|
fd_t fd = internal_open(filename, true);
|
||||||
if (fd == kInvalidFd) {
|
if (fd == kInvalidFd) {
|
||||||
TsanPrintf("Failed to open memory profile file '%s'\n", &filename[0]);
|
TsanPrintf("Failed to open memory profile file '%s'\n", &filename[0]);
|
||||||
Die();
|
Die();
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,7 @@ void RestoreStack(int tid, const u64 epoch, StackTrace *stk) {
|
||||||
const u64 ebegin = eend / kTracePartSize * kTracePartSize;
|
const u64 ebegin = eend / kTracePartSize * kTracePartSize;
|
||||||
DPrintf("#%d: RestoreStack epoch=%zu ebegin=%zu eend=%zu partidx=%d\n",
|
DPrintf("#%d: RestoreStack epoch=%zu ebegin=%zu eend=%zu partidx=%d\n",
|
||||||
tid, (uptr)epoch, (uptr)ebegin, (uptr)eend, partidx);
|
tid, (uptr)epoch, (uptr)ebegin, (uptr)eend, partidx);
|
||||||
InternalScopedBuf<uptr> stack(1024); // FIXME: de-hardcode 1024
|
InternalScopedBuffer<uptr> stack(1024); // FIXME: de-hardcode 1024
|
||||||
for (uptr i = 0; i < hdr->stack0.Size(); i++) {
|
for (uptr i = 0; i < hdr->stack0.Size(); i++) {
|
||||||
stack[i] = hdr->stack0.Get(i);
|
stack[i] = hdr->stack0.Get(i);
|
||||||
DPrintf2(" #%02lu: pc=%zx\n", i, stack[i]);
|
DPrintf2(" #%02lu: pc=%zx\n", i, stack[i]);
|
||||||
|
|
|
||||||
|
|
@ -26,27 +26,27 @@ static Suppression *g_suppressions;
|
||||||
static char *ReadFile(const char *filename) {
|
static char *ReadFile(const char *filename) {
|
||||||
if (filename == 0 || filename[0] == 0)
|
if (filename == 0 || filename[0] == 0)
|
||||||
return 0;
|
return 0;
|
||||||
InternalScopedBuf<char> tmp(4*1024);
|
InternalScopedBuffer<char> tmp(4*1024);
|
||||||
if (filename[0] == '/')
|
if (filename[0] == '/')
|
||||||
internal_snprintf(tmp, tmp.Size(), "%s", filename);
|
internal_snprintf(tmp, tmp.size(), "%s", filename);
|
||||||
else
|
else
|
||||||
internal_snprintf(tmp, tmp.Size(), "%s/%s", GetPwd(), filename);
|
internal_snprintf(tmp, tmp.size(), "%s/%s", GetPwd(), filename);
|
||||||
fd_t fd = internal_open(tmp, false);
|
fd_t fd = internal_open(tmp, false);
|
||||||
if (fd == kInvalidFd) {
|
if (fd == kInvalidFd) {
|
||||||
TsanPrintf("ThreadSanitizer: failed to open suppressions file '%s'\n",
|
TsanPrintf("ThreadSanitizer: failed to open suppressions file '%s'\n",
|
||||||
tmp.Ptr());
|
tmp.data());
|
||||||
Die();
|
Die();
|
||||||
}
|
}
|
||||||
const uptr fsize = internal_filesize(fd);
|
const uptr fsize = internal_filesize(fd);
|
||||||
if (fsize == (uptr)-1) {
|
if (fsize == (uptr)-1) {
|
||||||
TsanPrintf("ThreadSanitizer: failed to stat suppressions file '%s'\n",
|
TsanPrintf("ThreadSanitizer: failed to stat suppressions file '%s'\n",
|
||||||
tmp.Ptr());
|
tmp.data());
|
||||||
Die();
|
Die();
|
||||||
}
|
}
|
||||||
char *buf = (char*)internal_alloc(MBlockSuppression, fsize + 1);
|
char *buf = (char*)internal_alloc(MBlockSuppression, fsize + 1);
|
||||||
if (fsize != internal_read(fd, buf, fsize)) {
|
if (fsize != internal_read(fd, buf, fsize)) {
|
||||||
TsanPrintf("ThreadSanitizer: failed to read suppressions file '%s'\n",
|
TsanPrintf("ThreadSanitizer: failed to read suppressions file '%s'\n",
|
||||||
tmp.Ptr());
|
tmp.data());
|
||||||
Die();
|
Die();
|
||||||
}
|
}
|
||||||
internal_close(fd);
|
internal_close(fd);
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ static ReportStack *NewReportStackEntry(const AddressInfo &info) {
|
||||||
ReportStack *SymbolizeCode(uptr addr) {
|
ReportStack *SymbolizeCode(uptr addr) {
|
||||||
if (flags()->use_internal_symbolizer) {
|
if (flags()->use_internal_symbolizer) {
|
||||||
static const uptr kMaxAddrFrames = 16;
|
static const uptr kMaxAddrFrames = 16;
|
||||||
InternalScopedBuf<AddressInfo> addr_frames(kMaxAddrFrames);
|
InternalScopedBuffer<AddressInfo> addr_frames(kMaxAddrFrames);
|
||||||
for (uptr i = 0; i < kMaxAddrFrames; i++)
|
for (uptr i = 0; i < kMaxAddrFrames; i++)
|
||||||
new(&addr_frames[i]) AddressInfo();
|
new(&addr_frames[i]) AddressInfo();
|
||||||
uptr addr_frames_num = __sanitizer::SymbolizeCode(addr, addr_frames,
|
uptr addr_frames_num = __sanitizer::SymbolizeCode(addr, addr_frames,
|
||||||
|
|
|
||||||
|
|
@ -85,10 +85,10 @@ static void NOINLINE InitModule(ModuleDesc *m) {
|
||||||
|
|
||||||
static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
|
static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
|
||||||
DlIteratePhdrCtx *ctx = (DlIteratePhdrCtx*)arg;
|
DlIteratePhdrCtx *ctx = (DlIteratePhdrCtx*)arg;
|
||||||
InternalScopedBuf<char> tmp(128);
|
InternalScopedBuffer<char> tmp(128);
|
||||||
if (ctx->is_first) {
|
if (ctx->is_first) {
|
||||||
internal_snprintf(tmp.Ptr(), tmp.Size(), "/proc/%d/exe", GetPid());
|
internal_snprintf(tmp, tmp.size(), "/proc/%d/exe", GetPid());
|
||||||
info->dlpi_name = tmp.Ptr();
|
info->dlpi_name = tmp.data();
|
||||||
}
|
}
|
||||||
ctx->is_first = false;
|
ctx->is_first = false;
|
||||||
if (info->dlpi_name == 0 || info->dlpi_name[0] == 0)
|
if (info->dlpi_name == 0 || info->dlpi_name[0] == 0)
|
||||||
|
|
@ -159,14 +159,14 @@ ReportStack *SymbolizeCodeAddr2Line(uptr addr) {
|
||||||
m->out_fd, errno);
|
m->out_fd, errno);
|
||||||
Die();
|
Die();
|
||||||
}
|
}
|
||||||
InternalScopedBuf<char> func(1024);
|
InternalScopedBuffer<char> func(1024);
|
||||||
ssize_t len = internal_read(m->inp_fd, func, func.Size() - 1);
|
ssize_t len = internal_read(m->inp_fd, func, func.size() - 1);
|
||||||
if (len <= 0) {
|
if (len <= 0) {
|
||||||
TsanPrintf("ThreadSanitizer: can't read from symbolizer (%d, %d)\n",
|
TsanPrintf("ThreadSanitizer: can't read from symbolizer (%d, %d)\n",
|
||||||
m->inp_fd, errno);
|
m->inp_fd, errno);
|
||||||
Die();
|
Die();
|
||||||
}
|
}
|
||||||
func.Ptr()[len] = 0;
|
func.data()[len] = 0;
|
||||||
ReportStack *res = NewReportStackEntry(addr);
|
ReportStack *res = NewReportStackEntry(addr);
|
||||||
res->module = internal_strdup(m->name);
|
res->module = internal_strdup(m->name);
|
||||||
res->offset = offset;
|
res->offset = offset;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue