1 //===- llvm/Support/Valgrind.h - Communication with Valgrind -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Methods for communicating with a valgrind instance this program is running
11 // under. These are all no-ops unless LLVM was configured on a system with the
12 // valgrind headers installed and valgrind is controlling this process.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_SYSTEM_VALGRIND_H
17 #define LLVM_SYSTEM_VALGRIND_H
19 #include "llvm/Support/Compiler.h"
20 #include "llvm/Config/llvm-config.h"
23 #if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG)
24 // tsan (Thread Sanitizer) is a valgrind-based tool that detects these exact
27 LLVM_ATTRIBUTE_WEAK void AnnotateHappensAfter(const char *file, int line,
28 const volatile void *cv);
29 LLVM_ATTRIBUTE_WEAK void AnnotateHappensBefore(const char *file, int line,
30 const volatile void *cv);
31 LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesBegin(const char *file, int line);
32 LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesEnd(const char *file, int line);
38 // True if Valgrind is controlling this process.
39 bool RunningOnValgrind();
41 // Discard valgrind's translation of code in the range [Addr .. Addr + Len).
42 // Otherwise valgrind may continue to execute the old version of the code.
43 void ValgrindDiscardTranslations(const void *Addr, size_t Len);
45 #if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG)
46 // Thread Sanitizer is a valgrind tool that finds races in code.
47 // See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
49 // This marker is used to define a happens-before arc. The race detector will
50 // infer an arc from the begin to the end when they share the same pointer
52 #define TsanHappensBefore(cv) \
53 AnnotateHappensBefore(__FILE__, __LINE__, cv)
55 // This marker defines the destination of a happens-before arc.
56 #define TsanHappensAfter(cv) \
57 AnnotateHappensAfter(__FILE__, __LINE__, cv)
59 // Ignore any races on writes between here and the next TsanIgnoreWritesEnd.
60 #define TsanIgnoreWritesBegin() \
61 AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
63 // Resume checking for racy writes.
64 #define TsanIgnoreWritesEnd() \
65 AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
67 #define TsanHappensBefore(cv)
68 #define TsanHappensAfter(cv)
69 #define TsanIgnoreWritesBegin()
70 #define TsanIgnoreWritesEnd()