Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 64273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:45:50+00:00 2026-05-10T18:45:50+00:00

When using the unmanaged API for the .NET framework to profile a .NET process

  • 0

When using the unmanaged API for the .NET framework to profile a .NET process in-process, is it possible to look up the IL instruction pointer that correlates to the native instruction pointer provided to the StackSnapshotCallback function?

As is probably obvious, I am taking a snapshot of the current stack, and would like to provide file and line number information in the stack dump. The Managed Stack Explorer does this by querying ISymUnmanagedMethod::GetSequencePoints. This is great, but the sequence points are associated to offsets, and I have so far assumed these are offsets from the beginning of the method ( in intermediate language ).

In a follow-up comment to his blog post Profiler stack walking: Basics and beyond, David Broman indicates that this mapping can be achieved using ICorDebugCode::GetILToNativeMapping. However, this is not ideal as getting this interface requires attaching to my process from another, debugger process.

I would like to avoid that step because I would like to continue to be able to run my application from within the visual studio debugger while I am taking these snapshots. It makes it easier to click on the line number in the output window and go to the code in question.

The functionality is possible…. you can spit out a line-numbered stack trace at will inside of managed code, the only question, is it accessible. Also, I don’t want to use the System::Diagnostics::StackTrace or System::Environment::StackTrace functionality because, for performance reasons, I need to delay the actual dump of the stack…. so saving the cost for resolution of method names and code location for later is desirable… along with the ability to intermix native and managed frames.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:45:51+00:00Added an answer on May 10, 2026 at 6:45 pm

    In order to translate from a native instruction pointer as provided by ICorProfilerInfo2::DoStackSnapshot to an intermediate language method offset, you must take two steps since DoStackSnapshot provides a FunctionID and native instruction pointer as a virtual memory address.

    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 ICorProfilerInfo2::GetCodeInfo2

    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->GetCodeInfo2(functioId, 0, &cItem, NULL)) &&     (NULL != (codeInfo = new COR_PRF_CODE_INFO[cItem]))) {     if (SUCCEEDED(hr = pInfo->GetCodeInfo2(functionId, cItem, &cItem, codeInfo)))     {         COR_PRF_CODE_INFO *pCur(codeInfo), *pEnd(codeInfo + cItem);         nativePCOffset = 0;         for (; pCur < pEnd; pCur++)         {             // 'ip' is the UINT_PTR passed to the StackSnapshotCallback as named in             // the docs I am looking at              if ((ip >= pCur->startAddress) && (ip < (pCur->startAddress + pCur->size)))             {                 nativePCOffset += (instructionPtr - pCur->startAddress);                 break;             }             else             {                 nativePCOffset += pCur->size;             }          }     }     delete[] codeInfo; codeInfo = NULL; } 

    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 ICorProfilerInfo2::GetILToNativeMapping.

    if ((nativePCOffset != -1) &&     SUCCEEDED(hr = pInfo->GetILToNativeMapping(functionId, 0, &cItem, NULL)) &&     (NULL != (map = new COR_DEBUG_IL_TO_NATIVE_MAP[cItem]))) {     if (SUCCEEDED(pInfo->GetILToNativeMapping(functionId, cItem, &cItem, map)))     {         COR_DEBUG_IL_TO_NATIVE_MAP* mapCurrent = map + (cItem - 1);         for (;mapCurrent >= map; mapCurrent--)         {             if ((mapCurrent->nativeStartOffset <= nativePCOffset) &&                  (mapCurrent->nativeEndOffset > nativePCOffset))             {                 pcIL = mapCurrent->ilOffset;                 break;             }         }     }     delete[] map; map = NULL; } 

    This can then be used to map the code location to a file and line number using the symbol APIs

    Thanks to Mithun Shanbhag for direction in finding the solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 63k
  • Answers 63k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I would use the javascript dateObject.getTimezoneOffset(). Even if their time… May 11, 2026 at 10:30 am
  • added an answer A: This may be a change for security reasons in… May 11, 2026 at 10:30 am
  • added an answer In the end I switched back to Apache + mod_python… May 11, 2026 at 10:30 am

Related Questions

When using the unmanaged API for the .NET framework to profile a .NET process
When using the app_offline.htm feature of ASP.NET, it only allows html, but no images.
When using the php include function the include is succesfully executed, but it is
When using the Eclipse->Team->Show History view, what's the difference between using Subclipse Get Contents
When using the ObsoleteAtribute in .Net it gives you compiler warnings telling you that
When using the .NET WebBrowser control how do you open a link in a
When using the Net.Sockets.TcpListener, what is the best way to handle incoming connections (.AcceptSocket)
When using the pImpl idiom is it preferable to use a boost:shared_ptr instead of
When using the Ajax.BeginForm() helper in ASP.Net MVC , I can pass options with
When using the Entity Framework, does ESQL perform better than Linq to Entities? I'd

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.