Jeffrey Yasskin | 3ddd88f | 2010-03-15 04:57:55 +0000 | [diff] [blame] | 1 | //===-- Valgrind.cpp - Implement Valgrind communication ---------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Jeffrey Yasskin | 3ddd88f | 2010-03-15 04:57:55 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Defines Valgrind communication methods, if HAVE_VALGRIND_VALGRIND_H is |
| 10 | // defined. If we have valgrind.h but valgrind isn't running, its macros are |
| 11 | // no-ops. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 15 | #include "llvm/Support/Valgrind.h" |
Jeffrey Yasskin | 3ddd88f | 2010-03-15 04:57:55 +0000 | [diff] [blame] | 16 | #include "llvm/Config/config.h" |
Adrian Prantl | d859638 | 2015-10-15 19:41:54 +0000 | [diff] [blame] | 17 | #include <cstddef> |
Jeffrey Yasskin | 3ddd88f | 2010-03-15 04:57:55 +0000 | [diff] [blame] | 18 | |
| 19 | #if HAVE_VALGRIND_VALGRIND_H |
| 20 | #include <valgrind/valgrind.h> |
| 21 | |
| 22 | static 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. |
| 30 | static const bool NotUnderValgrind = InitNotUnderValgrind(); |
| 31 | |
| 32 | bool llvm::sys::RunningOnValgrind() { |
| 33 | if (NotUnderValgrind) |
| 34 | return false; |
| 35 | return RUNNING_ON_VALGRIND; |
| 36 | } |
| 37 | |
| 38 | void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) { |
| 39 | if (NotUnderValgrind) |
| 40 | return; |
| 41 | |
Duncan Sands | a1c4433 | 2011-07-02 13:14:22 +0000 | [diff] [blame] | 42 | VALGRIND_DISCARD_TRANSLATIONS(Addr, Len); |
Jeffrey Yasskin | 3ddd88f | 2010-03-15 04:57:55 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | #else // !HAVE_VALGRIND_VALGRIND_H |
| 46 | |
| 47 | bool llvm::sys::RunningOnValgrind() { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) { |
| 52 | } |
| 53 | |
| 54 | #endif // !HAVE_VALGRIND_VALGRIND_H |