Question

I run MSIL inside Visual Studio or via Mdbg.

Is there any way of displaying the contents of the MSIL stack?

e.g. if I execute ldloc "some variable", is there any way of looking at the stack and seeing that the variable is now on the stack.

I'm presuming that the MSIL stack is not the same as the CPU stack i.e. the memory pointed to by the SP register?

Was it helpful?

Solution

At runtime, there actually isn't any "MSIL" stack. Even in debug mode the code that is executed is always JIT compiled. The process of JIT compiling MSIL "flattens" it from a virtual stack machine into ordinary assembly code for the platform you are running on. That means ldloc.0 might end up being translated into something like mov eax, [sp + 4], or even a no-op, if the value was already lying around in a register. If you want to debug the specific instruction ldloc, then you have to look at it in the dissasembly to see what the ldoloc was translated into and where it's actually loading the data from.

The WinDbg + SoS tools (mentioned in another post) will help you to view the CPU stack, from a managed-code perspective. They won't allow you, however, to see the "MSIL" stack because there isn't one to see.

OTHER TIPS

You can do that and more using WinDbg + SoS. Check this question for references on how to use WinDbg.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top