Valgrind.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //===- llvm/Support/Valgrind.h - Communication with Valgrind -----*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  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.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_SUPPORT_VALGRIND_H
  16. #define LLVM_SUPPORT_VALGRIND_H
  17. #include "llvm/Config/llvm-config.h"
  18. #include "llvm/Support/Compiler.h"
  19. #include <stddef.h>
  20. #if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG)
  21. // tsan (Thread Sanitizer) is a valgrind-based tool that detects these exact
  22. // functions by name.
  23. extern "C" {
  24. void AnnotateHappensAfter(const char *file, int line, const volatile void *cv);
  25. void AnnotateHappensBefore(const char *file, int line, const volatile void *cv);
  26. void AnnotateIgnoreWritesBegin(const char *file, int line);
  27. void AnnotateIgnoreWritesEnd(const char *file, int line);
  28. }
  29. #endif
  30. namespace llvm {
  31. namespace sys {
  32. // True if Valgrind is controlling this process.
  33. bool RunningOnValgrind();
  34. // Discard valgrind's translation of code in the range [Addr .. Addr + Len).
  35. // Otherwise valgrind may continue to execute the old version of the code.
  36. void ValgrindDiscardTranslations(const void *Addr, size_t Len);
  37. #if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG)
  38. // Thread Sanitizer is a valgrind tool that finds races in code.
  39. // See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
  40. // This marker is used to define a happens-before arc. The race detector will
  41. // infer an arc from the begin to the end when they share the same pointer
  42. // argument.
  43. #define TsanHappensBefore(cv) \
  44. AnnotateHappensBefore(__FILE__, __LINE__, cv)
  45. // This marker defines the destination of a happens-before arc.
  46. #define TsanHappensAfter(cv) \
  47. AnnotateHappensAfter(__FILE__, __LINE__, cv)
  48. // Ignore any races on writes between here and the next TsanIgnoreWritesEnd.
  49. #define TsanIgnoreWritesBegin() \
  50. AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
  51. // Resume checking for racy writes.
  52. #define TsanIgnoreWritesEnd() \
  53. AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
  54. #else
  55. #define TsanHappensBefore(cv)
  56. #define TsanHappensAfter(cv)
  57. #define TsanIgnoreWritesBegin()
  58. #define TsanIgnoreWritesEnd()
  59. #endif
  60. }
  61. }
  62. #endif