How get value of parameters in stacktrace

对着背影说爱祢 提交于 2019-11-28 09:08:31

There are two ways. The more powerful is the COM API for .NET Debugging. For example, arguments and local variables of function in the call stack are both accessible from ICorDebugILFrame. But this must be run from a separate process that is attached to your process as the debugger.

For in-process introspection, there's the Profiler API, which also can find information about function arguments. Look at the information about "shadow stacks".

Not with C# except if you are creating a highly CLR (patch) version dependant solution. But what does work is to attach Windbg to your process, load sos.dll switch to your thread and type

!ClrStack -p

to show the managed call stack and the method parameters for most methods. This is even under the debugger not foolproof because due to inlining and JIT optimizations the stack layout is very flexible. Besides this some parameters might not even show up in the stack memory because they are passed via registers (which is even more common under the x64 platform).

To answer your first question. No it is not possible with the approach you are trying. A working solution would be possible but not at all portable. A managed debugger can partially retrieve your arguments but there is no 100% working solution (even under the debugger).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!