LLVM API Documentation

Valgrind.cpp
Go to the documentation of this file.
00001 //===-- Valgrind.cpp - Implement Valgrind communication ---------*- 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 //  Defines Valgrind communication methods, if HAVE_VALGRIND_VALGRIND_H is
00011 //  defined.  If we have valgrind.h but valgrind isn't running, its macros are
00012 //  no-ops.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #include "llvm/Support/Valgrind.h"
00017 #include "llvm/Config/config.h"
00018 
00019 #if HAVE_VALGRIND_VALGRIND_H
00020 #include <valgrind/valgrind.h>
00021 
00022 static bool InitNotUnderValgrind() {
00023   return !RUNNING_ON_VALGRIND;
00024 }
00025 
00026 // This bool is negated from what we'd expect because code may run before it
00027 // gets initialized.  If that happens, it will appear to be 0 (false), and we
00028 // want that to cause the rest of the code in this file to run the
00029 // Valgrind-provided macros.
00030 static const bool NotUnderValgrind = InitNotUnderValgrind();
00031 
00032 bool llvm::sys::RunningOnValgrind() {
00033   if (NotUnderValgrind)
00034     return false;
00035   return RUNNING_ON_VALGRIND;
00036 }
00037 
00038 void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
00039   if (NotUnderValgrind)
00040     return;
00041 
00042   VALGRIND_DISCARD_TRANSLATIONS(Addr, Len);
00043 }
00044 
00045 #else  // !HAVE_VALGRIND_VALGRIND_H
00046 
00047 bool llvm::sys::RunningOnValgrind() {
00048   return false;
00049 }
00050 
00051 void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
00052 }
00053 
00054 #endif  // !HAVE_VALGRIND_VALGRIND_H
00055 
00056 #if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG)
00057 // These functions require no implementation, tsan just looks at the arguments
00058 // they're called with. However, they are required to be weak as some other
00059 // application or library may already be providing these definitions for the
00060 // same reason we are.
00061 extern "C" {
00062 LLVM_ATTRIBUTE_WEAK void AnnotateHappensAfter(const char *file, int line,
00063                                               const volatile void *cv);
00064 void AnnotateHappensAfter(const char *file, int line, const volatile void *cv) {
00065 }
00066 LLVM_ATTRIBUTE_WEAK void AnnotateHappensBefore(const char *file, int line,
00067                                                const volatile void *cv);
00068 void AnnotateHappensBefore(const char *file, int line,
00069                            const volatile void *cv) {}
00070 LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesBegin(const char *file, int line);
00071 void AnnotateIgnoreWritesBegin(const char *file, int line) {}
00072 LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesEnd(const char *file, int line);
00073 void AnnotateIgnoreWritesEnd(const char *file, int line) {}
00074 }
00075 #endif