下载最新版本Valgrind 3.7.0,解压缩后创建一个文件夹“Valgrind-3.7.0” 现在,我所做的是导出gcc以与目标机器兼容,并配置为禁用tls并给予主机。 我还制作了一个C程序“leak.c”,并使用以下命令
编译了它的目标文件“a.out”export CC=/usr/local/netd_tools_v1/powerpc/bin/powerpc-linux-gnu-gcc leak.c
所以
a. export CC=/usr/local/netd_tools_v1/powerpc/bin/powerpc-linux-gnu-gcc
b. ./configure --prefix=/netd --host=powerpc-linux --disable-tls
c. make
d. make install
(/ netd / lib和/ netd / usr / sbin是项目特定目录)
将这些文件(“netd”中的文件)复制到目标计算机,并通过以下命令在文件“a.out”上运行Valgrind:
valgrind --log-file=/u/july5.txt --leak-check=summary --tool=memcheck ./a.out
(/u
是挂载点,july5
是日志文件)
输出显示0报告泄漏
int main()
{
printf("I am leaking.");
int *a =(int *) malloc(100);
return 0;
}
这在linux上运行得很好并且报告了内存泄漏。 如果这可行,那么我会在项目特定流程上运行Valgrind。
在LINUX上为a.out输出日志文件:
[asaini@OTN05 abhaysaini]$ vi xyz.txt
==14843== Memcheck, a memory error detector
==14843== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==14843== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==14843== Command: ./a.out
==14843== Parent PID: 51
61
==14843==
==14843==
==14843== HEAP SUMMARY:
==14843== in use at exit: 100 bytes in 1 blocks
==14843== total heap usage: 1 allocs, 0 frees, 100 bytes allocated
==14843==
==14843== LEAK SUMMARY:
==14843== definitely lost: 100 bytes in 1 blocks
==14843== indirectly lost: 0 bytes in 0 blocks
==14843== possibly lost: 0 bytes in 0 blocks
==14843== still reachable: 0 bytes in 0 blocks
==14843== suppressed: 0 bytes in 0 blocks
==14843== Rerun with --leak-check=full to see details of leaked memory
==14843==
==14843== For counts of detected and suppressed errors, rerun with: -v
==14843== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 11 from 6)
PowerPc上的日志文件输出
[00002003-Unknown] Debug> cat leak.txt
==1208== Memcheck, a memory error detector
==1208== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==1208== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==1208== Command: ./a.out
==1208== Parent PID: 1195
==1208==
--1208-- WARNING: Serious error when reading debug info
--1208-- When reading debug info from /lib/ld-2.3.2.so:
--1208-- Can't make sense of .data section mapping
--1208-- WARNING: Serious error when reading debug info
--1208-- When reading debug info from /u/Leak/a.out:
--1208-- Can't make sense of .data section mapping
--1208-- WARNING: Serious error when reading debug info
--1208-- When reading debug info from /u/netd/lib/valgrind/vgpreload_core-ppc32-linux.so:
--1208-- Can't make sense of .eh_frame section mapping
==1208== Use of uninitialised value of size 4
==1208== at 0x4011E08: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x4016517: ???
==1208== by 0x400917F: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x4005083: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x4006967: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x4002C0F: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x400DF03: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x4001BD3: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x400215F: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x400EF2B: ??? (in /lib/ld-2.3.2.so)
==1208==
--1208-- WARNING: Serious error when reading debug info
--1208-- When reading debug info from /u/netd/lib/valgrind/vgpreload_memcheck-ppc32-linux.so:
--1208-- Can't make sense of .eh_frame section mapping
--1208-- WARNING: Serious error when reading debug info
--1208-- When reading debug info from /lib/libc-2.3.2.so:
--1208-- Can't make sense of .data section mapping
==1208== Use of uninitialised value of size 4
==1208== at 0x4011CC0: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x7: ???
==1208== by 0x400AB33: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x4002ECB: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x400DF03: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x4001BD3: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x400215F: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x400EF2B: ??? (in /lib/ld-2.3.2.so)
==1208==
==1208== Use of uninitialised value of size 4
==1208== at 0x4011D38: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x7: ???
==1208== by 0x400AB33: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x4002ECB: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x400DF03: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x4001BD3: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x400215F: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x400EF2B: ??? (in /lib/ld-2.3.2.so)
==1208==
==1208== Use of uninitialised value of size 4
==1208== at 0x4011D64: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x7: ???
==1208== by 0x400AB33: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x4002ECB: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x400DF03: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x4001BD3: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x400215F: ??? (in /lib/ld-2.3.2.so)
==1208== by 0x400EF2B: ??? (in /lib/ld-2.3.2.so)
==1208==
==1208== Use of uninitialised value of size 4
==1208== at 0x400B958: ??? (in /lib/ld-2.3.2.so)
==1208== by 0xFE8ABE7: ??? (in /lib/libc-2.3.2.so)
==1208== by 0xFE7278B: ??? (in /lib/libc-2.3.2.so)
==1208==
... snip ...
==1208==
==1208== Use of uninitialised value of size 4
==1208== at 0x400BBE0: ??? (in /lib/ld-2.3.2.so)
==1208== by 0xFE8ABE7: ??? (in /lib/libc-2.3.2.so)
==1208== by 0xFE7278B: ??? (in /lib/libc-2.3.2.so)
==1208==
==1208== Use of uninitialised value of size 4
==1208== at 0x400BB0C: ??? (in /lib/ld-2.3.2.so)
==1208== by 0xFE8ABE7: ??? (in /lib/libc-2.3.2.so)
==1208== by 0xFE7278B: ??? (in /lib/libc-2.3.2.so)
==1208==
==1208==
==1208== HEAP SUMMARY:
==1208== in use at exit: 0 bytes in 0 blocks
==1208== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==1208==
==1208== All heap blocks were freed -- no leaks are possible
==1208==
==1208== For counts of detected and suppressed errors, rerun with: -v
==1208== Use --track-origins=yes to see where uninitialised values come from
==1208== ERROR SUMMARY: 40 errors from 20 contexts (suppressed: 3908 from 442)
错误(在链接https://bugs.kde.org/show_bug.cgi?id=290066中尝试修补程序后:(通过iWerner)
[00002003-Unknown] Debug> cat 1.txt
==1134== Memcheck, a memory error detector
==1134== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==1134== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==1134== Command: ./Leak/a.out
==1134== Parent PID: 1071
==1134==
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.so.1
valgrind: was not found whilst processing
valgrind: symbols from the object with soname: ld.so.1
valgrind:
valgrind: Possible fixes: (1, short term): install glibc's debuginfo
valgrind: package on this machine. (2, 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 (1) is called
valgrind:
valgrind: On Debian, Ubuntu: libc6-dbg
valgrind: On SuSE, openSuSE, Fedora, RHEL: glibc-debuginfo
valgrind:
valgrind: Cannot continue -- exiting now. Sorry.