valgrind 不正确的输出位置
valgrind improper output location
我有一个程序应该在另一个程序上 运行 valgind 并将 valgrind 输出定向到另一个文件。我使用的代码是:
char* args[] = {"sudo", //(This is inside a fork)
"valgrind",
"--leak-check=full",
"--show-leak-kinds=definite",
"--errors-for-leak-kinds=definite",
"<path to executable>", //placeholders
"&><path to output file>", //placeholders
"[=10=]"};
execvp("sudo",args);
我遇到的问题是,无论我做什么,它实际上都不会将输出定向到终端以外的任何地方。
我试过“&>”和“>”都没有改变。我已经尝试 运行 在终端中使用重定向输出到文件,我也尝试 运行 在 eclipse 中使用终端参数使用它,等等。我不确定我还能尝试什么。
有谁知道为什么“&>”没有重定向?我已经确认在终端中输入 args 数组(不是作为程序的一部分)确实有效。好像只是c++程序的问题(可能是fork?)。
我建议您使用 --log-file=<filename>
选项。
来自手册:
--log-file=<filename>
Specifies that Valgrind should send all of its messages to the specified file. If the file name is empty, it causes
an abort. There are three special format specifiers that can be used
in the file name.
%p is replaced with the current process ID. This is very useful for
program that invoke multiple processes. WARNING: If you use
--trace-children=yes and your program invokes multiple processes OR your program forks without calling exec afterwards, and you don't use
this specifier (or the %q specifier below), the Valgrind output from
all those processes will go into one file, possibly jumbled up, and
possibly incomplete.
%q{FOO} is replaced with the contents of the environment variable FOO.
If the {FOO} part is malformed, it causes an abort. This specifier is
rarely needed, but very useful in certain circumstances (eg. when
running MPI programs). The idea is that you specify a variable which
will be set differently for each process in the job, for example
BPROC_RANK or whatever is applicable in your MPI setup. If the named
environment variable is not set, it causes an abort. Note that in some
shells, the { and } characters may need to be escaped with a
backslash.
%% is replaced with %.
If an % is followed by any other character, it causes an abort.
If the file name specifies a relative file name, it is put in the
program's initial working directory : this is the current directory
when the program started its execution after the fork or after the
exec. If it specifies an absolute file name (ie. starts with '/') then
it is put there.
我有一个程序应该在另一个程序上 运行 valgind 并将 valgrind 输出定向到另一个文件。我使用的代码是:
char* args[] = {"sudo", //(This is inside a fork)
"valgrind",
"--leak-check=full",
"--show-leak-kinds=definite",
"--errors-for-leak-kinds=definite",
"<path to executable>", //placeholders
"&><path to output file>", //placeholders
"[=10=]"};
execvp("sudo",args);
我遇到的问题是,无论我做什么,它实际上都不会将输出定向到终端以外的任何地方。
我试过“&>”和“>”都没有改变。我已经尝试 运行 在终端中使用重定向输出到文件,我也尝试 运行 在 eclipse 中使用终端参数使用它,等等。我不确定我还能尝试什么。
有谁知道为什么“&>”没有重定向?我已经确认在终端中输入 args 数组(不是作为程序的一部分)确实有效。好像只是c++程序的问题(可能是fork?)。
我建议您使用 --log-file=<filename>
选项。
来自手册:
--log-file=<filename>
Specifies that Valgrind should send all of its messages to the specified file. If the file name is empty, it causes an abort. There are three special format specifiers that can be used in the file name.
%p is replaced with the current process ID. This is very useful for program that invoke multiple processes. WARNING: If you use --trace-children=yes and your program invokes multiple processes OR your program forks without calling exec afterwards, and you don't use this specifier (or the %q specifier below), the Valgrind output from all those processes will go into one file, possibly jumbled up, and possibly incomplete.
%q{FOO} is replaced with the contents of the environment variable FOO. If the {FOO} part is malformed, it causes an abort. This specifier is rarely needed, but very useful in certain circumstances (eg. when running MPI programs). The idea is that you specify a variable which will be set differently for each process in the job, for example BPROC_RANK or whatever is applicable in your MPI setup. If the named environment variable is not set, it causes an abort. Note that in some shells, the { and } characters may need to be escaped with a backslash.
%% is replaced with %.
If an % is followed by any other character, it causes an abort.
If the file name specifies a relative file name, it is put in the program's initial working directory : this is the current directory when the program started its execution after the fork or after the exec. If it specifies an absolute file name (ie. starts with '/') then it is put there.