Ubuntu12.04下使用valgrind内存测试工具测试Qt程序

时间:2024-03-25 16:35:08

1. 到官网http://valgrind.org/downloads/上下载valgrind最新版本;

2. 解压源码,执行./configure;make;make install后,默认安装到/usr/local/bin下,执行:

valgrind ls -l

3. 提示:

==== Memcheck, a memory error detector
==== Copyright (C) -, and GNU GPL'd, by Julian Seward et al.
==== Using Valgrind-3.7. and LibVEX; rerun with -h for copyright info
==== Command: ls -l
==== valgrind: Fatal error at startup: a function redirection
valgrind: which is mandatory for this platform-tool combination
valgrind: cannot be set up. Details of the redirection are:
valgrind:
valgrind: A must-be-redirected function
valgrind: whose name matches the pattern: strlen
valgrind: in an object with soname matching: ld-linux-x86-.so.
valgrind: was not found whilst processing
valgrind: symbols from the object with soname: ld-linux-x86-.so.
valgrind:
valgrind: Possible fixes: (, short term): install glibc's debuginfo
valgrind: package on this machine. (, longer term): ask the packagers
valgrind: for your Linux distribution to please in future ship a non-
valgrind: stripped ld.so (or whatever the dynamic linker .so is called)
valgrind: that exports the above-named function using the standard
valgrind: calling conventions for this platform. The package you need
valgrind: to install for fix () is called
valgrind:
valgrind: On Debian, Ubuntu: libc6-dbg
valgrind: On SuSE, openSuSE, Fedora, RHEL: glibc-debuginfo
valgrind:
valgrind: Cannot continue -- exiting now. Sorry.

大概是说我的glibc是个strip后的版本,需要下载debug版,debug版的名字是libc6-dbg。

执行:

sudo apt-get install libc6-dbg

4. 再次执行valgrind ls -l,输出:

==== Memcheck, a memory error detector
==== Copyright (C) -, and GNU GPL'd, by Julian Seward et al.
==== Using Valgrind-3.7. and LibVEX; rerun with -h for copyright info
==== Command: ls -l
====
total
drwxr-xr-x root root -- : bin
drwxr-xr-x root root -- : boot
drwxr-xr-x root root -- : cdrom
drwxr-xr-x root root -- : dev
drwxr-xr-x root root -- : etc
drwxr-xr-x root root -- : home
lrwxrwxrwx root root -- : initrd.img -> boot/initrd.img-2.6.--generic
drwxr-xr-x root root -- : lib
drwxr-xr-x root root -- : lib32
lrwxrwxrwx root root -- : lib64 -> /lib
drwx------ root root -- : lost+found
drwxr-xr-x root root -- : media
drwxr-xr-x root root -- : mnt
drwxr-xr-x root root -- : opt
dr-xr-xr-x root root -- : proc
drwx------ root root -- : root
drwxr-xr-x root root -- : sbin
drwxr-xr-x root root -- : selinux
drwxr-xr-x root root -- : srv
drwxr-xr-x root root -- : sys
drwxrwxrwx root root -- : tftpboot
drwxrwxrwt root root -- : tmp
drwxr-xr-x root root -- : usr
drwxr-xr-x root root -- : var
lrwxrwxrwx root root -- : vmlinuz -> boot/vmlinuz-2.6.--generic
drwxrwxrwx root root -- : work
====
==== HEAP SUMMARY:
==== in use at exit: , bytes in blocks
==== total heap usage: , allocs, , frees, , bytes allocated
====
==== LEAK SUMMARY:
==== definitely lost: bytes in blocks
==== indirectly lost: bytes in blocks
==== possibly lost: bytes in blocks
==== still reachable: , bytes in blocks
==== suppressed: bytes in blocks
==== Rerun with --leak-check=full to see details of leaked memory
====
==== For counts of detected and suppressed errors, rerun with: -v
==== ERROR SUMMARY: errors from contexts (suppressed: from )

看来ls这个命令是没有任何内存问题的。。。