GetSymbol() private method

Gets the symbol from the cache or adds new entry in the cache if symbol wasn't previously found.
private GetSymbol ( IDiaSymbol symbol ) : Symbol
symbol IDiaSymbol The symbol.
return Symbol
Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SymbolField"/> class.
        /// </summary>
        /// <param name="parentType">The parent type.</param>
        /// <param name="symbol">The DIA symbol.</param>
        public SymbolField(Symbol parentType, IDiaSymbol symbol)
        {
            this.symbol  = symbol;
            ParentType   = parentType;
            Name         = symbol.name;
            LocationType = (LocationType)symbol.locationType;
            DataKind     = (DataKind)symbol.dataKind;
            Offset       = symbol.offset;
            Value        = symbol.value;

            var size = symbol.length;

            if (size > int.MaxValue)
            {
                throw new ArgumentException("Symbol size is unexpected");
            }
            Size = (int)size;

            var bitPosition = symbol.bitPosition;

            if (bitPosition > int.MaxValue)
            {
                throw new ArgumentException("Symbol bit position is unexpected");
            }
            BitPosition = (int)bitPosition;

            IDiaSymbol type = symbol.type;

            if (type != null)
            {
                Type = Module.GetSymbol(type);
            }
        }
Exemplo n.º 2
0
        public static Symbol GetSymbol(string typeName, Module module)
        {
            Symbol[] symbols;

            if (deduplicatedSymbols.TryGetValue(typeName, out symbols))
                return symbols[0];
            return module.GetSymbol(typeName);
        }
Exemplo n.º 3
0
        public static Symbol GetSymbol(string typeName, Module module)
        {
            Symbol[] symbols;

            if (deduplicatedSymbols.TryGetValue(typeName, out symbols))
            {
                return(symbols[0]);
            }
            return(module.GetSymbol(typeName));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Symbol"/> class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="symbol">The DIA symbol.</param>
        public Symbol(Module module, IDiaSymbol symbol)
        {
            this.symbol = symbol;
            Module      = module;
            Tag         = (SymTagEnum)symbol.symTag;
            BasicType   = (BasicType)symbol.baseType;
            Id          = symbol.symIndexId;
            if (Tag != SymTagEnum.SymTagExe)
            {
                Name = TypeToString.GetTypeString(symbol);
            }
            else
            {
                Name = "";
            }

            Name   = Name.Replace("<enum ", "<").Replace(",enum ", ",");
            Offset = symbol.offset;

            var size = symbol.length;

            if (size > int.MaxValue)
            {
                throw new ArgumentException("Symbol size is unexpected");
            }
            Size = (int)size;

            // Initialize caches
            fields      = SimpleCache.Create(() => symbol.GetChildren(SymTagEnum.SymTagData).Select(s => new SymbolField(this, s)).Where(f => f.Type != null).ToArray());
            baseClasses = SimpleCache.Create(() => symbol.GetChildren(SymTagEnum.SymTagBaseClass).Select(s => Module.GetSymbol(s)).ToArray());
            elementType = SimpleCache.Create(() =>
            {
                if (Tag == SymTagEnum.SymTagPointerType || Tag == SymTagEnum.SymTagArrayType)
                {
                    IDiaSymbol type = symbol.type;

                    if (type != null)
                    {
                        var result = Module.GetSymbol(type);
                        if (Tag == SymTagEnum.SymTagPointerType)
                        {
                            result.pointerType.Value = this;
                        }
                        return(result);
                    }
                }

                return(null);
            });
            pointerType = SimpleCache.Create(() =>
            {
                var result = Module.GetSymbol(symbol.objectPointerType);
                result.elementType.Value = this;
                return(result);
            });
            userType   = SimpleCache.Create(() => (UserType)null);
            enumValues = SimpleCache.Create(() =>
            {
                List <Tuple <string, string> > result = new List <Tuple <string, string> >();

                if (Tag == SymTagEnum.SymTagEnum)
                {
                    foreach (var enumValue in symbol.GetChildren())
                    {
                        result.Add(Tuple.Create(enumValue.name, enumValue.value.ToString()));
                    }
                }

                return(result.ToArray());
            });
            namespaces = SimpleCache.Create(() => SymbolNameHelper.GetSymbolNamespaces(Name));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Symbol"/> class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="symbol">The DIA symbol.</param>
        public Symbol(Module module, IDiaSymbol symbol)
        {
            this.symbol = symbol;
            Module = module;
            Tag = (SymTagEnum)symbol.symTag;
            BasicType = (BasicType)symbol.baseType;
            Id = symbol.symIndexId;
            if (Tag != SymTagEnum.SymTagExe)
                Name = TypeToString.GetTypeString(symbol);
            else
                Name = "";

            Name = Name.Replace("<enum ", "<").Replace(",enum ", ",");
            Offset = symbol.offset;

            var size = symbol.length;
            if (size > int.MaxValue)
                throw new ArgumentException("Symbol size is unexpected");
            Size = (int)size;

            // Initialize caches
            fields = SimpleCache.Create(() => symbol.GetChildren(SymTagEnum.SymTagData).Select(s => new SymbolField(this, s)).Where(f => f.Type != null).ToArray());
            baseClasses = SimpleCache.Create(() => symbol.GetChildren(SymTagEnum.SymTagBaseClass).Select(s => Module.GetSymbol(s)).ToArray());
            elementType = SimpleCache.Create(() =>
            {
                if (Tag == SymTagEnum.SymTagPointerType || Tag == SymTagEnum.SymTagArrayType)
                {
                    IDiaSymbol type = symbol.type;

                    if (type != null)
                    {
                        var result = Module.GetSymbol(type);
                        if (Tag == SymTagEnum.SymTagPointerType)
                            result.pointerType.Value = this;
                        return result;
                    }
                }

                return null;
            });
            pointerType = SimpleCache.Create(() =>
            {
                var result = Module.GetSymbol(symbol.objectPointerType);
                result.elementType.Value = this;
                return result;
            });
            userType = SimpleCache.Create(() => (UserType)null);
            enumValues = SimpleCache.Create(() =>
            {
                List<Tuple<string, string>> result = new List<Tuple<string, string>>();

                if (Tag == SymTagEnum.SymTagEnum)
                {
                    foreach (var enumValue in symbol.GetChildren())
                    {
                        result.Add(Tuple.Create(enumValue.name, enumValue.value.ToString()));
                    }
                }

                return result.ToArray();
            });
            namespaces = SimpleCache.Create(() => SymbolNameHelper.GetSymbolNamespaces(Name));
        }