如何获得的堆栈跟踪参数值 [英] How get value of parameters in stacktrace

查看:374
本文介绍了如何获得的堆栈跟踪参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过堆栈跟踪使用像这样获得有关参数的信息:

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)

和通话是这样的:

MyMethod(10);

我想要得到值10。 我该怎么办呢?

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

推荐答案

有两种方式。更强大的是.NET调试的COM API。例如,参数和函数的局部变量调用堆栈都来自 ICorDebugILFrame 。但是,这必须从一个连接到你的过程,因为调试器单独的进程中运行。

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.

有关过程中的反思,还有的探查API,它也可以找到关于函数参数的信息。请看有关影子堆栈的信息。

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

这篇关于如何获得的堆栈跟踪参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆