如何从 Visual Studio 调试器执行所有进程内存的高级搜索? [英] How to perform advanced search of all process memory from Visual Studio debugger?

查看:55
本文介绍了如何从 Visual Studio 调试器执行所有进程内存的高级搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个大型商业程序的开发人员,我正在尝试追踪特定的 C++ 内存泄漏.我想使用 Visual Studio 搜索我进程的整个有效地址空间,但我看不到如何有效地执行此搜索.

I am a developer on a large commercial program, and I am trying to track down a particular C++ memory leak. I would like to use Visual Studio to search the entire valid address space of my process, but I can not see how to perform this search effectively.

我知道 .s 命令文档这里,但它没有做我需要的.例如,我 100% 确定地址 0xfdfd240 包含值 0x0f0e34a8.我可以成功地使用 .s 命令在该地址附近进行搜索,如下所示:

I am aware of the .s command documentation here, but it is not doing what I need. For examle, I am 100% certain that the address 0xfdfd240 contains the value 0x0f0e34a8. I can successfully use the .s command to search near that address like this:

.s -d 0x0fdfd200 L256000000 0x0f0e34a8
Found match at
0xfdfd240

但是我的程序进行了许多小的分配,这给我留下了许多小的不连续的内存部分.如果我备份几千字节,搜索命令就会失败:

But my program has made many small allocations which have left me with many small non-contiguious sections of memory. If I back up a few thousand bytes the search command fails:

.s -d 0x0fd00000 L256000000 0x0f0e34a8
Memory location could not be read. Please specify a valid memory location.

而且当它找到第一个错误地址时,搜索命令似乎也不再尝试向前搜索,即使在它之后还有有效地址.

And it also appears that the search command does not attempt to search forward any more when it finds it's first bad address, even if there are valid addresses beyond it.

.s -d 0x0f000000 L256000000 0x0f0e34a8
No match was found

我隐约知道有一种方法可以询问 windows 哪些内存范围对给定进程有效,所以我正在考虑编写一个小的一次性程序来收集该信息,然后自动执行一系列搜索命令到Immediate Window...但似乎有人之前必须处理过这个问题,并且必须做得更聪明.

I'm vaguely aware that there is a way to ask windows what memory ranges are valid for a given process, so I'm considering writing a small throwaway program to harvest that information and then automate a series of search commands to the Immediate Window...but it seems like someone must have dealt with this before, and must have done something smarter.

另外,我可以提取正在运行的进程的转储文件,所以如果有人可以推荐第三方工具来提供转储,那么它具有更强大的搜索功能,应该也能工作.

Also, I can extract a dump file of the running process, so if anyone can recommend third party tools to feed the dump to that has stronger search functionality that should work out as well.

有什么建议吗?

我在 VS2008SP1 和 VS2010SP1 中看到了这种行为.

I see this behavior in VS2008SP1 and VS2010SP1.

推荐答案

在进行简单调试之外的任何事情时,我发现 WinDbg(Windows 调试工具的一部分)通常具有更好的功能.

When doing anything beyond simple debugging, I find that often times WinDbg (part of Debugging Tools for Windows) has far better capability.

而且您甚至不必从 WinDbg 进行所有调试.如果你在 VS 中做你的事情,然后想要搜索内存(或做其他在 VS 中不容易做的事情),去调试 -> 将转储另存为...确保选择带堆的小型转储"文件类型.

And you don't even have to do all your debugging from WinDbg. If you are in VS doing your thing and then want to search memory (or do other things which are not easy in VS), go to Debug -> Save Dump As... Make sure to select "Minidump with Heap" file type.

这将为您的流程创建一个完整的快照文件.将其加载到 WinDbg 中,现在您可以使用许多很酷的命令.为了轻松访问文档,您始终可以在命令窗口中键入.hh".所有命令都列在 Debuggers -> Debugger Reference -> Debugger Commands 下.

This will create a complete snapshot file of your process. Load that up into WinDbg and now you have oh some many cool commands at your disposal. For easy access to the documentation, you can always type ".hh" in the command window. All Commands are listed under Debuggers -> Debugger Reference -> Debugger Commands.

你想要的是s(搜索记忆)

The one you want is s (Search Memory)

这篇关于如何从 Visual Studio 调试器执行所有进程内存的高级搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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