public int GetOffset(ISymUnmanagedDocument document, int line, int column, out int offset) { if (line <= 0) { offset = 0; return(HResult.E_INVALIDARG); } // Note that DiaSymReader completely ignores column parameter. var symDocument = SymReader.AsSymDocument(document); if (symDocument == null) { offset = 0; return(HResult.E_INVALIDARG); } // DiaSymReader uses DiaSession::findLinesByLinenum, which results in bad results for lines shared across multiple methods // and for lines outside of the current method. var documentHandle = symDocument.Handle; if (!SymReader.TryGetLineDeltas(GetId(), out var deltas)) { deltas = default(MethodLineDeltas); } int sequencePointIndex = 0; foreach (var sp in GetSequencePoints()) { if (!sp.IsHidden && sp.Document == documentHandle) { int delta = deltas.GetDeltaForSequencePoint(sequencePointIndex); if (line >= sp.StartLine + delta && line <= sp.EndLine + delta) { // Return the first matching IL offset. In common cases there will be a single one // since sequence points of a single method don't overlap unless forced by #line. offset = sp.Offset; return(HResult.S_OK); } } sequencePointIndex++; } offset = 0; return(HResult.E_FAIL); }
public int GetOffset(ISymUnmanagedDocument document, int line, int column, out int offset) { if (line <= 0) { offset = 0; return(HResult.E_INVALIDARG); } // Note that DiaSymReader completely ignores column parameter. var symDocument = SymReader.AsSymDocument(document); if (symDocument == null) { offset = 0; return(HResult.E_INVALIDARG); } // DiaSymReader uses DiaSession::findLinesByLinenum, which results in bad results for lines shared across multiple methods // and for lines outside of the current method. var spReader = GetSequencePointEnumerator(); var documentHandle = symDocument.Handle; while (spReader.MoveNext()) { if (!spReader.Current.IsHidden && spReader.Current.Document == documentHandle && line >= spReader.Current.StartLine && line <= spReader.Current.EndLine) { // Return the first matching IL offset. In common cases there will be a single one // since sequence points of a single method don't overlap unless forced by #line. offset = spReader.Current.Offset; return(HResult.S_OK); } } offset = 0; return(HResult.E_FAIL); }
internal int GetMethodSourceExtentInDocument(ISymUnmanagedDocument document, SymMethod method, out int startLine, out int endLine) { var symDocument = SymReader.AsSymDocument(document); if (symDocument == null) { startLine = endLine = 0; return(HResult.E_INVALIDARG); } var methodExtents = SymReader.GetMethodExtents(); if (!methodExtents.TryGetMethodSourceExtent(symDocument.GetId(), method.GetId(), out startLine, out endLine)) { startLine = endLine = 0; return(HResult.E_FAIL); } return(HResult.S_OK); }