LLVM API Documentation
00001 //===- llvm/Support/Valgrind.h - Communication with Valgrind -----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // Methods for communicating with a valgrind instance this program is running 00011 // under. These are all no-ops unless LLVM was configured on a system with the 00012 // valgrind headers installed and valgrind is controlling this process. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_SUPPORT_VALGRIND_H 00017 #define LLVM_SUPPORT_VALGRIND_H 00018 00019 #include "llvm/Config/llvm-config.h" 00020 #include "llvm/Support/Compiler.h" 00021 #include <stddef.h> 00022 00023 #if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG) 00024 // tsan (Thread Sanitizer) is a valgrind-based tool that detects these exact 00025 // functions by name. 00026 extern "C" { 00027 void AnnotateHappensAfter(const char *file, int line, const volatile void *cv); 00028 void AnnotateHappensBefore(const char *file, int line, const volatile void *cv); 00029 void AnnotateIgnoreWritesBegin(const char *file, int line); 00030 void AnnotateIgnoreWritesEnd(const char *file, int line); 00031 } 00032 #endif 00033 00034 namespace llvm { 00035 namespace sys { 00036 // True if Valgrind is controlling this process. 00037 bool RunningOnValgrind(); 00038 00039 // Discard valgrind's translation of code in the range [Addr .. Addr + Len). 00040 // Otherwise valgrind may continue to execute the old version of the code. 00041 void ValgrindDiscardTranslations(const void *Addr, size_t Len); 00042 00043 #if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG) 00044 // Thread Sanitizer is a valgrind tool that finds races in code. 00045 // See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations . 00046 00047 // This marker is used to define a happens-before arc. The race detector will 00048 // infer an arc from the begin to the end when they share the same pointer 00049 // argument. 00050 #define TsanHappensBefore(cv) \ 00051 AnnotateHappensBefore(__FILE__, __LINE__, cv) 00052 00053 // This marker defines the destination of a happens-before arc. 00054 #define TsanHappensAfter(cv) \ 00055 AnnotateHappensAfter(__FILE__, __LINE__, cv) 00056 00057 // Ignore any races on writes between here and the next TsanIgnoreWritesEnd. 00058 #define TsanIgnoreWritesBegin() \ 00059 AnnotateIgnoreWritesBegin(__FILE__, __LINE__) 00060 00061 // Resume checking for racy writes. 00062 #define TsanIgnoreWritesEnd() \ 00063 AnnotateIgnoreWritesEnd(__FILE__, __LINE__) 00064 #else 00065 #define TsanHappensBefore(cv) 00066 #define TsanHappensAfter(cv) 00067 #define TsanIgnoreWritesBegin() 00068 #define TsanIgnoreWritesEnd() 00069 #endif 00070 } 00071 } 00072 00073 #endif