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_SUPPORT_VALGRIND_H
17 #define LLVM_SUPPORT_VALGRIND_H
19 #include "llvm/Config/llvm-config.h"
20 #include "llvm/Support/Compiler.h"
23 #if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG)
24 // tsan (Thread Sanitizer) is a valgrind-based tool that detects these exact
27 void AnnotateHappensAfter(const char *file, int line, const volatile void *cv);
28 void AnnotateHappensBefore(const char *file, int line, const volatile void *cv);
29 void AnnotateIgnoreWritesBegin(const char *file, int line);
30 void AnnotateIgnoreWritesEnd(const char *file, int line);
36 // True if Valgrind is controlling this process.
37 bool RunningOnValgrind();
39 // Discard valgrind's translation of code in the range [Addr .. Addr + Len).
40 // Otherwise valgrind may continue to execute the old version of the code.
41 void ValgrindDiscardTranslations(const void *Addr, size_t Len);
43 #if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG)
44 // Thread Sanitizer is a valgrind tool that finds races in code.
45 // See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
47 // This marker is used to define a happens-before arc. The race detector will
48 // infer an arc from the begin to the end when they share the same pointer
50 #define TsanHappensBefore(cv) \
51 AnnotateHappensBefore(__FILE__, __LINE__, cv)
53 // This marker defines the destination of a happens-before arc.
54 #define TsanHappensAfter(cv) \
55 AnnotateHappensAfter(__FILE__, __LINE__, cv)
57 // Ignore any races on writes between here and the next TsanIgnoreWritesEnd.
58 #define TsanIgnoreWritesBegin() \
59 AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
61 // Resume checking for racy writes.
62 #define TsanIgnoreWritesEnd() \
63 AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
65 #define TsanHappensBefore(cv)
66 #define TsanHappensAfter(cv)
67 #define TsanIgnoreWritesBegin()
68 #define TsanIgnoreWritesEnd()