valgrind.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #pragma once
  2. #if defined(WITH_VALGRIND) && defined(HAVE_VALGRIND)
  3. #include <valgrind/valgrind.h>
  4. #include <valgrind/memcheck.h>
  5. #if !defined(VALGRIND_CHECK_READABLE)
  6. #define VALGRIND_CHECK_READABLE(s, l) VALGRIND_CHECK_MEM_IS_DEFINED(s, l)
  7. #endif
  8. #if !defined(VALGRIND_MAKE_READABLE)
  9. #define VALGRIND_MAKE_READABLE(a, b) VALGRIND_MAKE_MEM_DEFINED(a, b)
  10. #endif
  11. #else
  12. #define RUNNING_ON_VALGRIND 0
  13. #define VALGRIND_CHECK_READABLE(s, l)
  14. #define VALGRIND_MAKE_READABLE(a, b) 0
  15. #define VALGRIND_STACK_REGISTER(start, end) 0
  16. #define VALGRIND_STACK_DEREGISTER(id)
  17. #define VALGRIND_DISCARD(v) ((void)v)
  18. static inline int VALGRIND_PRINTF(...) {
  19. return 0;
  20. }
  21. #define VALGRIND_DO_LEAK_CHECK
  22. #endif
  23. namespace NValgrind {
  24. inline constexpr static bool ValgrindIsOn() noexcept {
  25. #if defined(WITH_VALGRIND)
  26. return true;
  27. #else
  28. return false;
  29. #endif
  30. }
  31. // Returns valgrinded if running under Valgrind and plain otherwise
  32. // Ment to be used in test code for constants (timeouts, etc)
  33. template <typename T>
  34. inline constexpr static T PlainOrUnderValgrind(T plain, T valgrinded) noexcept {
  35. #if defined(WITH_VALGRIND)
  36. Y_UNUSED(plain);
  37. return valgrinded;
  38. #else
  39. Y_UNUSED(valgrinded);
  40. return plain;
  41. #endif
  42. }
  43. } // namespace NValgrind