Valgrind 未检测:“总堆使用量:0 次分配、0 次释放、0 字节分配”
即使在引入故意内存泄漏之后,valgrind 也会显示:
==13483== HEAP SUMMARY:
==13483== in use at exit: 0 bytes in 0 blocks
==13483== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==13483==
==13483== All heap blocks were freed -- no leaks are possible
可执行文件是用 G++ 4.1.2 和 4.6.2 编译的:
g++ -ftemplate-depth-128 -O0 -fno-inline -Wall -pedantic -g -pthread -Wno-long-long -Wno-uninitialized <snipped definitions and include directives from the build system>
我尝试过使用 Valgrind 3.5.0 和 3.6.1,例如:
valgrind --leak-check=full --undef-value-errors=no --show-reachable=yes <executable args>
在我正在工作的库的框架内上,我正在使用一个简单的测试用例:
#include "pwiz/utility/misc/Std.hpp"
#include "pwiz/utility/misc/Filesystem.hpp"
#include "pwiz/data/identdata/IdentDataFile.hpp"
using namespace pwiz::cv;
using namespace pwiz::data;
using namespace pwiz::identdata;
using namespace pwiz::util;
int main(int argc, char** argv)
{
vector<string> args(argv+1, argv+argc);
BOOST_FOREACH(const bfs::path& filename, args)
{
// intentional memory leak
IdentDataFile* idp = new IdentDataFile(filename.string());
IdentDataFile& id = *idp;
cout << filename.string() << " "
<< id.analysisCollection.spectrumIdentification[0]->activityDate << " "
<< id.analysisCollection.spectrumIdentification[0]->spectrumIdentificationListPtr->spectrumIdentificationResult.size()
<< "\n";
}
return 0;
}
显然我不希望其他人能够编译这个,但无论如何我怀疑它是关于库的一些东西导致了 valgrind 所以更简单的测试用例是没有意义的。我知道 for 循环正在执行,因为我在 Valgrind 执行期间得到了 cout 输出。如何在不进一步简化的情况下调试它?
Even after introducing an intentional memory leak valgrind shows:
==13483== HEAP SUMMARY:
==13483== in use at exit: 0 bytes in 0 blocks
==13483== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==13483==
==13483== All heap blocks were freed -- no leaks are possible
The executable was compiled with G++ 4.1.2 and 4.6.2 with:
g++ -ftemplate-depth-128 -O0 -fno-inline -Wall -pedantic -g -pthread -Wno-long-long -Wno-uninitialized <snipped definitions and include directives from the build system>
I've tried with Valgrind 3.5.0 and 3.6.1 like:
valgrind --leak-check=full --undef-value-errors=no --show-reachable=yes <executable args>
Within the framework of the library I'm working on, I'm using a simple test case:
#include "pwiz/utility/misc/Std.hpp"
#include "pwiz/utility/misc/Filesystem.hpp"
#include "pwiz/data/identdata/IdentDataFile.hpp"
using namespace pwiz::cv;
using namespace pwiz::data;
using namespace pwiz::identdata;
using namespace pwiz::util;
int main(int argc, char** argv)
{
vector<string> args(argv+1, argv+argc);
BOOST_FOREACH(const bfs::path& filename, args)
{
// intentional memory leak
IdentDataFile* idp = new IdentDataFile(filename.string());
IdentDataFile& id = *idp;
cout << filename.string() << " "
<< id.analysisCollection.spectrumIdentification[0]->activityDate << " "
<< id.analysisCollection.spectrumIdentification[0]->spectrumIdentificationListPtr->spectrumIdentificationResult.size()
<< "\n";
}
return 0;
}
Obviously I don't expect others to be able to compile this, but anyway I suspect it's something about the library that's tripping up valgrind so a simpler test case would be pointless. And I know that the for loop is being executed because I get the cout output during Valgrind execution. How can I debug it without simplifying further?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它实际上归结为链接器选项。我使用 -static 进行编译,因此 valgrind 没有机会替换它自己的 malloc 实现。不幸的是 valgrind 至少没有警告这一点!
It boiled down to the linker options actually. I was compiling with -static, so valgrind did not have a chance to substitute its own malloc implementation. Unfortunate that valgrind doesn't at least warn about this though!