valgrind工具,在虛拟機上測試了幾個小程式,感覺不錯,于是決定編一個交叉valgrind出來,曆盡千辛萬苦,雖然解決了一些問題,但是還是沒有最終解決問題。
在這裡先将已經解決的問題的方法獻給大家。
問題1. 'optimize' attribute directive ignored
configure的過程這裡不再贅述。在make的時候遇到了如下錯誤,編譯停止不前,一直停留在這裡。
drd_clientreq.c:79: warning: 'optimize' attribute directive ignored
解決方法,修改drd目錄下的Makefile,将DRD_CFLAGS的優化選項由-O2改為-O1。
DRD_CFLAGS = \
--param inline-unit-growth=900 \
-O1 \
-Wextra \
-Wformat-nonliteral \
-Wno-inline \
-Wno-unused-parameter
問題2. valgrind: failed to start tool 'memcheck-mips-linux' for platform 'mips32-linux': No such file or directory
在解決了問題1後,編譯成功,make install之後,去安裝目錄下的bin目錄,将valgrind拷貝到目标機上。在運作#./vargrind ./memleak的時候,遇到了:
valgrind: failed to start tool 'memcheck-mips-linux' for platform 'mips32-linux': No such file or directory
于是去虛拟機的安裝目錄下的lib目錄,找到 lib/valgrind/memcheck-mips32-linux,上傳到目标機上。
再次執行,發現還是報相同的錯誤,幾經輾轉,才發現,你的memcheck-mips32-linux在目标機上的路徑必須和虛拟機上的完全一樣,否則valgrind就會找不到!!
再執行,剛才的錯誤應該沒有了,但是會接着報缺少 default.supp等,缺什麼就上傳什麼。
終于像在虛拟機上執行程式一樣,啪啪啪,列印出來一些結果,确發現,列印的結果不對!!!抓狂!!!
我的測試程式是:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
char *ptr;
ptr = (char *)malloc(10);
return 0;
}
在虛拟機上使用valgrind得到的結果是:
==8692== Memcheck, a memory error detector.
==8692== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==8692== Using LibVEX rev 1804, a library for dynamic binary translation.
==8692== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==8692== Using valgrind-3.3.0, a dynamic binary instrumentation framework.
==8692== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==8692== For more details, rerun with: -v
==8692==
==8692==
==8692== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 12 from 1)
==8692== malloc/free: in use at exit: 10 bytes in 1 blocks.
==8692== malloc/free: 1 allocs, 0 frees, 10 bytes allocated.
==8692== For counts of detected errors, rerun with: -v
==8692== searching for pointers to 1 not-freed blocks.
==8692== checked 48,384 bytes.
==8692==
==8692== LEAK SUMMARY:
==8692== definitely lost: 10 bytes in 1 blocks.
==8692== possibly lost: 0 bytes in 0 blocks.
==8692== still reachable: 0 bytes in 0 blocks.
==8692== suppressed: 0 bytes in 0 blocks.
==8692== Rerun with --leak-check=full to see details of leaked memory.而在目标機上得到的結果是:
==11667== Memcheck, a memory error detector
==11667== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==11667== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==11667== Command: ./memleak
==11667==
==11667== Conditional jump or move depends on uninitialised value(s)
==11667== at 0x37447280: ??? (in /lib/ld-2.5.so)
==11667== by 0x37436F00: ??? (in /lib/ld-2.5.so)
==11667==
==11667== Conditional jump or move depends on uninitialised value(s)
==11667== at 0x3743B870: ??? (in /lib/ld-2.5.so)
==11667== by 0x3743B75C: ??? (in /lib/ld-2.5.so)
==11667==
==11667== Conditional jump or move depends on uninitialised value(s)
==11667== at 0x3743BF94: ??? (in /lib/ld-2.5.so)
==11667== by 0x3743B75C: ??? (in /lib/ld-2.5.so)
==11667==
==11667== Conditional jump or move depends on uninitialised value(s)
==11667== at 0x3743B870: ??? (in /lib/ld-2.5.so)
==11667== by 0x3743B4E8: ??? (in /lib/ld-2.5.so)
==11667==
==11667== Conditional jump or move depends on uninitialised value(s)
==11667== at 0x3743BF94: ??? (in /lib/ld-2.5.so)
==11667== by 0x3743B4E8: ??? (in /lib/ld-2.5.so)
==11667==
==11667== Invalid write of size 4
==11667== at 0x374308E8: ??? (in /lib/ld-2.5.so)
==11667== by 0x3743087C: ??? (in /lib/ld-2.5.so)
==11667== Address 0x7ee6ae1c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==11667==
==11667==
==11667== HEAP SUMMARY:
==11667== in use at exit: 0 bytes in 0 blocks
==11667== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==11667==
==11667== All heap blocks were freed -- no leaks are possible
==11667==
==11667== For counts of detected and suppressed errors, rerun with: -v
==11667== Use --track-origins=yes to see where uninitialised values come from
==11667== ERROR SUMMARY: 10 errors from 6 contexts (suppressed: 0 from 0)對于目标機上的錯誤,還不知道具體是什麼原因,估計是哪個庫檔案不太比對之類的吧。
valgrind: failed to start tool 'memcheck' for platform 'arm-linux': No such file or directory