Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 views
in Technique[技术] by (71.8m points)

c# - How get value of parameters in stacktrace

I can get information about a parameter by StackTrace using something like this:

catch (Exception ex)
{
    var st = new StackTrace(ex);

    System.Reflection.ParameterInfo pi = st.GetFrame(0).GetMethod().GetParameters().First();
}

I want know how i get the value of parameter. Example:

If my method in stack trace was like:

void MyMethod(object value)

And the call was like:

MyMethod(10);

I want to get the value 10. How i do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...