Inspect Managed Stack

A .NET application can get a managed StackTrace that describes which methods were called and contains references to them to get their name, token and signature, and on which the IL offset in the method body caused the call. But it does not contain the values โ€‹โ€‹of the arguments that were passed to each method.

The values โ€‹โ€‹of the arguments are somewhere in the memory of the process stack for sure, but this is its own representation, which can be a little inconvenient and unpredictable for evaluation.

There is also a managed stack that essentially executes the CLR, before the JIT compiler. In MSIL code, arguments are pushed onto this stack before the call operation code is executed. Therefore, these values โ€‹โ€‹must also be on the CLR stack.

The question is, can a managed application check its own managed stack at runtime to extract such information?

I am not talking about individual debugger processes such as Visual Studio. I want to do this from within the process. I also understand that any executable code will be added to the stack, so this thing would have to set a certain โ€œentry pointโ€ from which I could check the stack up (i.e. towards the root, if the CLR also holds stacks hanging down from the ceiling ...), ignoring what my current method and its called methods are doing.

+2
source share
1 answer

The reason is described by Raymond Chen here .

In short:

The method parameter may become collectable while the method is still running.

This is not intuitive; read the part about JIT and GC working together. Thus, limiting StackTrace design information.

+1
source

Source: https://habr.com/ru/post/1239084/


All Articles