找到上次释放的记忆? [英] Finding where memory was last freed?

查看:188
本文介绍了找到上次释放的记忆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常一般:
当发生访问冲突时,有没有一个简单的方法来告诉哪一行代码最后释放一段内存?

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?

详细信息:
Windows,ANSI C,使用Visual Studio

Specifics: Windows, ANSI C, using Visual Studio

推荐答案

是的

安装 Windows调试工具,并使用应用程序验证程序


  1. 文件 - >添加应用程序,选择您的.exe

  2. 在基础之下,选择内存和堆。

  3. 在ntsd(ntsd yourprogram.exe)下运行程序的调试版本。

  4. 重现错误。

  1. File -> Add Application, select your .exe
  2. Under Basics, select Memory and Heaps.
  3. Run the debug build of your program under ntsd (ntsd yourprogram.exe).
  4. Reproduce the bug.

现在,当您发生崩溃时,您会收到广告来自AppVerifier的调试器中的附加信息。使用!avrf(可能需要很长时间才能运行(分钟)),它会尽可能地为您提供更多有用的信息。

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.

您可以使用内存地址上的dps命令获取所有存储的堆栈信息(分配,释放等)。

You can all use the dps command on the memory address to get all the stored stack info (allocation, deallocation, etc).

您还可以在内存地址上使用!heap命令:

You can also use the !heap command on the memory address:

0:004> !heap -p -a 0x0C46CFE0

哪些也会转储信息。

进一步阅读:

  • Advanced Windows Debugging, Hewardt and Pravat
  • Debugging with PageHeap

这篇关于找到上次释放的记忆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆