Get the values of method`s parameters

Hello!

How can I get the values of the parameters of a method that is in an assembly, at run-time?

Lets say we want to see the System.Xml assembly, XmlDocumnet class and and some application I don`t know calls the 'CreateNode(string, string, string)' method, e.g: xmlDocument.CreateNode("1","2","").

I want to make an aplication that has the input data the name of the assembly (e.g. System.Xml.dll) and with the System.Reflection namespace I was able to get the static structure of the assembly(classes, constructors, methods + signarure, proprietes, events).
When I click on a method, I want to see all the calls of that method since I`ve clicked on it until the current moment.

Is this possible?

Do you think this could help?
http://msdn2.microsoft.com/en-us/library/ms404386.aspx

Thanks!

[1006 byte] By [Eusebiu] at [2007-12-24]
# 1

You would have to use the profiling API. However even then you can't see method calls that have already happened. You would need to log each method call as it occurs for later use. There is no place in .NET where a list of methods that were called is stored. This would require a tremendous amount of memory. Using the profiling API you can monitor the calls an application makes.

Michael Taylor - 9/21/06

TaylorMichaelL at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2

Thanks for the answer.

I want to say that I want to see not only the method name but the parameter`s values too!(eg: System.Xml.Xmldocument.CreateNode("1","2", "");)

Thanks!

Eusebiu at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3

You can retrieve the parameters from the profiling API as well. The COR_PRF_FUNCTION_ARGUMENT_INFO and related structures can be used. However you'll need to go through the documentation and samples to determine how to use them. I believe there is a sample in MSDN or in the SDK that provides a base profiler implementation.

If you want to use a different method for examining method calls then please post what method you are using. I don't believe there is any way in .NET itself to arbitrarily monitor a specific method invocation without using the profiler.

Michael Taylor - 9/21/06

TaylorMichaelL at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 4

Thanks Michael!

Yes... I want to use a .NET method, not the one with the API profiler.

Thanks

Eusebiu at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 5

AFAIK there is no way to hook an arbitrary method invocation (such as XmlDocument.CreateNode) from within .NET and retrieve the argument information. The best you can do is use StackFrame and StackTrace to get the method that was called and where it is located. You could, in theory, get the IL offset and then enumerate the IL code but that would probably be really difficult. However since you can't arbitrary trap method invocations you would need to modify whatever method(s) you wanted to track such that they called a method you wrote to dump the information. Not pretty.

Michael Taylor - 9/21/06

TaylorMichaelL at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 6

Ok then... I guess I'll have to use API profiler.

Thanks a lot Michael!

Eusebiu at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 7
Is there any example code of how to actually evaluate the function argument values anywhere? I have looked extensively and can't seem to find any. I have a CLR profiler that logs the function names, return type, and parameter types, but I would also like to log the value of each parameter. I have navigated into the COR_PRF_FUNCTION_ARGUMENT_RANGE structure and obtained the starting memory address of the memory block for each argument, and in the case of an integer I can evaluate it, but having trouble figuring how to make sense if it's any other type of variable or an object, class etc...
rrry at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified