使Valgrind错误抑制通用于对象库,带通配符。

huangapple go评论103阅读模式
英文:

Make a valgrind error suppression generic for an object library, with wildcards

问题

在C++项目中使用Valgrind,我一直在尝试抑制来自第三方库的内存泄漏信息。我会通过运行Valgrind并使用--gen-suppressions=all选项来生成特定的抑制文件条目,例如:

  1. {
  2. <insert_a_suppression_name_here>
  3. Memcheck:Leak
  4. match-leak-kinds: reachable
  5. fun:malloc
  6. obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
  7. obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
  8. obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
  9. obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
  10. obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
  11. obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
  12. obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
  13. obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
  14. obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
  15. obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
  16. obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
  17. }

现在我想通用化该规则,以便抑制来自任何名为*libcuda*的库的任何警告。我尝试了不同的方法,如:

  1. {
  2. cuda
  3. memcheck:Leak
  4. ...
  5. obj:*libcuda*
  6. ...
  7. }

或者

  1. {
  2. cuda
  3. memcheck:Leak
  4. obj:*libcuda*
  5. }

或者(受到这个回答的启发 this

  1. {
  2. cuda
  3. memcheck:Leak
  4. fun:*alloc
  5. ...
  6. obj:*libcuda*
  7. ...
  8. }

以上所有方法都不起作用,因此即使Valgrind在不报错的情况下读取了抑制文件,我的libcuda来源的消息也不会被抑制。是否有办法让Valgrind接受这种通用抑制命令?

英文:

Using valgrind in the context of a C++ project, I have been trying to suppress memory leak information coming from third party libraries. I would generate the specific suppression file entry running valgrind with --gen-suppressions=all and obtain for example:

  1. {
  2. &lt;insert_a_suppression_name_here&gt;
  3. Memcheck:Leak
  4. match-leak-kinds: reachable
  5. fun:malloc
  6. obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
  7. obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
  8. obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
  9. obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
  10. obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
  11. obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
  12. obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
  13. obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
  14. obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
  15. obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
  16. obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
  17. }

Now I would like to generalize that rule so that it suppresses any warning coming from any library called *libcuda*. I tried different things, like:

  1. {
  2. cuda
  3. memcheck:Leak
  4. ...
  5. obj:*libcuda*
  6. ...
  7. }

or

  1. {
  2. cuda
  3. memcheck:Leak
  4. obj:*libcuda*
  5. }

or (inspired by this)

  1. {
  2. cuda
  3. memcheck:Leak
  4. fun:*alloc
  5. ...
  6. obj:*libcuda*
  7. ...
  8. }

None of this worked, so even if the suppression file is read by valgrind with no complaint, none of my libcuda originated messages get suppressed.
Is there a way to make Valgrind accept this kind of generic suppression commands?

答案1

得分: 2

主要问题是您将 Memcheck 拼写为小写 m

以下内容将有效:

  1. {
  2. cuda
  3. Memcheck:Leak
  4. ...
  5. obj:*libcuda*
  6. }

您放置的最后一个帧通配符 ... 是不必要的。

英文:

The main problem is that you have mispelled Memcheck with lowercase m.

The following will work:

  1. {
  2. cuda
  3. Memcheck:Leak
  4. ...
  5. obj:*libcuda*
  6. }

The last frame wildcard ... you had put is not necessary.

huangapple
  • 本文由 发表于 2023年6月12日 23:07:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76457983.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定