如何转储(在 Windows 中)DLL 使用的内存空间?
我可以使用各种工具轻松转储进程的整个内存空间。
但是是否可以仅转储某个进程加载的 DLL 使用的内存空间?我应该使用什么工具?
谢谢,
吉姆
I can readily dump the entire memory space of a process using various tools.
But is it possible to dump just the memory space used by a DLL loaded by some process? What tools should I use?
Thanks,
Jim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能是指查看 DLL 中的代码分配的内存。
我认为这是不可能的。如果DLL分配内存,并且DLL是用C++编写的,并且C/C++运行时是动态链接的(即作为DLL),那么它将使用与主应用程序相同的C/C++运行时,并且所有分配的DLL内存将分配在同一个堆上。
即使 DLL 具有静态链接的 C/C++ 运行时,或者 DLL 是用不同的语言编写的,它也可能会使用相同的默认 Windows 堆。
如果您自己可以控制 DLL,您可以尝试为您的 DLL 实现自定义内存管理器(在 C++ 中,这意味着重写 new 和 delete,总共 6 个全局运算符),尝试使用不同的(即非默认的)Windows堆,然后使用低级 Windows 调试器 WinDbg 的 heapwalk 方法,但要让这一切正常工作将是相当困难的。或者您的 DLL 的自定义内存管理器可以使用 VirtualAlloc 在固定地址分配内存(或非固定地址,然后记录虚拟地址)。然后你可以在正常的进程内存转储中查看这个地址空间。
You probably mean looking at the memory allocated by code in the DLL.
I think this is impossible. If the DLL allocates memory, and the DLL is written in C++, and the C/C++ Run Time is dynamically linked (i.e. as DLL), then it will use the same C/C++ Run Time as the main application, and all DLL's allocated memory will be allocated on the same heap.
Even if the DLL would have the C/C++ Run Time statically linked, or the DLL is written in a different language, it will probably use the same default Windows heap.
If you have control over the DLL yourself, you could try to implement a custom memory manager for your DLL (in C++ this means overriding new and delete, 6 global operators in total), try to use a different (i.e. non-default) Windows heap, and then using the heapwalk methods of the low-level Windows debugger WinDbg, but it will be quite difficult to get this all working. Or your DLL's custom memory manager could allocate memory at a fixed address using VirtualAlloc (or non-fixed, and then logging the virtual address). Then you can look at this address space in the normal process memory dump.