views:

93

answers:

3

Ok, This question is not exactly a programming question but this is what can really make programming more practical and easy to implement.

This question is coming out beacuase each-time I write int c=10; or MyClass objMyClass=new MyClass(); I want to see where in the memory the value has been created (Though We can see the address as an Hex Value now) .

Can we see (when we declare a variable) Where it is being created in the Memory? In which state i.e : C#->IL->Machine Language, is the variable present in the memory.Now how different events and functions update it's value. This is just something like my CPU emulator.

I am asking because this question was popping in mind long time? When ever I get to know a new concept , the reflex is , Ok How does it look in the memory.

+2  A: 

You need good debugger, they are capable of what is going on behind the scene in details. You can start with Visual Studio, if it is not enough, try more sophisticated debuggers like IDA or OllyDbg.

Andrey
+4  A: 

You can see all this and more if you load the SOS.dll (or PSSCOR2.dll) extension into WinDbg or even into Visual Studio.

SOS is a part of the .NET framework and it basically turns a native debugger such as WinDbg into a "managed code aware" debugger.

SOS has commands that will let you inspect the managed heap, objects and their references and so on.

For more information see Tess' excellent blog.

For another example of how to use SOS see this question.

Brian Rasmussen
@Brian Rasmussen,Tess' excellent blog is linking to http://blogs.msdn.com/b/tess/ if you can change it to http://blogs.msdn.com/b/tess/archive/2007/10/19/net-finalizer-memory-leak-debugging-with-sos-dll-in-visual-studio.aspx
Subhen
@Subhen I picked the overview page, as she has many very useful posts on managed debugging.
Brian Rasmussen
+3  A: 

There is a .NET extension to the Microsoft Debugger called 'SoS' that allows you to inspect the memory and other internal structures of the .NET CLR.

It is quite a low-level tool so it will take a while to become proficient in its use. I would recommend searching for tutorials following these.

  • Debugging Tools for Windows includes the debugger (WinDbg and CDB).
  • Son of Strike (SOS.dll) is shipped with the .NET runtime at %WINDIR%\Microsoft.NET\Framework*\SOS.dll.

It may also be worth searching for SoS, memory-management and memory-leaks questions on StackOverflow.

Paul Ruane