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

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

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

问题

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

{
   <insert_a_suppression_name_here>
   Memcheck:Leak
   match-leak-kinds: reachable
   fun:malloc
   obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
   obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
   obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
   obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
   obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
   obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
   obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
   obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
   obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
   obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
   obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
}

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

{
   cuda
   memcheck:Leak
   ...
   obj:*libcuda*
   ...
}

或者

{
   cuda
   memcheck:Leak
   obj:*libcuda*
}

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

{
   cuda
   memcheck:Leak
   fun:*alloc
   ...
   obj:*libcuda*
   ...
}

以上所有方法都不起作用,因此即使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:

{
   &lt;insert_a_suppression_name_here&gt;
   Memcheck:Leak
   match-leak-kinds: reachable
   fun:malloc
   obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
   obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
   obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
   obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
   obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
   obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
   obj:/usr/lib/x86_64-linux-gnu/libcuda.so.515.105.01
   obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
   obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
   obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
   obj:/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart.so.11.6.55
}

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:

{
   cuda
   memcheck:Leak
   ...
   obj:*libcuda*
   ...
}

or

{
   cuda
   memcheck:Leak
   obj:*libcuda*
}

or (inspired by this)

{
   cuda
   memcheck:Leak
   fun:*alloc
   ...
   obj:*libcuda*
   ...
}

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

以下内容将有效:

{
   cuda
   Memcheck:Leak
   ...
   obj:*libcuda*
}

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

英文:

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

The following will work:

{
   cuda
   Memcheck:Leak
   ...
   obj:*libcuda*
}

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:

确定