A .NET application can get a managed StackTrace
that describes which methods were called and holds references to them to get their name, token and signature, and at which IL offset in the method body the call was made. But it does not contain the argument values that were passed to each method.
The argument values are in the process's stack memory somewhere for sure, but that's the native representation which may be a bit unhandy and unpredictable to evaluate.
There is also the managed stack, the one that the CLR essentially executes on, before the JIT compiler. In MSIL code, arguments are put on that stack before the call
opcode is executed. So these values should also be on the CLR stack.
The question is, can a managed application inspect its own managed stack at runtime to extract such information?
I'm not talking about separate debugger processes like Visual Studio. I want to do this from within the process. I also understand that any executed code will add to the stack, so this thing would need to set a certain "entry point" from which I could inspect the stack upwards (i. e. towards to root, if the CLR also keeps stacks hanging from the ceiling...), ignoring what my current method and its called methods do.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…