Skip to content

Instantly share code, notes, and snippets.

@vivmishra
Created October 23, 2015 21:04
Show Gist options
  • Save vivmishra/0ba03a73154ee9fde6cd to your computer and use it in GitHub Desktop.
Save vivmishra/0ba03a73154ee9fde6cd to your computer and use it in GitHub Desktop.
Better support for accessing PDBs in IcorProfilerInfo
//Step 1) Set the COR_PRF_HIGH_IN_MEMORY_SYMBOLS_UPDATED flag so that your profiler will receive callbacks when symbols are loaded for modules.
// in production handle possible failing HRESULTs
ICorProfilerInfo5* pCorProfilerInfo5 = …
DWORD lowFlags = 0; // Most profilers will have other flags to set
DWORD highFlags = COR_PRF_HIGH_IN_MEMORY_SYMBOLS_UPDATED;
pCorProfilerInfo5->SetEventMask2(lowFlags, highFlags);
// Step 2) Implement ICorProfilerCallback7 so that your profiler can handle the symbol load notification
HRESULT STDMETHODCALLTYPE ProfilerCallback::ModuleInMemorySymbolsUpdated(
ModuleID moduleId)
{
// in production handle possible failing HRESULTs
ICorProfilerInfo7* pCorProfilerInfo7 = …
DWORD length = 0;
pCorProfilerInfo7->GetInMemorySymbolsLength(moduleId, &length);
BYTE* pSymbols = new BYTE[length];
DWORD lengthRead = 0;
pCorProfilerInfo7->ReadInMemorySymbols(moduleId, 0, pSymbols, length, &lengthRead);
// Do whatever you want with the PDB data in pSymbols. These bytes will match
// the byte array that was passed to Assembly.Load().
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment