是否可以让 valgrind 忽略某些库?

发布于 2024-09-08 03:19:47 字数 147 浏览 0 评论 0原文

或者最好是全部而不只是我的代码?我的程序使用 Gtk、Loudmouth 和其他一些东西,而这两个(以及它们背后的一些,libgcrypto、libssl)本身导致了如此多的错误,以至于我无法检测到我自己的错误。是否有可能让 valgrind 忽略来自比我自己的代码更深层的东西?

Or preferably all of them instead of just my code? My program uses Gtk, Loudmouth and few other things, and these two (and some behind them, libgcrypto, libssl) are causing so many errors themselves that I'm unable to detect my own. Is it possible to make valgrind ignore things coming from deeper than my own code?

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

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

发布评论

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

评论(3

指尖上得阳光 2024-09-15 03:19:47

假设您正在运行 memcheck 工具,并且您想忽略仅 libcrypto 中的Leak 错误,您可以放置​​ 抑制 就像:

{
   ignore_libcrypto_conditional_jump_errors
   Memcheck:Leak
   ...
   obj:*/libcrypto.so.*
}

...到文件中并将其传递给 valgrind--suppressions=FILENAME

忽略任何 lib 目录(/lib/lib64<下的所有共享库中的泄漏错误/em>、/usr/lib/usr/lib64、...):

{
   ignore_unversioned_libs
   Memcheck:Leak
   ...
   obj:*/lib*/lib*.so
}
{
   ignore_versioned_libs
   Memcheck:Leak
   ...
   obj:*/lib*/lib*.so.*
}

不太可能,但您可能需要添加目录模式的其他变体说明 X11 和 GTK 库的位置。

请注意,这将忽略您编写的库调用的任何回调所导致的错误。捕获这些回调中的错误几乎可以通过以下方式完成:

{
   ignore_unversioned_libs
   Memcheck:Leak
   obj:*/lib*/lib*.so
   ...
   obj:*/lib*/lib*.so
}
{
   ignore_versioned_libs
   Memcheck:Leak
   obj:*/lib*/lib*.so.*
   ...
   obj:*/lib*/lib*.so.*
}

...但这揭示了使用 Valgrind malloc 的库调用中的错误。由于 valgrind malloc 直接注入到程序文本中(而不是作为动态库加载),因此它在堆栈中的显示方式与您自己的代码相同。这使得 Valgrind 能够跟踪分配情况,但也使得准确执行您所要求的操作变得更加困难。

仅供参考:我正在使用 valgrind 3.5。

Assuming you are running the memcheck tool and you want to ignore Leak errors in libcrypto only, you could put a suppression like:

{
   ignore_libcrypto_conditional_jump_errors
   Memcheck:Leak
   ...
   obj:*/libcrypto.so.*
}

... into a file and pass it to valgrind with --suppressions=FILENAME.

To ignore Leak errors in all shared libraries under any lib directory (/lib, /lib64, /usr/lib, /usr/lib64, ...):

{
   ignore_unversioned_libs
   Memcheck:Leak
   ...
   obj:*/lib*/lib*.so
}
{
   ignore_versioned_libs
   Memcheck:Leak
   ...
   obj:*/lib*/lib*.so.*
}

It is unlikely, but you may need to add additional variations of the directory pattern to account for the locations of the X11 and GTK libraries.

Beware that this will ignore errors caused by any callbacks you wrote that were invoked by the libraries. Catching errors in those callbacks could almost be done with:

{
   ignore_unversioned_libs
   Memcheck:Leak
   obj:*/lib*/lib*.so
   ...
   obj:*/lib*/lib*.so
}
{
   ignore_versioned_libs
   Memcheck:Leak
   obj:*/lib*/lib*.so.*
   ...
   obj:*/lib*/lib*.so.*
}

... but this reveals errors in calls by a library that use the Valgrind malloc. Since valgrind malloc is injected directly into the program text -- not loaded as a dynamic library -- it appears in the stack the same way as your own code does. This allows Valgrind to track the allocations, but also makes it harder to do exactly what you have asked.

FYI: I am using valgrind 3.5.

猫卆 2024-09-15 03:19:47

您可以生成对库错误的抑制,但我认为您通常不能排除这些库。

此外,很难自动知道库中的内存错误是否是由代码中的问题引起的。

You can generate suppressions for the errors for the libraries, but I don't think you can exclude the libraries generally.

Also it's hard to automatically know if a memory error in the library is caused by a problem in your code or not.

花开柳相依 2024-09-15 03:19:47

特别是对于 OpenSSL,这是非常困难的。 SSL 加密密钥部分基于未初始化的堆栈垃圾,这意味着所有解密的数据也受到污染。这种污染往往会蔓延到 OpenSSL 本身之外。

使用“PURIFY”选项编译 OpenSSL 可能会有所帮助。不幸的是,由于主要 Linux 发行版的一些考虑不周的行为,这不太可能成为默认设置。

一个非常直接的解决方法是 memcheck 的 --undef-value-errors=no 选项。

With OpenSSL in particular, this is very hard. SSL encryption keys are partially based on uninitialized stack garbage, which means that all decrypted data is contaminated too. This contamination tends to spread beyond OpenSSL itself.

Compiling OpenSSL with a "PURIFY" option may help here. Unfortunately, due to some poorly thought out actions by a major Linux distribution, this is unlikely to become default.

A very blunt workaround is memcheck's --undef-value-errors=no option.

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