Does valgrind memcheck support checking mmap

后端 未结 2 826
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 05:48

I am trying valgrind for detecting memory leak. It works well on heap leak(i.e. memory allocation from malloc or new). however, does it support check mmap leaking in linux?<

2条回答
  •  臣服心动
    2021-01-05 06:29

    Sadly, valgrind's memcheck doesn't support mmap tracking (at least not out of the box), but there's hope.

    I've recently came across valgrind-mmt, a valgrind fork for tracing mmap memory accesses and allocations: https://nouveau.freedesktop.org/wiki/Valgrind-mmt

    It is developed by envytools, and seems to be used mostly for graphic drivers developement.

    The mmap tracing tool, mmt, does deep tracing on all access to mmapped memory, including loads and stores. This may be too much for the job of finding leaking mmap memory, and the output of the tool needs be processed and analyzed, but with some careful work it may be useful for detecting mmap leak scenarios. Personally, I've had only partial success using it, but perhaps others will be more lucky.

    Note that, it may not be suitable for anonymous mmap allocations.


    For getting started:

    • Clone and build the envytools/envytools repository
    • Clone and build the envytools/valgrind repository
    • Run valgrind with the following parameters:

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

    • Decode mmt output: demmt -l mmt-log.bin > mmt-log.txt

提交回复
热议问题