2010-03-15 12:57:55 +08:00
|
|
|
//===-- Valgrind.cpp - Implement Valgrind communication ---------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Defines Valgrind communication methods, if HAVE_VALGRIND_VALGRIND_H is
|
|
|
|
// defined. If we have valgrind.h but valgrind isn't running, its macros are
|
|
|
|
// no-ops.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-11-30 02:16:10 +08:00
|
|
|
#include "llvm/Support/Valgrind.h"
|
2010-03-15 12:57:55 +08:00
|
|
|
#include "llvm/Config/config.h"
|
|
|
|
|
|
|
|
#if HAVE_VALGRIND_VALGRIND_H
|
|
|
|
#include <valgrind/valgrind.h>
|
|
|
|
|
|
|
|
static bool InitNotUnderValgrind() {
|
|
|
|
return !RUNNING_ON_VALGRIND;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This bool is negated from what we'd expect because code may run before it
|
|
|
|
// gets initialized. If that happens, it will appear to be 0 (false), and we
|
|
|
|
// want that to cause the rest of the code in this file to run the
|
|
|
|
// Valgrind-provided macros.
|
|
|
|
static const bool NotUnderValgrind = InitNotUnderValgrind();
|
|
|
|
|
|
|
|
bool llvm::sys::RunningOnValgrind() {
|
|
|
|
if (NotUnderValgrind)
|
|
|
|
return false;
|
|
|
|
return RUNNING_ON_VALGRIND;
|
|
|
|
}
|
|
|
|
|
|
|
|
void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
|
|
|
|
if (NotUnderValgrind)
|
|
|
|
return;
|
|
|
|
|
2011-07-02 21:14:22 +08:00
|
|
|
VALGRIND_DISCARD_TRANSLATIONS(Addr, Len);
|
2010-03-15 12:57:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#else // !HAVE_VALGRIND_VALGRIND_H
|
|
|
|
|
|
|
|
bool llvm::sys::RunningOnValgrind() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !HAVE_VALGRIND_VALGRIND_H
|
2011-11-15 04:50:16 +08:00
|
|
|
|
|
|
|
// These functions require no implementation, tsan just looks at the arguments
|
2014-03-30 19:20:25 +08:00
|
|
|
// they're called with. However, they are required to be weak as some other
|
|
|
|
// application or library may already be providing these definitions for the
|
|
|
|
// same reason we are.
|
2011-11-15 04:50:16 +08:00
|
|
|
extern "C" {
|
2014-03-30 19:20:25 +08:00
|
|
|
LLVM_ATTRIBUTE_WEAK void AnnotateHappensAfter(const char *file, int line,
|
|
|
|
const volatile void *cv);
|
|
|
|
void AnnotateHappensAfter(const char *file, int line, const volatile void *cv) {
|
|
|
|
}
|
|
|
|
LLVM_ATTRIBUTE_WEAK void AnnotateHappensBefore(const char *file, int line,
|
|
|
|
const volatile void *cv);
|
2011-11-15 09:23:22 +08:00
|
|
|
void AnnotateHappensBefore(const char *file, int line,
|
|
|
|
const volatile void *cv) {}
|
2014-03-30 19:20:25 +08:00
|
|
|
LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesBegin(const char *file, int line);
|
2011-11-15 09:23:22 +08:00
|
|
|
void AnnotateIgnoreWritesBegin(const char *file, int line) {}
|
2014-03-30 19:20:25 +08:00
|
|
|
LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesEnd(const char *file, int line);
|
2011-11-15 09:23:22 +08:00
|
|
|
void AnnotateIgnoreWritesEnd(const char *file, int line) {}
|
2011-11-15 04:50:16 +08:00
|
|
|
}
|
2015-02-19 13:30:16 +08:00
|
|
|
|