首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >valgrind memcheck是否支持检查mmap

valgrind memcheck是否支持检查mmap
EN

Stack Overflow用户
提问于 2013-03-11 16:37:31
回答 2查看 2.4K关注 0票数 7

我正在尝试valgrind来检测内存泄漏。它可以很好地处理堆泄漏(即从malloc或new分配内存)。但是,它是否支持linux中的检查mmap泄漏?

谢谢常

EN

回答 2

Stack Overflow用户

发布于 2013-03-11 17:34:40

不是直接的,它很难调试,看看valgrind.h

代码语言:javascript
运行
复制
   VALGRIND_MALLOCLIKE_BLOCK should be put immediately after the point where a
   heap block -- that will be used by the client program -- is allocated.
   It's best to put it at the outermost level of the allocator if possible;
   for example, if you have a function my_alloc() which calls
   internal_alloc(), and the client request is put inside internal_alloc(),
   stack traces relating to the heap block will contain entries for both
   my_alloc() and internal_alloc(), which is probably not what you want.

   For Memcheck users: if you use VALGRIND_MALLOCLIKE_BLOCK to carve out
   custom blocks from within a heap block, B, that has been allocated with
   malloc/calloc/new/etc, then block B will be *ignored* during leak-checking
   -- the custom blocks will take precedence.

   VALGRIND_FREELIKE_BLOCK is the partner to VALGRIND_MALLOCLIKE_BLOCK.  For
   Memcheck, it does two things:

   - It records that the block has been deallocated.  This assumes that the
     block was annotated as having been allocated via
     VALGRIND_MALLOCLIKE_BLOCK.  Otherwise, an error will be issued.

   - It marks the block as being unaddressable.

   VALGRIND_FREELIKE_BLOCK should be put immediately after the point where a
   heap block is deallocated.
票数 6
EN

Stack Overflow用户

发布于 2018-12-31 15:23:13

遗憾的是,valgrind的memcheck不支持mmap跟踪(至少不是现成的),但还是有希望的。

我最近遇到了mmap mmap,这是一个用于跟踪内存访问和分配的valgrind分支:https://nouveau.freedesktop.org/wiki/Valgrind-mmt

它是由envytools开发的,似乎主要用于图形驱动程序的开发。

mmap跟踪工具mmt对所有对mmap内存的访问进行深度跟踪,包括加载和存储。对于查找泄漏的mmap内存的工作来说,这可能太多了,并且需要对工具的输出进行处理和分析,但是通过一些仔细的工作,它可能对检测mmap泄漏情况很有用。就我个人而言,我使用它只取得了部分成功,但也许其他人会更幸运。

请注意,它可能不适用于anonymous mmap allocations

入门指南:

使用以下参数克隆并构建envytools/envytools repository

  • Run

/usr/local/bin/valgrind --tool=mmt --mmt-trace-file=[mmapped-file-to-be-traced] --log-file=mmt-log.bin

  • Decode mmt输出:demmt -l mmt-log.bin > mmt-log.txt
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15334191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档