views:

460

answers:

4

I don't think this exists, but I'll throw this out there anyway. Is it possible, while debugging, to search for a value in memory?

For example, if I have a string "uniqueString" cached somewhere in memory, but I don't know under which variable it's stored--can I do a search for it? As in, find out which variable(s) have "uniqueString" as their value?

This is for C# managed code.

A: 

You would need to create a memory dump. Windbg would enable you to do this.

Visual Studio can read dumps.

Mitch Wheat
+1  A: 

windbg will let you do the search directly. 's' is the command you're looking for, here's a very good cheat sheet. sos extension lets you scan for string objects too in managed code though the s command should find them too (must use unicode aware search).

ShuggyCoUk
+1  A: 

You have the same functionality in Visual Studio, available from the immediate window. Although, you'd have to manually somehow limit the address range to search in (see the syntax in the link).

(edit) BTW, you can easily create dumps from VS too: Debug->Save Dump As.

Ofek Shilon
A: 

I'm using Visual Studio 2008 and I can't for the life of me getting the memory search working in the immediate window. I am debugging a memory dump and it just keeps giving me one of the following errors: CXX0014: Error: missing operand or CXX0013: Error: missing operator

I tried cut and pasting the examples from here:

http://msdn.microsoft.com/en-us/library/ms171363%28v=VS.90%29.aspx

Has anybody had any success using the memory search feature in VS 2008? In the mean time I'm going to try Windbg.

Martin Sherburn