Memory debugger with ptrace

梦想与她 提交于 2019-12-13 02:49:37

问题


I would like to expand an existing tool with the functionality of a memory debugger (just leak detection).

I know that some memory debuggers work by replacing malloc/free and keeping track of what is pending to be freed and who allocated it; or by running the process on sort of a virtual machine and monitoring memory accesses.

I want to know if it makes sense to use ptrace() to set breakpoints on malloc/free, instead rebuilding with dmalloc for example, and monitoring allocations in a separate process. Would it be too slow? Does any other tool work this way?


回答1:


It is not practical to use a debugger and trap malloc/free calls for a few of reasons:

  1. The overhead of switching from one process to the other one is just to great on nontrivial programs.

  2. You'll end up spending a similar amount of memory to store ownership information than with other methods. (This is what I actually wanted to improve)

  3. There are quite a few functions that work the heap, and it could be easy to miss some.



来源:https://stackoverflow.com/questions/13572089/memory-debugger-with-ptrace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!