private void EnsureMethods()
 {
     if (_methods == null)
     {
         _methods = new List <ImportedMethod>();
         foreach (MethodDefinitionHandle methodHandle in _typeDef.GetMethods())
         {
             ImportedMethod method = Module.ResolveMethod(methodHandle, this);
             _methods.Add(method);
         }
     }
 }
        internal ImportedMethod ResolveMethod(MethodDefinitionHandle handle, ImportedType declaringType = null)
        {
            ImportedMethod method;

            if (!_resolvedMethods.TryGetValue(handle, out method))
            {
                MethodDefinition methodDef = _reader.GetMethodDefinition(handle);
                method = new ImportedMethod(this, methodDef, declaringType ?? ResolveType(methodDef.GetDeclaringType()));
                _resolvedMethods.Add(handle, method);
            }

            return(method);
        }
        public ImportedMethod TryImportCurrentMethod()
        {
            if (_currentMethod != null)
                return _currentMethod;

            IntPtr metadataBlock;
            uint blockSize;
            try
            {
                metadataBlock = InstructionAddress.ModuleInstance.GetMetaDataBytesPtr(out blockSize);
            }
            catch (DkmException)
            {
                // This can fail when dump debugging if the full heap is not available
                return null;
            }

            ImportedModule module = Session.Importer.ImportModule(metadataBlock, blockSize);
            _currentMethod = module.GetMethod(InstructionAddress.MethodId.Token);
            return _currentMethod;
        }
        internal ImportedMethod ResolveMethod(MethodDefinitionHandle handle, ImportedType declaringType = null)
        {
            ImportedMethod method;
            if (!_resolvedMethods.TryGetValue(handle, out method))
            {
                MethodDefinition methodDef = _reader.GetMethodDefinition(handle);
                method = new ImportedMethod(this, methodDef, declaringType ?? ResolveType(methodDef.GetDeclaringType()));
                _resolvedMethods.Add(handle, method);
            }

            return method;
        }
 private IEnumerable<LocalVariable> GetLocalsImpl(ImportedMethod method)
 {
     if (method != null)
     {
         // Get the local symbols from the PDB (symbol file).  If symbols aren't loaded, we
         // can't show any local variables
         DkmClrLocalVariable[] symbols = GetLocalSymbolsFromPdb().ToArray();
         if (symbols.Length != 0)
         {
             // To determine the local types, we need to decode the local variable signature
             // token.  Get the token from the debugger, then use the Iris Compiler's importer
             // to get the variables types.  We can then construct the correlated list of local
             // types and names.
             int localVarSigToken = InstructionAddress.ModuleInstance.GetLocalSignatureToken(CurrentMethodToken);
             ImmutableArray<IrisType> localTypes = method.Module.DecodeLocalVariableTypes(localVarSigToken);
             foreach (DkmClrLocalVariable localSymbol in symbols)
             {
                 int slot = localSymbol.Slot;
                 yield return new LocalVariable(localSymbol.Name, localTypes[slot], slot);
             }
         }
     }
 }