将 callgrind 设置为 valgrind 的默认工具

Set callgrind as default tool of valgrind

我需要使用由某些脚本启动的 callgrind 来分析一个程序,我无法控制。我可以告诉脚本启动 valgrind,但我不能告诉脚本使用哪些工具或参数。

我在 valgrind 手册中发现可以使用变量 $VALGRIND_OPTS.valgrindrc 文件。 这适用于特定于工具的选项。例如,我可以写在 ~/.valgrindrc

--callgrind:callgrind-out-file=<somefile>

当我执行一些测试程序时a.out

valgrind --tool=callgrind a.out

输出文件按照.valgrindrc中的定义编写。 但是我无法指定我想使用的工具(callgrind)。

我试过:

--tool=callgrind

--valgrind:tool=callgrind

两者均无效,默认启动 memcheck。 任何提示将不胜感激!

您可以在 shell 中创建别名:

$ alias valgrind="valgrind --tool=callgrind"

并调用脚本:

$ ./the_script

别名将在脚本中扩展为 valgrind --tool=callgrind

由于 Valgrind 是开源的,您可以获得代码,对其进行修改并构建您自己的默认为 callgrind 的版本。您需要修改的行位于 coregrind/m_options.c 中。这是 3.13:

const HChar *VG_(clo_toolname) = "memcheck";    // default to Memcheck

以下参数在 early_process_cmd_line_options (coregrind/m_main.c) 中处理。这些是无法从 RC 文件或环境中读取的选项。

--version"
"-v"/"--verbose"
"-q"/"--quiet"
"-h"/"--help"
"--help-debug"
"--tool"
"--max-stackframe"
"--main-stacksize"
"--max-threads"
"--sim-hints"