Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PdbLocalScope"/> class.
        /// </summary>
        /// <param name="function">Function that contains this scope.</param>
        /// <param name="handle">Our metadata reader handle.</param>
        /// <param name="parent">Parent scope.</param>
        internal PdbLocalScope(PdbFunction function, LocalScopeHandle handle, IPdbLocalScope parent = null)
        {
            Function        = function;
            localScopeCache = SimpleCache.CreateStruct(() => function.PdbFile.Reader.GetLocalScope(handle));
            childrenCache   = SimpleCache.CreateStruct(() =>
            {
                var enumerator = LocalScope.GetChildren();
                List <IPdbLocalScope> children = new List <IPdbLocalScope>();

                while (enumerator.MoveNext())
                {
                    children.Add(new PdbLocalScope(function, enumerator.Current, this));
                }
                return(children);
            });
            constantsCache = SimpleCache.CreateStruct(() =>
            {
                var localConstants            = LocalScope.GetLocalConstants();
                IPdbLocalConstant[] constants = new IPdbLocalConstant[localConstants.Count];
                int i = 0;

                foreach (var c in localConstants)
                {
                    constants[i++] = new PdbLocalConstant(this, c);
                }
                return(constants);
            });
            variablesCache = SimpleCache.CreateStruct(() =>
            {
                var localVariables            = LocalScope.GetLocalVariables();
                IPdbLocalVariable[] variables = new IPdbLocalVariable[localVariables.Count];
                int i = 0;

                foreach (var v in localVariables)
                {
                    variables[i++] = new PdbLocalVariable(this, v);
                }
                return(variables);
            });
        }
Example #2
0
        /// <summary>
        /// Find function by the specified token.
        /// </summary>
        /// <param name="token">Method definition token.</param>
        /// <returns><see cref="IPdbFunction"/> object if found, <c>null</c> otherwise.</returns>
        public IPdbFunction GetFunctionFromToken(int token)
        {
            EntityHandle handle    = System.Reflection.Metadata.Ecma335.MetadataTokens.EntityHandle(token);
            int          rowNumber = System.Reflection.Metadata.Ecma335.MetadataTokens.GetRowNumber(handle);
            MethodDebugInformationHandle methodHandle = System.Reflection.Metadata.Ecma335.MetadataTokens.MethodDebugInformationHandle(rowNumber);

            try
            {
                PdbFunction function = functionsByHandle[methodHandle];

                if (function != null)
                {
                    // Verify that returned function is valid.
                    var document = function.MethodDebugInformation.Document;
                }
                return(function);
            }
            catch
            {
                functionsByHandle[methodHandle] = null;
                return(null);
            }
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PdbSequencePoint"/> class.
 /// </summary>
 /// <param name="function">Function that contains this sequence point.</param>
 /// <param name="sequencePoint">Sequence point.</param>
 internal PdbSequencePoint(PdbFunction function, SequencePoint sequencePoint)
 {
     Function      = function;
     SequencePoint = sequencePoint;
     sourceCache   = SimpleCache.CreateStruct(() => Function.PdbFile[SequencePoint.Document]);
 }