src/managed/SymbolReader.cs
/// <summary>
/// Returns method token and IL offset for given source line number.
/// </summary>
/// <param name="symbolReaderHandle">symbol reader handle returned by LoadSymbolsForModule</param>
/// <param name="filePath">source file name and path</param>
/// <param name="lineNumber">source line number</param>
/// <param name="methodToken">method token return</param>
/// <param name="ilOffset">IL offset return</param>
/// <returns> true if information is available</returns>
Returns method token and IL offset for given source line number.
Returns method token and IL offset for given source line number .
internal static bool ResolveSequencePoint(IntPtr symbolReaderHandle, [MarshalAs(UnmanagedType.LPWStr)] string filePath, int lineNumber, out int methodToken, out int ilOffset)
        {
            Debug.Assert(symbolReaderHandle != IntPtr.Zero);
            methodToken = 0;
            ilOffset = 0;
            GCHandle gch = GCHandle.FromIntPtr(symbolReaderHandle);
            MetadataReader reader = ((OpenedReader)gch.Target).Reader;
            try
            {
                Func<string, bool> FileNameMatches;
                bool isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
                FileNameMatches = s => s.Equals(filePath, isWindows ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
                foreach (MethodDebugInformationHandle methodDebugInformationHandle in reader.MethodDebugInformation)
                {
                    MethodDebugInformation methodDebugInfo = reader.GetMethodDebugInformation(methodDebugInformationHandle);
                    SequencePointCollection sequencePoints = methodDebugInfo.GetSequencePoints();
                    foreach (SequencePoint point in sequencePoints)
                    {
                        string sourceName = reader.GetString(reader.GetDocument(point.Document).Name);
                        if (point.StartLine == lineNumber && FileNameMatches(sourceName))
                        {
                            methodToken = MetadataTokens.GetToken(methodDebugInformationHandle.ToDefinitionHandle());
                            ilOffset = point.Offset;
                            return true;
                        }
                    }
                }
            }
            catch
            {
            }
            return false;
        }
internal static bool ResolveSequencePoint ( IntPtr symbolReaderHandle , [ MarshalAs ( UnmanagedType . LPWStr ) ] string filePath , int lineNumber , out int methodToken , out int ilOffset ) { Debug . Assert ( symbolReaderHandle != IntPtr . Zero ) ; methodToken = 0 ; ilOffset = 0 ; GCHandle gch = GCHandle . FromIntPtr ( symbolReaderHandle ) ; MetadataReader reader = ( ( OpenedReader ) gch . Target ) . Reader ; try { Func < string , bool > FileNameMatches ; bool isWindows = System . Runtime . InteropServices . RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ; FileNameMatches = s => s . Equals ( filePath , isWindows ? StringComparison . OrdinalIgnoreCase : StringComparison . Ordinal ) ; foreach ( MethodDebugInformationHandle methodDebugInformationHandle in reader . MethodDebugInformation ) { MethodDebugInformation methodDebugInfo = reader . GetMethodDebugInformation ( methodDebugInformationHandle ) ; SequencePointCollection sequencePoints = methodDebugInfo . GetSequencePoints ( ) ; foreach ( SequencePoint point in sequencePoints ) { string sourceName = reader . GetString ( reader . GetDocument ( point . Document ) . Name ) ; if ( point . StartLine == lineNumber && FileNameMatches ( sourceName ) ) { methodToken = MetadataTokens . GetToken ( methodDebugInformationHandle . ToDefinitionHandle ( ) ) ; ilOffset = point . Offset ; return true ; } } } } catch { } return false ; }
Returns method token and IL offset for given source line number.
Returns method token and IL offset for given source line number .
true if information is available
true if information is available
symbolReaderHandle
IntPtr
symbol reader handle returned by LoadSymbolsForModule
symbol reader handle returned by LoadSymbolsForModule
string
[MarshalAs(UnmanagedType.LPWStr)]
<not_specific>
lineNumber
int
source line number
source line number
int
out
<not_specific>
filePath
<not_specific>
source file name and path
source file name and path
methodToken
<not_specific>
method token return
method token return
ilOffset
<not_specific>
IL offset return
IL offset return