src/managed/SymbolReader.cs
/// <summary>
/// Helper method to return local variable name for given local index and IL offset.
/// </summary>
/// <param name="symbolReaderHandle">symbol reader handle returned by LoadSymbolsForModule</param>
/// <param name="methodToken">method token</param>
/// <param name="localIndex">local variable index</param>
/// <param name="localVarName">local variable name return</param>
/// <returns>true if name has been found</returns>
Helper method to return local variable name for given local index and IL offset.
Helper method to return local variable name for given local index and IL offset .
internal static bool GetLocalVariableByIndex(IntPtr symbolReaderHandle, int methodToken, int localIndex, out string localVarName)
        {
            Debug.Assert(symbolReaderHandle != IntPtr.Zero);
            localVarName = null;
            GCHandle gch = GCHandle.FromIntPtr(symbolReaderHandle);
            MetadataReader reader = ((OpenedReader)gch.Target).Reader;
            try
            {
                Handle handle = MetadataTokens.Handle(methodToken);
                if (handle.Kind != HandleKind.MethodDefinition)
                    return false;
                MethodDebugInformationHandle methodDebugHandle = ((MethodDefinitionHandle)handle).ToDebugInformationHandle();
                LocalScopeHandleCollection localScopes = reader.GetLocalScopes(methodDebugHandle);
                foreach (LocalScopeHandle scopeHandle in localScopes)
                {
                    LocalScope scope = reader.GetLocalScope(scopeHandle);
                    LocalVariableHandleCollection localVars = scope.GetLocalVariables();
                    foreach (LocalVariableHandle varHandle in localVars)
                    {
                        LocalVariable localVar = reader.GetLocalVariable(varHandle);
                        if (localVar.Index == localIndex)
                        {
                            if (localVar.Attributes == LocalVariableAttributes.DebuggerHidden)
                                return false;
                            localVarName = reader.GetString(localVar.Name);
                            return true;
                        }
                    }
                }
            }
            catch
            {
            }
            return false;
        }
internal static bool GetLocalVariableByIndex ( IntPtr symbolReaderHandle , int methodToken , int localIndex , out string localVarName ) { Debug . Assert ( symbolReaderHandle != IntPtr . Zero ) ; localVarName = null ; GCHandle gch = GCHandle . FromIntPtr ( symbolReaderHandle ) ; MetadataReader reader = ( ( OpenedReader ) gch . Target ) . Reader ; try { Handle handle = MetadataTokens . Handle ( methodToken ) ; if ( handle . Kind != HandleKind . MethodDefinition ) return false ; MethodDebugInformationHandle methodDebugHandle = ( ( MethodDefinitionHandle ) handle ) . ToDebugInformationHandle ( ) ; LocalScopeHandleCollection localScopes = reader . GetLocalScopes ( methodDebugHandle ) ; foreach ( LocalScopeHandle scopeHandle in localScopes ) { LocalScope scope = reader . GetLocalScope ( scopeHandle ) ; LocalVariableHandleCollection localVars = scope . GetLocalVariables ( ) ; foreach ( LocalVariableHandle varHandle in localVars ) { LocalVariable localVar = reader . GetLocalVariable ( varHandle ) ; if ( localVar . Index == localIndex ) { if ( localVar . Attributes == LocalVariableAttributes . DebuggerHidden ) return false ; localVarName = reader . GetString ( localVar . Name ) ; return true ; } } } } catch { } return false ; }
Helper method to return local variable name for given local index and IL offset.
Helper method to return local variable name for given local index and IL offset .
true if name has been found
true if name has been found
symbolReaderHandle
IntPtr
symbol reader handle returned by LoadSymbolsForModule
symbol reader handle returned by LoadSymbolsForModule
methodToken
int
None
localIndex
int
local variable index
local variable index
string
out
localVarName
local variable name return
local variable name return