valgrind linuxプログラムメモリ漏洩検出

5556 ワード

1.Valgrind Homeで最新バージョンをダウンロードできます.
2.解凍後、READMEファイルを開き、ソフトウェアのインストール方法を確認する.configure make make installの3つのステップ.
3.正しくインストールされているかどうかを確認します.
1 valgrind ls -l

インストール中に次のエラーが発生しました.
 1 # valgrind ls -l

 2 ==13544== Memcheck, a memory error detector

 3 ==13544== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.

 4 ==13544== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info

 5 ==13544== Command: ls -l

 6 ==13544== 

 7 

 8 valgrind:  Fatal error at startup: a function redirection

 9 valgrind:  which is mandatory for this platform-tool combination

10 valgrind:  cannot be set up.  Details of the redirection are:

11 valgrind:  

12 valgrind:  A must-be-redirected function

13 valgrind:  whose name matches the pattern:      strlen

14 valgrind:  in an object with soname matching:   ld-linux.so.2

15 valgrind:  was not found whilst processing

16 valgrind:  symbols from the object with soname: ld-linux.so.2

17 valgrind:  

18 valgrind:  Possible fixes: (1, short term): install glibc's debuginfo

19 valgrind:  package on this machine.  (2, longer term): ask the packagers

20 valgrind:  for your Linux distribution to please in future ship a non-

21 valgrind:  stripped ld.so (or whatever the dynamic linker .so is called)

22 valgrind:  that exports the above-named function using the standard

23 valgrind:  calling conventions for this platform.  The package you need

24 valgrind:  to install for fix (1) is called

25 valgrind:  

26 valgrind:    On Debian, Ubuntu:                 libc6-dbg

27 valgrind:    On SuSE, openSuSE, Fedora, RHEL:   glibc-debuginfo

28 valgrind:  

29 valgrind:  Cannot continue -- exiting now.  Sorry.

以上のエラーは、ubuntuにライブラリが必要であるためです.
1 sudo apt-get install libc6-dbg

このライブラリのインストールが完了したらvalgrind ls-lを再実行します
4.使用方法:
1 valgrind --tool=memcheck --leak-check=full ./main