是否有办法从valgrind中获取泄漏摘要?

问题描述 投票:1回答:1

我正在尝试制作一个脚本,该脚本将编译一个.cpp文件,对输出进行泄漏检查,然后提示用户是否自动运行输出,并且从该角度来看,所有这些都可以正常工作。

问题是我只想要

LEAK SUMMARY:
    definitely lost: ...
    possibly lost: ...
    still reachable: ...
    suppressed: ...

输出部分。我尝试通过grep传递valgrind,但过滤不正确。有什么想法吗?

代码(.sh)

clear; clear; clear; g++ *.cpp -o outputFile && echo "Compilation Successful!" && ( valgrind --leak-check=full ./output | grep  "LEAK\|lost:\|reachable\|suppressed\|possible" ) && {
echo "Do you want to run this file as compiled? (y/n)"
read decision
if [ "$decision" == "y" ]
then
./output
fi
echo "Script ended."
exit
}
echo "Something went wrong!"
exit

输出:

Compilation Successful!
{full valgrind output}
Something went wrong!

虽然出问题了,这行似乎是grep引起的,因为如果删除了grep语句,则脚本的其余部分将正常运行。

所需的输出:

Compilation Successful!
LEAK SUMMARY:
    definitely lost: ...
    possibly lost: ...
    still reachable: ...
    suppressed: ...
Do you want to run this file as compiled? (y/n)
>y
{program output displayed}
Script ended.
c++ bash grep valgrind
1个回答
0
投票

我已使用以下代码修复了代码:

© www.soinside.com 2019 - 2024. All rights reserved.