如何在Snow Leopard上编译Valgrind?
我最近养成了运行所有程序valgrind来检查内存泄漏的习惯,但是大部分结果对我来说都有点神秘.
对于我的最新运行,valgrind -v给了我:
All heap blocks were freed -- no leaks are possible
Run Code Online (Sandbox Code Playgroud)
这意味着我的程序被内存泄漏所覆盖,对吗?
那么这个错误意味着什么?我的程序没有正确读取某些内存块吗?
ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 14 from 9)
1 errors in context 1 of 1:
Invalid read of size 4
at 0x804885B: findPos (in /home/a.out)
by 0xADD918: start_thread (pthread_create.c:301)
by 0xA26CCD: clone (clone.S:133)
Address 0x4a27108 is 0 bytes after a block of size 40 alloc'd
at 0x4005BDC: malloc (vg_replace_malloc.c:195)
by 0x804892F: readInput (in /home/a.out)
by 0xADD918: …Run Code Online (Sandbox Code Playgroud) 我试图理解程序的性能如何在使用不同选项运行时发生变化 - 我的因子为1.8我想解释一下.我一直在用[valgrind]的callgrind工具进行分析,并使用kcachegrind来显示结果.但我真的很想看看差异.我找到了该cg_diff程序,但它不能与callgrind配置文件一起使用,只能使用cachegrind配置文件,这对我来说太昂贵了.
有没有人知道用于可视化两个配置文件之间差异的工具?
我正在使用XCode 4.2.1中的Instruments来查找一些内存泄漏.我发现了一个非常奇怪的(至少对我而言)内存泄漏:(该函数values_table_get_value返回一个double,并且output = stdout)

这两个问题是:它是真正的内存泄漏吗?我该如何清理它?(fprintf格式%.3f错了double?
为了表明泄漏是在fprintf中,我将函数的返回值更改为5.0:

并将返回值移动到临时变量:

更确切地说,这是一张asm代码的图片,显示泄漏是:

我做了一个非常简单的测试:使用sprintf+ 打印fprintf,但是我在sprintf上得到了泄漏:

我也尝试printf直接使用,我得到它的泄漏.
我真的认为问题在于格式.
最后的尝试,表明没有任何与我的功能相关的东西:

只是为了检查,我用valgrind执行:( values_table_print是函数名)
valgrind --leak-check=full --show-reachable=yes ./leastsquares

我的软件版本:valgrind --version:valgrind-3.7.0 gcc --version i686-apple-darwin11-llvm-gcc-4.2(GCC)4.2.1(基于Apple Inc. build 5658)(LLVM build 2336.1.00 )
我有一个声明如此的方法:
/*!
\brief Removes the leading and trailing white space from a string.
\param s The string to remove the white space from.
\param white_chars Characters to be considered as whitespace.
*/
std::string Trim(const std::string &s, const std::string &white_chars = " \t\n\r");
Run Code Online (Sandbox Code Playgroud)
该方法的定义是无趣的,但无论如何它在这里:
std::string Trim(const std::string &s, const std::string &white_chars)
{
size_t startidx = s.find_first_not_of(white_chars);
if (startidx == std::string::npos) return "";
size_t endidx = s.find_last_not_of(white_chars);
return s.substr(startidx, endidx - startidx + 1);
}
Run Code Online (Sandbox Code Playgroud)
现在在这种方法的大多数用法中,我只提供了第一个参数.Valgrind给了我以下警告
==3338== 68 bytes in 2 blocks …Run Code Online (Sandbox Code Playgroud) 谁能告诉我如何对kcachegrind的结果感兴趣.
我有两个版本的代码(v1,v2)都在调试模式下编译.我通过valgrind用选项运行它们:
valgrind --tool=callgrind -v ....
这样生成的输出文件在kcachegrind中打开.现在我已经发现代码的版本v2运行速度比第一版v1更快,因为它意味着.但是我如何从kcachegrind的调用图中获得结果.
在kcachegrind All Callers选项卡中,我有以下列:Incl. , Distance, Called, Caller.
IIUC,Called并且caller在计划中没有被称为"来电者".但我不了解其他人.
另一件事是在选择特定功能然后在"呼叫者"选项卡上显示更多信息.Ir, Ir per call, count, caller
在类型选项卡中:`EventType,Incl.自我,简短,公式.
我在这里没有任何想法.
到目前为止,我读过这些问题:
我可能会遗漏某些东西或者可能没有,但是setrlimit当在valgrind下运行时,函数会一直失败
int main()
{
const struct rlimit file_limits = { .rlim_cur = 65536, .rlim_max = 65536 };
if ( setrlimit( RLIMIT_NOFILE, &file_limits ) )
{
printf(" Failed %d", errno );
perror(" More " );
}
else
{
printf(" Success ");
}
printf("\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
正常运行
sh-4.2# ulimit -H -n
800000
sh-4.2# ulimit -S -n
500000
sh-4.2# ./rlimit
Success
sh-4.2#
Run Code Online (Sandbox Code Playgroud)
在valgrind
sh-4.2#
sh-4.2# valgrind ./rlimit
==28974== Memcheck, a memory error detector
==28974== Copyright (C) 2002-2015, and GNU …Run Code Online (Sandbox Code Playgroud) 有没有人知道Android NDK下的本机C++代码的内存调试工具(如Valgrind)?
我在Valgrind得到这个.
--24101-- REDIR: 0xbb20580 (operator delete(void*)) redirected to 0x93b7d48 (operator delete(void*))
--24101-- REDIR: 0xbb22580 (operator new[](unsigned long)) redirected to 0x93b88b7 (operator new[](unsigned long))
==24101== WARNING: new redirection conflicts with existing -- ignoring it
--24101-- new: 0x15632010 (__GI_strlen ) R-> 0x093b96b0 strlen
--24101-- REDIR: 0xbb205c0 (operator delete[](void*)) redirected to 0x93b79c4 (operator delete[](void*))
Run Code Online (Sandbox Code Playgroud)
有什么顾虑吗?
我很惊讶我找不到任何文件说明Valgrind 工具的输出_int_malloc和malloc输出之间的区别callgrind.
有人可以解释一下他们的区别吗?
此外,我实际上编写C++代码,所以我完全new不使用malloc,但在callgrind输出中只显示mallocs.
valgrind ×10
c++ ×4
c ×3
callgrind ×2
kcachegrind ×2
linux ×2
memory-leaks ×2
profiling ×2
android-ndk ×1
centos ×1
instruments ×1
macos ×1
malloc ×1
stdstring ×1
xcode ×1