blob: 078d705183d05b89fe440fc1adf634104f678dec [file] [log] [blame]
Jeffrey Yasskinf28411f2010-03-15 04:57:55 +00001//===-- Valgrind.cpp - Implement Valgrind communication ---------*- C++ -*-===//
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// Defines Valgrind communication methods, if HAVE_VALGRIND_VALGRIND_H is
11// defined. If we have valgrind.h but valgrind isn't running, its macros are
12// no-ops.
13//
14//===----------------------------------------------------------------------===//
15
Michael J. Spencer1f6efa32010-11-29 18:16:10 +000016#include "llvm/Support/Valgrind.h"
Jeffrey Yasskinf28411f2010-03-15 04:57:55 +000017#include "llvm/Config/config.h"
18
19#if HAVE_VALGRIND_VALGRIND_H
20#include <valgrind/valgrind.h>
21
22static bool InitNotUnderValgrind() {
23 return !RUNNING_ON_VALGRIND;
24}
25
26// This bool is negated from what we'd expect because code may run before it
27// gets initialized. If that happens, it will appear to be 0 (false), and we
28// want that to cause the rest of the code in this file to run the
29// Valgrind-provided macros.
30static const bool NotUnderValgrind = InitNotUnderValgrind();
31
32bool llvm::sys::RunningOnValgrind() {
33 if (NotUnderValgrind)
34 return false;
35 return RUNNING_ON_VALGRIND;
36}
37
38void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
39 if (NotUnderValgrind)
40 return;
41
Duncan Sandsba519f82011-07-02 13:14:22 +000042 VALGRIND_DISCARD_TRANSLATIONS(Addr, Len);
Jeffrey Yasskinf28411f2010-03-15 04:57:55 +000043}
44
45#else // !HAVE_VALGRIND_VALGRIND_H
46
47bool llvm::sys::RunningOnValgrind() {
48 return false;
49}
50
51void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
52}
53
54#endif // !HAVE_VALGRIND_VALGRIND_H
Nick Lewycky4d0a9ff2011-11-14 20:50:16 +000055
56// These functions require no implementation, tsan just looks at the arguments
57// they're called with.
58extern "C" {
Nick Lewyckye7c1aef2011-11-15 01:23:22 +000059void AnnotateHappensBefore(const char *file, int line,
60 const volatile void *cv) {}
61void AnnotateHappensAfter(const char *file, int line,
62 const volatile void *cv) {}
63void AnnotateIgnoreWritesBegin(const char *file, int line) {}
64void AnnotateIgnoreWritesEnd(const char *file, int line) {}
Nick Lewycky4d0a9ff2011-11-14 20:50:16 +000065}