如何在make文件或shell脚本中检测是否在valgrind下运行?
我需要检测我的 Makefile 是否在 valgrind 下运行(间接地,使用 valgrind --trace-children=yes),我知道如何从 C 执行此操作,但我还没有找到从脚本执行此操作的方法,
早期的答案仅适用于 Linux。 对于 Mac OS X,我将在环境中 grep 查找 VALGRIND_STARTUP_PWD,除非有人有更好的主意。
I need to detect whether my Makefile is running under valgrind (indirectly, using valgrind --trace-children=yes), I know how to do it from C but I have not found a way to do it from a script,
The earlier answers works on Linux only. For Mac OS X I am an going to grep for VALGRIND_STARTUP_PWD in the environment, unless someone has a better idea.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 shell:
grep -q '/valgrind' /proc/$$/maps && echo "valgrindage"
这确定 valgrind 预加载库是否存在于进程的地址映射中。 这是相当有效的,但是如果您碰巧有一个与 valgrind 无关的库共享“/valgrind”名称,那么您将得到误报(不太可能)。
[我将 grep 模式从 vg_preload 更改为 /valgrind,因为在 Debian/Ubuntu 上进行的测试显示库名称不同,而 valgrind 的目录匹配最有可能成功。]
from a shell:
grep -q '/valgrind' /proc/$$/maps && echo "valgrindage"
This determines if the valgrind preloaded libraries are present in address map of the process. This is reasonably effective, but if you happen to have a non-valgrind related library that shares the '/valgrind' moniker then you will get a false positive (unlikely).
[I changed the grep pattern from vg_preload to /valgrind, as testing on Debian/Ubuntu revealed that the library name was different, while a directory match of valgrind is most likely to succeed.]