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.
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
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.
Any suggestions?
Edit: I see this behavior in VS2008SP1 and VS2010SP1.
When doing anything beyond simple debugging, I find that often times WinDbg (part of Debugging Tools for Windows) has far better capability.
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.
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.
The one you want is s (Search Memory)