blob: 8d852a67c0756b1b4cf6dc2d66c1879e0dc2b9e4 [file] [log] [blame]
Jeffrey Yasskin3ddd88f2010-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. Spencer447762d2010-11-29 18:16:10 +000016#include "llvm/Support/Valgrind.h"
Jeffrey Yasskin3ddd88f2010-03-15 04:57:55 +000017#include "llvm/Config/config.h"
Adrian Prantld8596382015-10-15 19:41:54 +000018#include <cstddef>
Jeffrey Yasskin3ddd88f2010-03-15 04:57:55 +000019
20#if HAVE_VALGRIND_VALGRIND_H
21#include <valgrind/valgrind.h>
22
23static bool InitNotUnderValgrind() {
24 return !RUNNING_ON_VALGRIND;
25}
26
27// This bool is negated from what we'd expect because code may run before it
28// gets initialized. If that happens, it will appear to be 0 (false), and we
29// want that to cause the rest of the code in this file to run the
30// Valgrind-provided macros.
31static const bool NotUnderValgrind = InitNotUnderValgrind();
32
33bool llvm::sys::RunningOnValgrind() {
34 if (NotUnderValgrind)
35 return false;
36 return RUNNING_ON_VALGRIND;
37}
38
39void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
40 if (NotUnderValgrind)
41 return;
42
Duncan Sandsa1c44332011-07-02 13:14:22 +000043 VALGRIND_DISCARD_TRANSLATIONS(Addr, Len);
Jeffrey Yasskin3ddd88f2010-03-15 04:57:55 +000044}
45
46#else // !HAVE_VALGRIND_VALGRIND_H
47
48bool llvm::sys::RunningOnValgrind() {
49 return false;
50}
51
52void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
53}
54
55#endif // !HAVE_VALGRIND_VALGRIND_H