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
|
|
|
|
2011-11-29 06:14:02 +08:00
|
|
|
#if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG)
|
2011-11-15 04:50:16 +08:00
|
|
|
// These functions require no implementation, tsan just looks at the arguments
|
|
|
|
// they're called with.
|
|
|
|
extern "C" {
|
2011-11-15 09:23:22 +08:00
|
|
|
void AnnotateHappensBefore(const char *file, int line,
|
|
|
|
const volatile void *cv) {}
|
|
|
|
void AnnotateHappensAfter(const char *file, int line,
|
|
|
|
const volatile void *cv) {}
|
|
|
|
void AnnotateIgnoreWritesBegin(const char *file, int line) {}
|
|
|
|
void AnnotateIgnoreWritesEnd(const char *file, int line) {}
|
2011-11-15 04:50:16 +08:00
|
|
|
}
|
2011-11-29 06:14:02 +08:00
|
|
|
#endif
|