当堆 > 时条件断点一些限制
当附加进程的分配内存大于某个值时,是否可以中断调试器?
最好使用 Visual Studio 2005,但也可以选择其他 IDE/调试器。
Is it possible to break into debugger when the allocated memory of attached-to process becomes bigger than a certain value?
Preferrably using Visual Studio 2005, but other IDE's/debuggers are an option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有直接的方法可以做到这一点。另一种方法是在 CRT 分配代码中的某处设置普通断点,并在命中计数是 2000 的倍数时将其设置为中断。您将足够快地进入所需状态。
There is no direct way to do it. Alternative is to set ordinary breakpoint somewhere inside CRT allocation code, and set it to break when the hit count is multiple of say 2000. You'll get to wanted state quickly enough.
我不知道 Visual Studio 中有任何直接的方法,但您可以使用 ProcDump< /a> 当内存提交阈值达到特定值时创建故障转储(-m 选项)。
然后,您需要使用 WinDbg(Windows 调试工具)来检查堆。
I don't know of any direct way in Visual Studio, but you could use ProcDump to create a crash dump when the Memory commit threshold reaches a certain value (-m option).
You would then need to use WinDbg (part of the Windows debugging tools) to inspect the heap.
这个问题可能很旧,但仍然相关。
您可以使用以下函数检查可用内存:
https ://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-globalmemorystatusex
https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getprocessmemoryinfo
然后,偶尔从主线程调用该函数,或者运行一个单独的线程来监视主线程。您可以在监视代码中设置断点,以便在内存使用超过定义的阈值时中断执行。
The question may be old, but it is still relevant.
You can check available memory using these functions:
https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-globalmemorystatusex
https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getprocessmemoryinfo
Then, either call that function from your main thread occasionally or run a separate thread to monitor the main thread. You can have a breakpoint in the monitoring code to break execution if memory use exceeds a defined threshold.