How to make valgrind ignore certain line?

末鹿安然 提交于 2021-02-08 06:28:31

问题


for example

==26460== 2 bytes in 1 blocks are still reachable in loss record 2 of 105
==26460==    at 0x4C28BE3: malloc (vg_replace_malloc.c:299)
==26460==    by 0x580D889: strdup (in /usr/lib64/libc-2.17.so)
==26460==    by 0x4F50AF: init (init.c:468)
==26460==    by 0x406D75: main (main.c:825)

I want to not check init.c:468: mode = strdup, i'm sure this only malloc once, and will last whole process life.

Is it possible to make valgrind not check this line?


回答1:


As I said in my comment: I recommend not to.

But Valgrind does have a feature to suppress warnings. The most convenient way of suppressing a specific message is supported by the feature dedicated to exactly that purpose:

--gen-suppressions=yes

Which apparently will ouptput the precise suppression syntax for each/any generated message.

See 5.1 in the FAQ:
http://valgrind.org/docs/manual/faq.html#faq.writesupp

(I love their style:
"F:Can you write ... for me?" and I expected a totally adequate
"A:No." But they actually answer
"A: Yes ...". Beyond cool.)




回答2:


You should fix the leaks; it is far better to do so.

You can't stop Valgrind checking for the leaks, but you can stop it reporting them by suppressing the leaks.

Use:

valgrind --gen-suppressions=yes --leak-check=all -- tested-program …

You can then save the suppressions in a file, say tp.suppressions, and subsequently you use:

valgrind --suppressions=tp.suppressions -- tested-program …

If you work on a Mac like I do, and work with bleeding edge systems, you'll often find it necessary to suppress leaks from the system startup code — memory that's allocated before main() is called and which you cannot therefore control.

OTOH, it is routine that after the new release of macOS, it takes a while to get Valgrind running again. I upgraded to macOS High Sierra 10.13; Valgrind has stopped working again because the kernel isn't recognized.



来源:https://stackoverflow.com/questions/46482390/how-to-make-valgrind-ignore-certain-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!