Linux使用valgrind來檢測程式的記憶體流失

來源:互聯網
上載者:User

1.到http://valgrind.org/下載最新版本的valgrind

2.加壓後,可以查看README檔案,參照readme的指示進行如下的操作:

  1). Run ./configure, with some options if you wish.  The only interesting
     one is the usual --prefix=/where/you/want/it/installed.

  2). Run "make".

  3). Run "make install", possibly as root if the destination permissions
     require that.  --- Ubuntu下需要root許可權,即應該這樣運行: sudo make install

  4). See if it works.  Try "valgrind ls -l".  Either this works, or it
     bombs out with some complaint.  In that case, please let us know
     (see www.valgrind.org).

可能會出現以下的錯誤:

valgrind:  Fatal error at startup: a function redirectionvalgrind:  which is mandatory for this platform-tool combinationvalgrind:  cannot be set up.  Details of the redirection are:valgrind:  valgrind:  A must-be-redirected functionvalgrind:  whose name matches the pattern:      indexvalgrind:  in an object with soname matching:   ld-linux.so.2valgrind:  was not found whilst processingvalgrind:  symbols from the object with soname: ld-linux.so.2valgrind:  valgrind:  Possible fixes: (1, short term): install glibc's debuginfovalgrind:  package on this machine.  (2, longer term): ask the packagersvalgrind:  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 standardvalgrind:  calling conventions for this platform.  The package you needvalgrind:  to install for fix (1) is calledvalgrind:  valgrind:    On Debian, Ubuntu:                 libc6-dbgvalgrind:    On SuSE, openSuSE, Fedora, RHEL:   glibc-debuginfovalgrind:  valgrind:  Cannot continue -- exiting now.  Sorry.

 以上錯誤,是因為在Ubuntu下還需要一個LIB:libc6-dbg

運行:sudo apt-get install libc6-dbg 以安裝libc6-dbg

然後再次運行: valgrind ls -l

 

使用的時候,可以按照如下的方式使用:

valgrind --tool=memcheck --leak-check=full ./hellworld

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.