我们在Linux虚拟机上运行我们的程序,该虚拟机从linux-2.6.3长期编译。我想在那台机器上运行valgrind
,并按建议的方式从源代码编译。
./configure --prefix=/tmp/valgrind/
make
make install
然后,我将/tmp/valgrind
复制到我自己的Linux机器上,我把它放在目录/data
上,设置环境变量:
export PATH=$PATH:/data/valgrind/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib:/lib64:/data/valgrind/lib
export VALGRIND_LIB=/data/valgrind/lib/valgrind
valgrind
可以工作,并且可以检测除内存泄漏之外的其他一些错误。以下是运行valgrind ls -l
==2207==
==2207== Conditional jump or move depends on uninitialised value(s)
==2207== at 0x80F3CDE: ??? (in /bin/busybox)
==2207== by 0x80548ED: ??? (in /bin/busybox)
==2207==
==2207== Use of uninitialised value of size 4
==2207== at 0x80D8F77: ??? (in /bin/busybox)
==2207== by 0x8048866: ??? (in /bin/busybox)
==2207==
==2207== Conditional jump or move depends on uninitialised value(s)
==2207== at 0x80F0F55: ??? (in /bin/busybox)
==2207== by 0x80D8F49: ??? (in /bin/busybox)
==2207== by 0x8048866: ??? (in /bin/busybox)
==2207==
==2207== Conditional jump or move depends on uninitialised value(s)
==2207== at 0x80F1000: ??? (in /bin/busybox)
==2207== by 0x80D8F49: ??? (in /bin/busybox)
==2207== by 0x8048866: ??? (in /bin/busybox)
==2207==
==2207==
==2207== HEAP SUMMARY:
==2207== in use at exit: 0 bytes in 0 blocks
==2207== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==2207==
==2207== All heap blocks were freed -- no leaks are possible
==2207==
==2207== For counts of detected and suppressed errors, rerun with: -v
==2207== Use --track-origins=yes to see where uninitialised values come from
==2207== ERROR SUMMARY: 2390 errors from 117 contexts (suppressed: 0 from 0)
总堆使用率全为零。我发现有人已经遇到同样的问题: cross-compiled Valgrind does not detect obvious leaks 这是一个已知的问题吗? 上面的链接没有说明如何解决它,任何人都知道吗?