LLVM API Documentation

Valgrind.h
Go to the documentation of this file.
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_SYSTEM_VALGRIND_H
00017 #define LLVM_SYSTEM_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 LLVM_ATTRIBUTE_WEAK void AnnotateHappensAfter(const char *file, int line,
00028                                               const volatile void *cv);
00029 LLVM_ATTRIBUTE_WEAK void AnnotateHappensBefore(const char *file, int line,
00030                                                const volatile void *cv);
00031 LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesBegin(const char *file, int line);
00032 LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesEnd(const char *file, int line);
00033 }
00034 #endif
00035 
00036 namespace llvm {
00037 namespace sys {
00038   // True if Valgrind is controlling this process.
00039   bool RunningOnValgrind();
00040 
00041   // Discard valgrind's translation of code in the range [Addr .. Addr + Len).
00042   // Otherwise valgrind may continue to execute the old version of the code.
00043   void ValgrindDiscardTranslations(const void *Addr, size_t Len);
00044 
00045 #if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG)
00046   // Thread Sanitizer is a valgrind tool that finds races in code.
00047   // See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
00048 
00049   // This marker is used to define a happens-before arc. The race detector will
00050   // infer an arc from the begin to the end when they share the same pointer
00051   // argument.
00052   #define TsanHappensBefore(cv) \
00053     AnnotateHappensBefore(__FILE__, __LINE__, cv)
00054 
00055   // This marker defines the destination of a happens-before arc.
00056   #define TsanHappensAfter(cv) \
00057     AnnotateHappensAfter(__FILE__, __LINE__, cv)
00058 
00059   // Ignore any races on writes between here and the next TsanIgnoreWritesEnd.
00060   #define TsanIgnoreWritesBegin() \
00061     AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
00062 
00063   // Resume checking for racy writes.
00064   #define TsanIgnoreWritesEnd() \
00065     AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
00066 #else
00067   #define TsanHappensBefore(cv)
00068   #define TsanHappensAfter(cv)
00069   #define TsanIgnoreWritesBegin()
00070   #define TsanIgnoreWritesEnd()
00071 #endif
00072 }
00073 }
00074 
00075 #endif