/// <summary> /// Obtain the original source code file and line number for the given /// IL offset in a method identified by a unique metadata token. /// </summary> /// <param name="methodMetadataToken"></param> /// <param name="ilOffset"></param> /// <returns></returns> /// <remarks> /// Metadata token is stored in the PDB file for each method. Additionally /// it can always be retrieved from MethodInfo via reflection. Exception /// report saves a meatdata token for each method in the stack trace. /// </remarks> public SourceLocation GetSourceLoc(int methodMetadataToken, int ilOffset) { IDiaSymbol symMethod; _session.findSymbolByToken((uint)methodMetadataToken, SymTagEnum.SymTagFunction, out symMethod); var rvaMethod = symMethod.relativeVirtualAddress; rvaMethod += (uint)ilOffset; IDiaEnumLineNumbers lineNumbers; _session.findLinesByRVA(rvaMethod, 1, out lineNumbers); foreach (IDiaLineNumber ln in lineNumbers) { var sourceFile = ln.sourceFile; return(new SourceLocation() { LineNumber = ln.lineNumber, SourceFile = (sourceFile == null) ? null : sourceFile.fileName }); } return(null); }