LLVM  3.7.0
Valgrind.cpp
Go to the documentation of this file.
1 //===-- 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 
16 #include "llvm/Support/Valgrind.h"
17 #include "llvm/Config/config.h"
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 
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 
42  VALGRIND_DISCARD_TRANSLATIONS(Addr, Len);
43 }
44 
45 #else // !HAVE_VALGRIND_VALGRIND_H
46 
48  return false;
49 }
50 
51 void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
52 }
53 
54 #endif // !HAVE_VALGRIND_VALGRIND_H
55 
56 // These functions require no implementation, tsan just looks at the arguments
57 // they're called with. However, they are required to be weak as some other
58 // application or library may already be providing these definitions for the
59 // same reason we are.
60 extern "C" {
61 LLVM_ATTRIBUTE_WEAK void AnnotateHappensAfter(const char *file, int line,
62  const volatile void *cv);
63 void AnnotateHappensAfter(const char *file, int line, const volatile void *cv) {
64 }
65 LLVM_ATTRIBUTE_WEAK void AnnotateHappensBefore(const char *file, int line,
66  const volatile void *cv);
67 void AnnotateHappensBefore(const char *file, int line,
68  const volatile void *cv) {}
69 LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesBegin(const char *file, int line);
70 void AnnotateIgnoreWritesBegin(const char *file, int line) {}
71 LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesEnd(const char *file, int line);
72 void AnnotateIgnoreWritesEnd(const char *file, int line) {}
73 }
74 
static const bool NotUnderValgrind
Definition: Valgrind.cpp:30
void ValgrindDiscardTranslations(const void *Addr, size_t Len)
Definition: Valgrind.cpp:38
Number of individual test Apply this number of consecutive mutations to each input exit after the first new interesting input is found the minimized corpus is saved into the first input directory Number of jobs to run If Reload the main corpus periodically to get new units discovered by other processes Read the given input file
#define LLVM_ATTRIBUTE_WEAK
Definition: Compiler.h:150
LLVM_ATTRIBUTE_WEAK void AnnotateHappensAfter(const char *file, int line, const volatile void *cv)
Definition: Valgrind.cpp:63
LLVM_ATTRIBUTE_WEAK void AnnotateHappensBefore(const char *file, int line, const volatile void *cv)
Definition: Valgrind.cpp:67
bool RunningOnValgrind()
Definition: Valgrind.cpp:32
LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesBegin(const char *file, int line)
Definition: Valgrind.cpp:70
static bool InitNotUnderValgrind()
Definition: Valgrind.cpp:22
LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesEnd(const char *file, int line)
Definition: Valgrind.cpp:72