Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In order to translate from a native instruction pointer as provided by <code>ICorProfilerInfo2::DoStackSnapshot</code> to an intermediate language method offset, you must take two steps since <code>DoStackSnapshot</code> provides a <code>FunctionID</code> and native instruction pointer as a virtual memory address.</p> <p>Step 1, is to convert the instruction pointer to a native code method offset. ( an offset from the beginning of the JITed method). This can be done with <code>ICorProfilerInfo2::GetCodeInfo2</code></p> <pre><code>ULONG32 pcIL(0xffffffff); HRESULT hr(E_FAIL); COR_PRF_CODE_INFO* codeInfo(NULL); COR_DEBUG_IL_TO_NATIVE_MAP* map(NULL); ULONG32 cItem(0); UINT_PTR nativePCOffset(0xffffffff); if (SUCCEEDED(hr = pInfo-&gt;GetCodeInfo2(functioId, 0, &amp;cItem, NULL)) &amp;&amp; (NULL != (codeInfo = new COR_PRF_CODE_INFO[cItem]))) { if (SUCCEEDED(hr = pInfo-&gt;GetCodeInfo2(functionId, cItem, &amp;cItem, codeInfo))) { COR_PRF_CODE_INFO *pCur(codeInfo), *pEnd(codeInfo + cItem); nativePCOffset = 0; for (; pCur &lt; pEnd; pCur++) { // 'ip' is the UINT_PTR passed to the StackSnapshotCallback as named in // the docs I am looking at if ((ip &gt;= pCur-&gt;startAddress) &amp;&amp; (ip &lt; (pCur-&gt;startAddress + pCur-&gt;size))) { nativePCOffset += (instructionPtr - pCur-&gt;startAddress); break; } else { nativePCOffset += pCur-&gt;size; } } } delete[] codeInfo; codeInfo = NULL; } </code></pre> <p>Step 2. Once you have an offset from the begining of the natvie code method, you can use this to convert to an offset from the begining of the intermediate language method using <code>ICorProfilerInfo2::GetILToNativeMapping</code>.</p> <pre><code>if ((nativePCOffset != -1) &amp;&amp; SUCCEEDED(hr = pInfo-&gt;GetILToNativeMapping(functionId, 0, &amp;cItem, NULL)) &amp;&amp; (NULL != (map = new COR_DEBUG_IL_TO_NATIVE_MAP[cItem]))) { if (SUCCEEDED(pInfo-&gt;GetILToNativeMapping(functionId, cItem, &amp;cItem, map))) { COR_DEBUG_IL_TO_NATIVE_MAP* mapCurrent = map + (cItem - 1); for (;mapCurrent &gt;= map; mapCurrent--) { if ((mapCurrent-&gt;nativeStartOffset &lt;= nativePCOffset) &amp;&amp; (mapCurrent-&gt;nativeEndOffset &gt; nativePCOffset)) { pcIL = mapCurrent-&gt;ilOffset; break; } } } delete[] map; map = NULL; } </code></pre> <p>This can then be used to map the code location to a file and line number using the symbol APIs</p> <p>Thanks to <a href="http://social.msdn.microsoft.com/Forums/en-US/netfxtoolsdev/thread/ee47a207-5ee6-4e24-a89f-e2134a8eb7c8" rel="nofollow noreferrer">Mithun Shanbhag</a> for direction in finding the solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload