Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

File name and line number in StackSnapshotCallback (unmanaged API for profiling)

$
0
0

I'm trying to make my profiler output how a profiled method was called, from a FunctionEnter hook.  With the DoStackSnapshot and StackSnapshotCallback combo, getting the class and method names in the call stack is easy enough.  However, getting the file names or the line numbers seems to be quite hard.

The only information I found is from a forum thread and related Stack Overflow question:

  • https://social.msdn.microsoft.com/Forums/en-US/ee47a207-5ee6-4e24-a89f-e2134a8eb7c8/how-do-i-resolve-managed-symbol-names-using-the-unmanged-profiling-api-inprocess?forum=netfxtoolsdev
  • https://stackoverflow.com/questions/198754/how-do-you-map-a-native-to-il-instruction-pointer-in-process

The following steps are suggested:

  1. Get native code offset from the instruction pointer with `GetCodeInfo2`.
  2. Convert it to an IL offset with `GetILToNativeMapping`.
  3. Get symbols from that IL offset.

While steps (1) and (2) are complicated but clear enough, step (3) is a mystery to me. My questions are thus:

  • Is a profiler supposed to have access to file names and line numbers for given stack frames?
  • If yes, are those steps a good way of obtaining the file name or line number for a given stack frame?
  • If yes, how to do step (3)?
  • Is there a better way?

Viewing all articles
Browse latest Browse all 1710

Trending Articles