code_junkie

How can I detect if a program is running from within valgrind?

Nov 12th, 2011
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <vector>
  2. int main()
  3. {
  4. size_t uint_max = static_cast<size_t>(-1);
  5. std::vector<char> v;
  6. v.reserve(uint_max);
  7. }
  8.  
  9. Warning: silly arg (-1) to __builtin_new()
  10. new/new[] failed and should throw an exception, but Valgrind
  11. cannot throw exceptions and so is aborting instead. Sorry.
  12. at 0x40192BC: VALGRIND_PRINTF_BACKTRACE (valgrind.h:319)
  13. by 0x401C823: operator new(unsigned) (vg_replace_malloc.c:164)
  14. by 0x80487BF: std::vector<char, std::allocator<char> >::reserve(unsigned) new_allocator.h:92)
  15. by 0x804874D: main (vg.cxx:6)
  16.  
  17. MYAPP_UNIT_TESTS_DISABLED="NEW_MINUS_ONE,FLY_TO_MOON,DEREF_NULL" valgrind myapp
  18.  
  19. bool unit_test_enabled(const char *testname);
Add Comment
Please, Sign In to add comment