Valgrind.h revision 263508
155682Smarkm//===- llvm/Support/Valgrind.h - Communication with Valgrind -----*- C++ -*-===// 2233294Sstas// 3233294Sstas// The LLVM Compiler Infrastructure 4233294Sstas// 555682Smarkm// This file is distributed under the University of Illinois Open Source 6233294Sstas// License. See LICENSE.TXT for details. 7233294Sstas// 8233294Sstas//===----------------------------------------------------------------------===// 955682Smarkm// 10233294Sstas// Methods for communicating with a valgrind instance this program is running 11233294Sstas// under. These are all no-ops unless LLVM was configured on a system with the 1255682Smarkm// valgrind headers installed and valgrind is controlling this process. 13233294Sstas// 14233294Sstas//===----------------------------------------------------------------------===// 15233294Sstas 1655682Smarkm#ifndef LLVM_SUPPORT_VALGRIND_H 17233294Sstas#define LLVM_SUPPORT_VALGRIND_H 18233294Sstas 19233294Sstas#include "llvm/Config/llvm-config.h" 2055682Smarkm#include "llvm/Support/Compiler.h" 21233294Sstas#include <stddef.h> 22233294Sstas 23233294Sstas#if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG) 24233294Sstas// tsan (Thread Sanitizer) is a valgrind-based tool that detects these exact 25233294Sstas// functions by name. 26233294Sstasextern "C" { 27233294SstasLLVM_ATTRIBUTE_WEAK void AnnotateHappensAfter(const char *file, int line, 28233294Sstas const volatile void *cv); 29233294SstasLLVM_ATTRIBUTE_WEAK void AnnotateHappensBefore(const char *file, int line, 30233294Sstas const volatile void *cv); 31233294SstasLLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesBegin(const char *file, int line); 3255682SmarkmLLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesEnd(const char *file, int line); 3355682Smarkm} 3455682Smarkm#endif 35178825Sdfr 3655682Smarkmnamespace llvm { 37178825Sdfrnamespace sys { 38178825Sdfr // True if Valgrind is controlling this process. 3955682Smarkm bool RunningOnValgrind(); 40178825Sdfr 4155682Smarkm // Discard valgrind's translation of code in the range [Addr .. Addr + Len). 42178825Sdfr // Otherwise valgrind may continue to execute the old version of the code. 43178825Sdfr void ValgrindDiscardTranslations(const void *Addr, size_t Len); 44178825Sdfr 45178825Sdfr#if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG) 46178825Sdfr // Thread Sanitizer is a valgrind tool that finds races in code. 47233294Sstas // See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations . 48178825Sdfr 49178825Sdfr // This marker is used to define a happens-before arc. The race detector will 50178825Sdfr // infer an arc from the begin to the end when they share the same pointer 51178825Sdfr // argument. 52178825Sdfr #define TsanHappensBefore(cv) \ 5355682Smarkm AnnotateHappensBefore(__FILE__, __LINE__, cv) 54178825Sdfr 55178825Sdfr // This marker defines the destination of a happens-before arc. 5655682Smarkm #define TsanHappensAfter(cv) \ 57178825Sdfr AnnotateHappensAfter(__FILE__, __LINE__, cv) 58233294Sstas 59178825Sdfr // Ignore any races on writes between here and the next TsanIgnoreWritesEnd. 60178825Sdfr #define TsanIgnoreWritesBegin() \ 61178825Sdfr AnnotateIgnoreWritesBegin(__FILE__, __LINE__) 62178825Sdfr 63178825Sdfr // Resume checking for racy writes. 64178825Sdfr #define TsanIgnoreWritesEnd() \ 65233294Sstas AnnotateIgnoreWritesEnd(__FILE__, __LINE__) 66233294Sstas#else 67178825Sdfr #define TsanHappensBefore(cv) 68178825Sdfr #define TsanHappensAfter(cv) 69178825Sdfr #define TsanIgnoreWritesBegin() 7055682Smarkm #define TsanIgnoreWritesEnd() 71178825Sdfr#endif 72178825Sdfr} 73178825Sdfr} 74178825Sdfr 75178825Sdfr#endif 76178825Sdfr