检查管理堆栈 [英] Inspect the managed stack
问题描述
一个.NET应用程序可以得到堆栈跟踪 A管理
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.
参数值是在这个过程中的堆栈内存的某个地方肯定的,但是这是本地再presentation这可能有点不方便和联合国predictable评估。
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.
也有管理堆栈,该CLR本质上执行,JIT编译器之前的数值。在MSIL code,参数被放在了堆栈中的来电前执行
运算code。因此,这些值也应在CLR堆栈。
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?
我说的不是像Visual Studio独立的调试过程。我想从这个过程中做到这一点。我也明白,任何执行code将添加到堆栈中,所以这件事情需要设置一定的切入点从中我可以向上(即检查堆栈朝根,如果CLR也保留堆栈挂从天花板......),忽略了什么我现在的方法及其调用的方法做的。
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.
推荐答案
原因是由雷蒙德陈的此处。
The reason is described by Raymond Chen here.
它的短:
一个参数的方法能够成为符合回收,而该方法仍在执行。
A parameter to a method can become eligible for collection while the method is still executing.
我觉得应该是参数,没有参数。这不是inuitive,了解JIT和GC一起工作的一部分。所以的堆栈跟踪信息的限制是由设计。
I think that should have been argument, not parameter. It's not inuitive, read the part about JIT and GC working together. So the limitation of the StackTrace info is by design.
这篇关于检查管理堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!