简体   繁体   English

valgrind输出位置不正确

[英]valgrind improper output location

I have a program that is supposed to run valgind on another program and direct the valgrind output to another file. 我有一个应该在另一个程序上运行valgind并将valgrind输出定向到另一个文件的程序。 The code I'm using is: 我使用的代码是:

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
        "\0"};
execvp("sudo",args);

The problem I'm getting is that no matter what I do, it doesn't actually direct the output anywhere but the terminal. 我遇到的问题是,无论我做什么,它实际上都不会将输出定向到终端以外的任何位置。

I've tried "&>" and ">" with no change. 我尝试了“&>”和“>”,但没有更改。 I've tried running it in terminal with redirected output to file, I've also tried running it in eclipse with terminal arguments, etc. I'm not sure what else I can try. 我试过在终端中运行它,并将输出重定向到文件,我也试过在eclipse中使用终端参数运行它,等等。我不确定我还能尝试什么。

Does anyone have any idea why "&>" isn't redirecting? 有谁知道为什么“&>”不重定向? I have confirmed that typing the args array in the terminal (not as part of the program) does work. 我已经确认在终端中键入args数组(不是作为程序的一部分)确实可以工作。 It seems to just be something with the c++ program (possibly fork?). 这似乎与c ++程序有关(可能是fork?)。

I recommend you to use --log-file=<filename> option. 我建议您使用--log-file=<filename>选项。

From manual: 从手册:

--log-file=<filename>

Specifies that Valgrind should send all of its messages to the specified file. 指定Valgrind应该将其所有消息发送到指定文件。 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. %p被替换为当前进程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. 警告:如果您使用--trace-children = yes并且您的程序调用多个进程或者您的程序派生而未随后调用exec,并且您不使用此说明符(或下面的%q说明符),则所有这些的Valgrind输出进程将进入一个文件,可能会弄乱,甚至可能不完整。

%q{FOO} is replaced with the contents of the environment variable FOO. %q {FOO}替换为环境变量FOO的内容。 If the {FOO} part is malformed, it causes an abort. 如果{FOO}部分格式错误,则将导致中止。 This specifier is rarely needed, but very useful in certain circumstances (eg. when running MPI programs). 该说明符很少需要,但在某些情况下(例如,运行MPI程序时)非常有用。 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. 想法是,您指定一个变量,该变量将为作业中的每个进程设置不同的变量,例如BPROC_RANK或MPI设置中适用的任何变量。 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. 请注意,在某些Shell中,{和}字符可能需要使用反斜杠进行转义。

%% 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. 如果文件名指定了相对文件名,则将其放在程序的初始工作目录中:这是程序在fork或exec之后开始执行的当前目录。 If it specifies an absolute file name (ie. starts with '/') then it is put there. 如果指定了绝对文件名(即以“ /”开头),则将其放置在那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM