如何排除某些子进程在 valgrind 下运行?

发布于 2024-08-22 12:49:49 字数 179 浏览 6 评论 0原文

我正在 Linux 中运行一个守护进程,我想在 valgrind 下运行这个守护进程来查找与内存相关的错误。由于它是一个守护进程,我需要使用 --trace-children=yes 选项,但这会在其生命周期内生成许多进程,我不希望它们在 valgrind 下运行。有没有办法排除某些孩子在 valgrind 下运行?

I am running a daemon in Linux and I want to run this daemon under valgrind to find memory-related errors. Since it is a daemon, I need to use --trace-children=yes option, but this spawns many processes later on during its lifetime and I don't want them to run under valgrind. Is there a way to exclude certain children from running under valgrind?

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

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

发布评论

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

评论(1

失去的东西太少 2024-08-29 12:49:49

当前发布的版本(valgrind 3.5.0)没有选项来跟踪某些但不是所有子进程。
但是,如果您愿意使用来自 SVN 存储库的最新代码,它包含一个 新选项 --trace-children-skip 用于此目的:

--trace-children-skip=patt1,patt2

<块引用>

此选项仅在指定 --trace-children=yes 时有效。它允许跳过一些孩子。该选项采用逗号分隔的模式列表作为 Valgrind 不应跟踪的子可执行文件的名称。模式可能包括元字符 ?*,它们具有通常的含义。

这对于从 Valgrind 上运行的进程树中修剪无用的分支很有用。但使用时应小心。当 Valgrind 跳过对可执行文件的跟踪时,它不仅会跳过跟踪该可执行文件,还会跳过跟踪该可执行文件的任何子进程。换句话说,该标志不仅仅导致跟踪在指定的可执行文件处停止——它会跳过对以任何指定的可执行文件为根的整个进程子树的跟踪。

较旧的方法是省略 --trace-children=yes,对于您确实想要跟踪的子项,将它们替换为在 valgrind 下运行真实程序的简单脚本:

#!/bin/sh
exec valgrind --log-file=myprog.vg.%p myprog-real "$@"

即使使用新的选项,如果您有一个孙子,您想在 valgrind 下跟踪但想跳过其父级,这种脚本可能会很有用。

The currently released version (valgrind 3.5.0) has no option to trace some but not all children.
However if you are willing to use the latest code from the SVN repository, it contains a new option --trace-children-skip for this purpose:

--trace-children-skip=patt1,patt2

This option only has an effect when --trace-children=yes is specified. It allows for some children to be skipped. The option takes a comma separated list of patterns for the names of child executables that Valgrind should not trace into. Patterns may include the metacharacters ? and *, which have the usual meaning.

This can be useful for pruning uninteresting branches from a tree of processes being run on Valgrind. But you should be careful when using it. When Valgrind skips tracing into an executable, it doesn't just skip tracing that executable, it also skips tracing any of that executable's child processes. In other words, the flag doesn't merely cause tracing to stop at the specified executables -- it skips tracing of entire process subtrees rooted at any of the specified executables.

The older method is to omit --trace-children=yes, and for the children that you do want to trace, replace them with a trivial script that runs the real program under valgrind:

#!/bin/sh
exec valgrind --log-file=myprog.vg.%p myprog-real "$@"

Even with the new option, this kind of script can be useful if you have e.g. a grandchild that you want to trace under valgrind but want to skip its parent.

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