valgrind工具介绍

一、简介

Valgrind是一个二进制插桩框架,可以用来制作二进制分析工具。利用Valgrind可以检测二进制程序的内存和线程漏洞。Valgrind框架目前包含以下几种工具:

Memcheck is a memory error detector. It helps you make your programs, particularly those written in C and C++, more correct.

Cachegrind is a cache and branch-prediction profiler. It helps you make your programs run faster.

Callgrind is a call-graph generating cache profiler. It has some overlap with Cachegrind, but also gathers some information that Cachegrind does not.

Helgrind is a thread error detector. It helps you make your multi-threaded programs more correct.

DRD is also a thread error detector. It is similar to Helgrind but uses different analysis techniques and so may find different problems.

Massif is a heap profiler. It helps you make your programs use less memory.

DHAT is a different kind of heap profiler. It helps you understand issues of block lifetimes, block utilisation, and layout inefficiencies.

SGcheck is an experimental tool that can detect overruns of stack and global arrays. Its functionality is complementary to that of Memcheck: SGcheck finds problems that Memcheck can't, and vice versa..

BBV is an experimental SimPoint basic block vector generator. It is useful to people doing computer architecture research and development.


二、安装valgrind

valgrind官网上下载源码,解压后依次执行

./configure

make

sudo make install

输入valgrind -h查看是否安装成功


三、使用

valgrind的默认命令结构为:

valgrind [valgrind-options] your-prog [your prog options]

对C/C++程序,采用-g 编译选项进行编译得到二进制程序myprog

一般使用下面命令来运行程序myprog:

valgrind --tool=memcheck  --leak-check=yes myprog arg1 arg2 

默认使用的是Memcheck工具,如果要使用别的工具可以在--tool 选项中设置,  --leak-check选项默认打开memory leak detector

--toool=<toolname>

toolname 可以为:memcheck, cachegrind, callgrind, helgrind, drd, massif, lackey, none, exp-sgcheck, exp-bbv, exp-dhat, etc.

如果目标是检查程序漏洞,则常使用的tool为:memcheck (内存错误), helgrind, drd(线程错误)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 有人说:生活如一团乱麻。 也有人说:生命如歌。 生活与生命,难道不是一件事吗?没有了生命,哪来的生活?没有了生活,...
    爱的花园阅读 746评论 0 4
  • 没翻开的人间词话 塞满了的烟灰缸 乱划下的铅笔灵感 发了霉的饼干 我躺在床上 用中了彩票的梦麻醉入眠。 关灯吧,清...
    不在楼上阅读 205评论 1 0
  • 说过很多话,没刻意去记得什么,也就差不多都忘记了。一些应该记得或者不想忘记的事情,自然而然的会留下来。 很羡慕世界...
    加七儿阅读 299评论 0 0
  • 类似微软visio的功能,可以做一些思维导图之类的;还可以做Business, UML等等,很方便好用。 http...
    小双2510阅读 1,940评论 0 0
  • 作者:逗逗 原创作品,抄袭搬运必究。 01. 有一次,我和我对象吵架,我们各自坐在一边谁也不理谁。 过了一会,我的...
    遇见逗逗阅读 503评论 0 0