Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用 Valgrind 时,我注意到它仅在进程终止时生成堆摘要。有没有办法强制 Valgrind 在进程仍在运行时扫描内存并打印泄漏报告?
除了VALGRIND_DO_LEAK_CHECK客户端请求之外,您还可以运行 valgrind with--vgdb=yes以启用嵌入式gdbserver,然后在提示符下发出monitor leak_check full reachable any 命令。(gdb)
VALGRIND_DO_LEAK_CHECK
--vgdb=yes
monitor leak_check full reachable any
(gdb)
这不需要修改和重建目标程序,并且具有其他优点:您可以在执行中的任意点设置断点并执行泄漏检查,而不仅仅是您在客户端请求中放置的点。
使用VALGRIND_DO_LEAK_CHECK来自的客户端请求valgrind/memcheck.h。
valgrind/memcheck.h