Reputation: 454
I want to get the native(x86) code of a debugee function from the debugger using ICorDebug APIs. After getting an ICorDebugFunction, I can call GetNativeCode on it but it returns the native code only if it has been Jited. So I need to forcefully JIt it. The RuntimeHelpers.PrepareMethod can do that but it needs a methodhandle( not a method token).From the debugger I have the Method Token but not the method handle. So can we get the real MethodInfo object(which can get me the handle) of a debugee function from the debugger? In other words, is it possible to do reflection on debugee from debugger?
Upvotes: 1
Views: 137
Reputation: 2856
Not exactly.
You can use IMetadataImport et. al. to get the static information and some dynamic information is available directly through the ICorDebug api, but any other sort of reflection would need to be run on the debuggee (which would normally use ICorDebugeEval).
If you don't mind using ICorDebugEval to execute your reflection on the debuggee, you could use the following sequence.
Depending on your use case, it might be beneficial to combine last 3 steps with your call to PrepareMethod into a helper method in a separate assembly that you have the debugge load.
Upvotes: 3