查找内存最后被释放的位置?
非常笼统: 当发生访问冲突时,是否有一种简单的方法可以判断哪一行代码最后释放了内存块?
不那么笼统: 我对探查器的理解是它们会覆盖分配和释放过程。 如果这是真的,他们是否会碰巧存储最后释放一段内存的代码行,以便当它稍后因访问冲突而崩溃时,您知道最后释放它的是什么?
具体: Windows、ANSI C、使用 Visual Studio
Very general:
Is there an easy way to tell which line of code last freed a block of memory when an access violation occurs?
Less general:
My understanding of profilers is that they override the allocation and deallocation processes. If this is true, might they happen to store the line of code that last freed a section of memory so that when it later crashes because of an access violation, you know what freed it last?
Specifics:
Windows, ANSI C, using Visual Studio
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,除非您提供自己的分配器(例如通过重载 new/delete)来存储此信息。
分析器所做的事情很大程度上取决于他们分析的内容。 我不知道有任何分析器可以跟踪您正在寻找的内容。
也许如果您提供有关您的情况的更多详细信息,人们可能会建议一种诊断您遇到的问题的替代方法。
No, not unless you provide your own allocators (e.g. by overloading new/delete) to store this information.
What profilers do is highly dependent on what they're profiling. I'm not aware of any profiler that tracks what you're looking for.
Perhaps if you provided more details on your situation people could suggest an alternative means of diagnosing the problem you're encountering.
是的!
安装Windows 调试工具并使用应用程序验证程序。
现在,当您发生崩溃时,您将在调试器中从 AppVerifier 获得更多信息。 使用!avrf(可能需要很长时间才能运行(分钟)),它会尝试为您提供尽可能多的有用信息。
您都可以在内存地址上使用 dps 命令来获取所有存储的堆栈信息(分配、释放等)。
您还可以在内存地址上使用 !heap 命令:
这也会转储信息。
进一步阅读:
Yes!
Install the Windows Debugging Tools and use Application Verifier.
Now when you make the crash happen, you will get additional information in the debugger from AppVerifier. Use !avrf (may take a long time to run (minutes)) and it will try to give you as much useful information as possible.
You can all use the dps command on the memory address to get all the stored stack info (allocation, deallocation, etc).
You can also use the !heap command on the memory address:
Which will dump information as well.
Further Reading:
简短的回答:不。
您需要的是调试 malloc。 我不再关注 Windows,但有几个关于,包括 这个免费的。
更新
看起来 Visual Studio C 有一个内置版本。 请参阅此处
...并参见此处的 _malloc_dbg。
Short answer: no.
What you need is a debug malloc. I don't keep up with Windows any longer but there are several about, including this free one.
Update
Looks like Visual Studio C has a built in version. See here
... and see here for _malloc_dbg.