如何告诉 Valgrind 完全抑制特定的 .so 文件?

发布于 2024-08-24 12:29:26 字数 396 浏览 3 评论 0原文

我正在尝试在我正在开发的程序上使用 Valgrind,但 Valgrind 为我正在使用的库之一生成一堆错误。我希望能够告诉它抑制涉及该库的所有错误。我可以为抑制文件提出的最接近的规则是,

{
   rule name
   Memcheck:Cond
   ...
   obj:/path/to/library/thelibrary.so
}

但这并不能完全完成工作。我必须为出现的每种抑制类型(Cond、Value4、Param 等)创建其中一个,并且似乎仍然会错过一些在堆栈跟踪中包含库的错误。

有没有办法给 Valgrind 一个单一的抑制规则,让它完全忽略某个特定的库?即使没有办法制定涵盖所有抑制类型的规则,是否至少有一种方法可以创建一个忽略特定库中特定抑制类型的所有错误的规则?

I'm trying to use Valgrind on a program that I'm working on, but Valgrind generates a bunch of errors for one of the libraries that I'm using. I'd like to be able to tell it to suppress all errors which involve that library. The closest rule that I can come up with for the suppression file is

{
   rule name
   Memcheck:Cond
   ...
   obj:/path/to/library/thelibrary.so
}

This doesn't entirely do the job, however. I have to create one of these for every suppression type that comes up (Cond, Value4, Param, etc), and it seems to still miss some errors which have the library in the stack trace.

Is there a way to give Valgrind a single suppression rule to make it completely ignore a particular library? And even if there is no way to make such a rule which covers all suppression types, is there at least a way to create a rule which ignores all errors of a particular suppression type from a particular library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绝不服输 2024-08-31 12:29:26

对于大多数抑制类型,您可以省略通配符,如下所示:

{
   name
   Memcheck:Cond
   obj:/path/to/lib/lib.so.10.1
}

{
   name
   Memcheck:Free
   obj:/path/to/lib/lib.so.10.1
}

{
   name
   Memcheck:Value8
   obj:/path/to/lib/lib.so.10.1
}

请注意,您必须单独列出每种类型的错误,不能使用通配符。您还必须列出库的完整路径名(如 valgrind 所示,带有版本号等任何“装饰”)。

此外,泄漏的处理方式也不同——对于那些您需要如下所示的东西的人:

{
   name
   Memcheck:Leak
   fun:*alloc
   ...
   obj:/path/to/lib/lib.so.10.1
   ...
}

For most of the suppression types, you omit the wildcard, like so:

{
   name
   Memcheck:Cond
   obj:/path/to/lib/lib.so.10.1
}

{
   name
   Memcheck:Free
   obj:/path/to/lib/lib.so.10.1
}

{
   name
   Memcheck:Value8
   obj:/path/to/lib/lib.so.10.1
}

Note that you must list each type of error separately, you can't wildcard them. You must also list the entire pathname of the library (as shown by valgrind, with any "decorations" like version numbers).

Also, leaks are handled differently -- for those you need something that looks like this:

{
   name
   Memcheck:Leak
   fun:*alloc
   ...
   obj:/path/to/lib/lib.so.10.1
   ...
}
国粹 2024-08-31 12:29:26

看来有必要为每种错误类型(Cond、Value4、Param 等)包含一个单独的抑制记录。但根据我对 valgrind-3.6.0.SVN-Debian 的测试,我相信您可以对每种类型的错误使用以下简化形式...

{
   <insert_a_suppression_name_here>
   Memcheck:Cond
   ...
   obj:/path/to/library/thelibrary.so.*
   ...
}

{
   <insert_a_suppression_name_here>
   Memcheck:Leak
   ...
   obj:/path/to/library/thelibrary.so.*
   ...
}

这三个点称为帧级通配符 Valgrind 文档。它们匹配调用堆栈中的零个或多个帧。换句话说,当谁调用库或库随后调用什么函数并不重要时,您可以使用它们。

有时错误包括“obj:”框架,有时它们仅使用“fun:”框架。一般来说,这基于该函数是否包含在库的符号表中。如果目标是排除整个库,如果库不包含符号,效果最好,这样您就可以根据库文件名进行排除,而不必为其中的每个函数调用创建单独的抑制图书馆。希望 Valgrind 足够聪明,能够根据库文件名抑制错误,即使它确实知道函数名称,但我还没有验证这一点。

如果您确实需要根据库中的各个函数添加抑制,您应该能够使用相同的形式...

{
   <insert_a_suppression_name_here>
   Memcheck:Leak
   ...
   fun:the_name_of_the_function
   ...
}

注意:您可以在 valgrind 命令中包含 --gen-suppressions=all -line 以便查看抑制每个错误所需的确切形式和名称(包括任何 C++ 修改)。您可以使用该输出作为抑制记录的模板 - 您通常希望将其中的大多数行替换为 ... 以简化抑制关联中可能发生的所有错误的过程与特定的库或函数调用。

注意: 是一个占位符,您可以在其中键入所需的任何描述性文本。要求不能为空。

It appears that it is necessary to include a separate suppression record for each type of error (Cond, Value4, Param, etc). But based on my testing with valgrind-3.6.0.SVN-Debian, I believe you can use the following simplified form for each type of error...

{
   <insert_a_suppression_name_here>
   Memcheck:Cond
   ...
   obj:/path/to/library/thelibrary.so.*
   ...
}

{
   <insert_a_suppression_name_here>
   Memcheck:Leak
   ...
   obj:/path/to/library/thelibrary.so.*
   ...
}

The three dots are called frame-level wildcards in the Valgrind docs. These match zero or more frames in the call stack. In other words, you use these when it doesn't matter who called into the library, or what functions the library subsequently calls.

Sometimes errors include "obj:" frames and sometimes they only use "fun:" frames. This is based, in general, on whether or not that function is included in the library's symbol table. If the goal is to exclude the entire library, it may work best if the library does not include symbols so that you can exclude based on the library filename instead of having to create separate suppressions for each function call within the library. Hopefully, Valgrind is clever enough to suppress errors based on library filename even when it does know the function name, but I haven't verified this.

If you do need to add suppressions based on individual functions within the library, you should be able to use the same form...

{
   <insert_a_suppression_name_here>
   Memcheck:Leak
   ...
   fun:the_name_of_the_function
   ...
}

Note: You can include --gen-suppressions=all on the valgrind command-line in order to see the exact form and names (including any C++ mangling) required to suppress each error. You can use that output as a template for your suppression records -- in which you would usually want to replace most lines with ... in order to simplify the process of suppressing all errors that might occur in association with a specific library or function call.

Note: <insert_a_suppression_name_here> is a placeholder in which you can type whatever descriptive text that you want. It is required to not be blank.

何止钟意 2024-08-31 12:29:26

nobar的答案几乎对我有用,但我收到语法错误:

==15566== FATAL: in suppressions file "suppresion.error.txt" near line 4:
==15566==    bad or missing extra suppression info
==15566== exiting now.

对于系统调用,我需要添加额外的行正如 docs 状态:

Param errors have a mandatory extra information line at this point,
which is the name of the offending system call parameter.

所以我最终得到了这和它的工作原理:

{
   <sup_mmap_length>
   Memcheck:Param
   mmap(length)
   ...
   fun:function_from_offending_lib
   ...
}

nobar's answer almost worked for me, but I was getting a syntax error:

==15566== FATAL: in suppressions file "suppresion.error.txt" near line 4:
==15566==    bad or missing extra suppression info
==15566== exiting now.

For system calls, I needed to add an extra line as the docs state:

Param errors have a mandatory extra information line at this point,
which is the name of the offending system call parameter.

So I ended up with this and it worked:

{
   <sup_mmap_length>
   Memcheck:Param
   mmap(length)
   ...
   fun:function_from_offending_lib
   ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文