如何记录特定内存位置何时被写入以及由哪个函数写入?
我有一个很少发生但会导致我的 C++ 程序崩溃的错误。我似乎遇到了缓冲区溢出问题或类似问题。我发现这些类型的错误是最难诊断的。
由于相同的损坏的内存位置,我的程序总是崩溃。是否有一些调试工具可以检测特定内存位置何时被写入并记录执行此操作的函数?
我使用 Visual Leak Detector (VLD) 来查找内存泄漏,效果非常好。它替换了它自己的原始 malloc,并记录每个分配。我想知道是否有类似的记忆?
我知道类似的事情会削弱程序,但它可能真的很有帮助。
我正在使用 Visual Studio 2008。
I have a bug which happens very rarely but crashes my C++ program. It's seems I have a buffer overflow problem or something similar. I find that these types of bug are the most difficult to diagnose.
My program always crashes because of the same corrupted memory location. Is there some debugging tool which could detect when a particular memory location get written to and logs the function which does it?
I'm using Visual Leak Detector (VLD) for my memory leak hunting and it works great. It substitutes the original mallocs which its own and logs every allocation. I was wondering if there is something similar for memory?
I know that something like that would cripple a program, but it could be really helpful.
I'm using Visual Studio 2008.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用的是 Visual C++,请查找数据断点。
If you are using Visual C++ then look up data breakpoints.
许多调试器可以监视特定的内存位置,并在该位置的内容发生更改时中断。不确定您的特定工具链,但 gdb 肯定支持这一点。
Many debuggers can watch a particular memory location, and break whenever the contents of that location are changed. Not sure about your particular toolchain, but
gdb
certainly supports this.Valgrind 是一个可以检测此类问题的工具。它是免费、开源且易于使用的。
Valgrind is a tool that can detect problems like this. It's free, open source and easy to use.