public static string GenerateClassCodeTypeInfo(Symbol symbol, string typeName) { StringBuilder sb = new StringBuilder(); foreach (var module in GetSymbolModuleNames(symbol)) { sb.Append(string.Format("\"{0}!{1}\", ", module, typeName)); } sb.Length -= 2; return sb.ToString(); }
internal static IEnumerable<string> GetSymbolModuleNames(Symbol symbol) { Symbol[] symbols; if (deduplicatedSymbols.TryGetValue(symbol.Name, out symbols)) foreach (var s in symbols) { if (symbol.Size > 0 && s.Size == 0) continue; yield return s.Module.Name; } else yield return symbol.Module.Name; }
public static UserType GetUserType(Symbol symbol) { if (symbol != null) { if (symbol.UserType == null) { symbol = GetSymbol(symbol.Name, symbol.Module); } if (symbol.UserType == null && symbol.Name.EndsWith("*")) { // Try to use Pointer symbol = GetSymbol(symbol.Name.Substring(0, symbol.Name.Length - 1), symbol.Module); } else if (symbol.UserType == null && symbol.Tag == SymTagEnum.SymTagArrayType) { symbol = GetSymbol(symbol.ElementType.Name, symbol.Module); } return symbol.UserType; } return null; }
/// <summary> /// Gets the symbol from the cache or adds new entry in the cache if symbol wasn't previously found. /// </summary> /// <param name="symbol">The symbol.</param> internal Symbol GetSymbol(IDiaSymbol symbol) { if (symbol == null) return null; Symbol s; uint symbolId = symbol.symIndexId; if (!symbolById.TryGetValue(symbolId, out s)) { s = new Symbol(this, symbol); lock (this) { Symbol previousSymbol = null; symbolById.TryAdd(symbolId, s); if (s.Tag != SymTagEnum.SymTagExe) if (!symbolByName.TryGetValue(s.Name, out previousSymbol)) { symbolByName.TryAdd(s.Name, s); } else { previousSymbol.LinkSymbols(s); } } s.InitializeCache(); } return s; }
internal static IEnumerable<SymbolField> GetSymbolStaticFields(Symbol symbol) { Symbol[] symbols; if (!deduplicatedSymbols.TryGetValue(symbol.Name, out symbols)) symbols = new Symbol[] { symbol }; foreach (var s in symbols) foreach (var field in s.Fields) if (field.DataKind == DataKind.StaticMember && field.IsValidStatic) yield return field; }
internal static IEnumerable<Symbol> GetSymbolStaticFieldsSymbols(Symbol symbol) { Symbol[] symbols; if (!deduplicatedSymbols.TryGetValue(symbol.Name, out symbols)) yield return symbol; else foreach (var s in symbols) foreach (var field in s.Fields) if (field.DataKind == DataKind.StaticMember && field.IsValidStatic) { yield return s; break; } }
/// <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); }
/// <summary> /// Links the symbols. /// </summary> internal void LinkSymbols(Symbol s) { s.baseClasses = baseClasses; s.elementType = elementType; s.fields = fields; s.pointerType = pointerType; s.userType = userType; }
/// <summary> /// Creates the lookup name for the specified symbol. /// This helps grouping template symbols together. /// </summary> /// <param name="symbol">The symbol.</param> public static string CreateLookupNameForSymbol(Symbol symbol) { return string.Join("::", symbol.Namespaces.Select(r => SymbolNameHelper.CreateLookupForNamespace(r))); }