src/managed/SymbolReader.cs
/// <summary>
/// Returns source line number and source file name for given IL offset and method token.
/// </summary>
/// <param name="symbolReaderHandle">symbol reader handle returned by LoadSymbolsForModule</param>
/// <param name="methodToken">method token</param>
/// <param name="ilOffset">IL offset</param>
/// <param name="sequencePoint">sequence point return</param>
/// <returns> true if information is available</returns>
Returns source line number and source file name for given IL offset and method token.
Returns source line number and source file name for given IL offset and method token .
private static bool GetSequencePointByILOffset(IntPtr symbolReaderHandle, int methodToken, long ilOffset, out DbgSequencePoint sequencePoint)
        {
            Debug.Assert(symbolReaderHandle != IntPtr.Zero);
            sequencePoint.document = IntPtr.Zero;
            sequencePoint.startLine = 0;
            sequencePoint.startColumn = 0;
            sequencePoint.endLine = 0;
            sequencePoint.endColumn = 0;
            sequencePoint.offset = 0;
            try
            {
                GCHandle gch = GCHandle.FromIntPtr(symbolReaderHandle);
                MetadataReader reader = ((OpenedReader)gch.Target).Reader;
                Handle handle = MetadataTokens.Handle(methodToken);
                if (handle.Kind != HandleKind.MethodDefinition)
                    return false;
                MethodDebugInformationHandle methodDebugHandle = ((MethodDefinitionHandle)handle).ToDebugInformationHandle();
                if (methodDebugHandle.IsNil)
                    return false;
                MethodDebugInformation methodDebugInfo = reader.GetMethodDebugInformation(methodDebugHandle);
                SequencePointCollection sequencePoints = methodDebugInfo.GetSequencePoints();
                SequencePoint nearestPoint = sequencePoints.GetEnumerator().Current;
                bool found = false;
                foreach (SequencePoint point in sequencePoints)
                {
                    if (found && point.Offset > ilOffset)
                        break;
                    if (!point.IsHidden)
                    {
                        nearestPoint = point;
                        found = true;
                    }
                }
                if (!found || nearestPoint.StartLine == 0) {
                    return false;
                }
                var fileName = reader.GetString(reader.GetDocument(nearestPoint.Document).Name);
                sequencePoint.document = Marshal.StringToBSTR(fileName);
                sequencePoint.startLine = nearestPoint.StartLine;
                sequencePoint.startColumn = nearestPoint.StartColumn;
                sequencePoint.endLine = nearestPoint.EndLine;
                sequencePoint.endColumn = nearestPoint.EndColumn;
                sequencePoint.offset = nearestPoint.Offset;
                fileName = null;
                return true;
            }
            catch
            {
            }
            return false;
        }
private static bool GetSequencePointByILOffset ( IntPtr symbolReaderHandle , int methodToken , long ilOffset , out DbgSequencePoint sequencePoint ) { Debug . Assert ( symbolReaderHandle != IntPtr . Zero ) ; sequencePoint . document = IntPtr . Zero ; sequencePoint . startLine = 0 ; sequencePoint . startColumn = 0 ; sequencePoint . endLine = 0 ; sequencePoint . endColumn = 0 ; sequencePoint . offset = 0 ; try { GCHandle gch = GCHandle . FromIntPtr ( symbolReaderHandle ) ; MetadataReader reader = ( ( OpenedReader ) gch . Target ) . Reader ; Handle handle = MetadataTokens . Handle ( methodToken ) ; if ( handle . Kind != HandleKind . MethodDefinition ) return false ; MethodDebugInformationHandle methodDebugHandle = ( ( MethodDefinitionHandle ) handle ) . ToDebugInformationHandle ( ) ; if ( methodDebugHandle . IsNil ) return false ; MethodDebugInformation methodDebugInfo = reader . GetMethodDebugInformation ( methodDebugHandle ) ; SequencePointCollection sequencePoints = methodDebugInfo . GetSequencePoints ( ) ; SequencePoint nearestPoint = sequencePoints . GetEnumerator ( ) . Current ; bool found = false ; foreach ( SequencePoint point in sequencePoints ) { if ( found && point . Offset > ilOffset ) break ; if ( ! point . IsHidden ) { nearestPoint = point ; found = true ; } } if ( ! found || nearestPoint . StartLine == 0 ) { return false ; } var fileName = reader . GetString ( reader . GetDocument ( nearestPoint . Document ) . Name ) ; sequencePoint . document = Marshal . StringToBSTR ( fileName ) ; sequencePoint . startLine = nearestPoint . StartLine ; sequencePoint . startColumn = nearestPoint . StartColumn ; sequencePoint . endLine = nearestPoint . EndLine ; sequencePoint . endColumn = nearestPoint . EndColumn ; sequencePoint . offset = nearestPoint . Offset ; fileName = null ; return true ; } catch { } return false ; }
Returns source line number and source file name for given IL offset and method token.
Returns source line number and source file name for given IL offset and method token .
true if information is available
true if information is available
symbolReaderHandle
IntPtr
symbol reader handle returned by LoadSymbolsForModule
symbol reader handle returned by LoadSymbolsForModule
methodToken
int
None
ilOffset
long
None
DbgSequencePoint
out
sequencePoint
sequence point return
sequence point return