如何检测是否在make文件或shell脚本中运行valgrind?

时间:2021-06-02 16:24:16

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,

我需要检测我的Makefile是否在valgrind下运行(间接地,使用valgrind --trace-children = yes),我知道如何从C中执行它但我还没有找到从脚本中执行此操作的方法,

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.

早期的答案仅适用于Linux。对于Mac OS X,我将在环境中为VALGRIND_STARTUP_PWD进行grep,除非有人有更好的想法。

1 个解决方案

#1


3  

from a shell:

从一个shell:

grep -q '/valgrind' /proc/$$/maps && echo "valgrindage"

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).

这确定了valgrind预加载的库是否存在于进程的地址映射中。这是相当有效的,但如果您碰巧有一个非valgrind相关的库共享'/ valgrind'名字对象,那么您将得到误报(不太可能)。

[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.]

[我将grep模式从vg_preload更改为/ valgrind,因为在Debian / Ubuntu上的测试显示库名称不同,而valgrind的目录匹配最有可能成功。]

#1


3  

from a shell:

从一个shell:

grep -q '/valgrind' /proc/$$/maps && echo "valgrindage"

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).

这确定了valgrind预加载的库是否存在于进程的地址映射中。这是相当有效的,但如果您碰巧有一个非valgrind相关的库共享'/ valgrind'名字对象,那么您将得到误报(不太可能)。

[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.]

[我将grep模式从vg_preload更改为/ valgrind,因为在Debian / Ubuntu上的测试显示库名称不同,而valgrind的目录匹配最有可能成功。]