Dr.Memory介绍

2018-11-26  本文已影响0人  YW23

一、简介

Dr.Memory是一个内存错误检查工具,主要检查的内存错误有(uninitialized memory, accesses to unaddressable memory (including outside of allocated heap units and heap underflow and overflow), accesses to freed memory, double frees, memory leaks, and (on Windows) handle leaks)

Dr.Memory的论文Practical Memory Checking with Dr.Memory,发表在CGO-2011上(CCF-B)

Dr.Memory可以运行在多个平台上(Windows, Linux, Mac, or Android on commodity IA-32, AMD64, and ARM hardware)

二、安装

DrMemory-download中下载Dr.Memory的压缩包

Dr.Memory不需要编译安装,解压后在DrMemory-Linux-2.0.1-2/bin目录下有drmemory的可执行文件。

官网[1] 上说对于32位的程序,Dr. Memory能追踪和报告更多类型的内存错误。所以建议你最好能建立和运行32位应用程序。在64位的Ubuntu操作系统上,你可能会想安装这些额外的软件包:

sudo apt-get install g++-multilib

因此,如果想让Dr.Memory分析32位程序,可以在编译选项中使用-m32. 

并且,对于所有(32/64位)程序,在编译时都需要加上-g选项。

对于单个C/C++程序,即gcc/g++ -g -o myprog myprog.c

对于一个软件:./configure CFLAGS="-g" CXXFLAGS="-g" LDFLAGS="-g"

编译成32位程序: ./configure CFLGAS="-g -m32" CXXFLAGS="-g -m32"

三、使用

通用命令:

./DrMemory-Linux-2.0.1-2/bin/drmemory -brief --  myprog  arg1 arg2 [input]

比如对于二进制程序exiv2来说,

./DrMemory-Linux-2.0.1-2/bin/drmemory -brief --  /usr/local/bin/exiv2 -pv  input_1

屏幕上会打印出检查结果,并且会自动保存结果文本到改目录下: xx/DrMemory-Linux-2.0.1-2/drmemory/logs/DrMemory-exiv2.49297.000/results.txt

上图是对编译成64位的exiv2的测试结果,经测试,在本次实验中,32位和64位的程序的检测结果并无较大差别。(系统环境ubuntu 16.04 64位)

参考资料

[1] http://drmemory.org/chinese.html

上一篇下一篇

猜你喜欢

热点阅读