2

I don't suppose there is a way to programmatically enable/disable Valgrind memcheck the way you can with callgrind? (Start/stop instrumentation).

It's painfully, unusably slow (which is okay if the code you want to test starts automatically and you just leave it running), but I can't actually get into the code that's important without clicking a few buttons in the app, which is rendered completely unresponsive. (My code is a plug-in to another app)

Thanks

mr grumpy
  • 1,513
  • 1
  • 10
  • 17

2 Answers2

4

It's pretty nearly impossible in principle. If valgrind doesn't know the complete history of all your memory, how can it know for sure that something is a leak, or even a reference to invalid memory?

bmargulies
  • 97,814
  • 39
  • 186
  • 310
2

You can't stop/start instrumentation but you can programmatically do incremental leak checks. See http://valgrind.org/docs/manual/mc-manual.html#mc-manual.clientreqs and specifically VALGRIND_DO_LEAK_CHECK, VALGRIND_DO_ADDED_LEAK_CHECK and VALGRIND_DO_CHANGED_LEAK_CHECK.

J.Churchill
  • 430
  • 3
  • 12
  • Also the `VALGRIND_DISABLE_ERROR_REPORTING` and `VALGRIND_ENABLE_ERROR_REPORTING` client-requests, which are handy for filtering things you know aren't interesting en-masse. If you're interested in a slow leak in a long running app you can start up, disable reporting, do an initial leak check, re-enable reporting, and do incremental leak checks to see what's reported. Particularly useful if you're doing `reachable` checking. – Craig Ringer Feb 19 '18 at 07:19