diff options
| author | Zachary Turner <zturner@google.com> | 2018-09-21 22:36:04 +0000 |
|---|---|---|
| committer | Zachary Turner <zturner@google.com> | 2018-09-21 22:36:04 +0000 |
| commit | 355ffb0032182e74f64349dc7e4b941147bac2a2 (patch) | |
| tree | 94e7412254a486f98b5faf0ee6e0c8ae58ead533 /llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp | |
| parent | 10febb0779ec74ed9090bcc11667567910a807d5 (diff) | |
| download | bcm5719-llvm-355ffb0032182e74f64349dc7e4b941147bac2a2.tar.gz bcm5719-llvm-355ffb0032182e74f64349dc7e4b941147bac2a2.zip | |
[PDB] Add native reading support for UDT / class types.
This allows the native reader to find records of class/struct/
union type and dump them. This behavior is tested by using the
diadump subcommand against golden output produced by actual DIA
SDK on the same PDB file, and again using pretty -native to
confirm that we actually dump the classes. We don't find class
members or anything like that yet, for now it's just the class
itself.
llvm-svn: 342779
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp')
| -rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp | 80 |
1 files changed, 50 insertions, 30 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp b/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp index d714177509d..4fd7adf1632 100644 --- a/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp @@ -1,6 +1,7 @@ #include "llvm/DebugInfo/PDB/Native/SymbolCache.h" #include "llvm/DebugInfo/CodeView/TypeDeserializer.h" +#include "llvm/DebugInfo/CodeView/TypeRecordHelpers.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" #include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h" #include "llvm/DebugInfo/PDB/Native/NativeEnumTypes.h" @@ -9,6 +10,7 @@ #include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h" #include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h" #include "llvm/DebugInfo/PDB/Native/NativeTypePointer.h" +#include "llvm/DebugInfo/PDB/Native/NativeTypeUDT.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/TpiStream.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" @@ -50,10 +52,18 @@ SymbolCache::SymbolCache(NativeSession &Session, DbiStream *Dbi) if (Dbi) Compilands.resize(Dbi->modules().getModuleCount()); + + auto &Tpi = cantFail(Session.getPDBFile().getPDBTpiStream()); + Tpi.buildHashMap(); +} + +std::unique_ptr<IPDBEnumSymbols> +SymbolCache::createTypeEnumerator(TypeLeafKind Kind) { + return createTypeEnumerator(std::vector<TypeLeafKind>{Kind}); } std::unique_ptr<IPDBEnumSymbols> -SymbolCache::createTypeEnumerator(codeview::TypeLeafKind Kind) { +SymbolCache::createTypeEnumerator(std::vector<TypeLeafKind> Kinds) { auto Tpi = Session.getPDBFile().getPDBTpiStream(); if (!Tpi) { consumeError(Tpi.takeError()); @@ -61,7 +71,7 @@ SymbolCache::createTypeEnumerator(codeview::TypeLeafKind Kind) { } auto &Types = Tpi->typeCollection(); return std::unique_ptr<IPDBEnumSymbols>( - new NativeEnumTypes(Session, Types, Kind)); + new NativeEnumTypes(Session, Types, std::move(Kinds))); } SymIndexId SymbolCache::createSimpleType(TypeIndex Index, @@ -98,38 +108,24 @@ SymbolCache::createSymbolForModifiedType(codeview::TypeIndex ModifierTI, if (Record.ModifiedType.isSimple()) return createSimpleType(Record.ModifiedType, Record.Modifiers); - auto Tpi = Session.getPDBFile().getPDBTpiStream(); - if (!Tpi) { - consumeError(Tpi.takeError()); - return 0; - } - codeview::LazyRandomTypeCollection &Types = Tpi->typeCollection(); - - codeview::CVType UnmodifiedType = Types.getType(Record.ModifiedType); - - switch (UnmodifiedType.kind()) { - case LF_ENUM: { - EnumRecord ER; - if (auto EC = - TypeDeserializer::deserializeAs<EnumRecord>(UnmodifiedType, ER)) { - consumeError(std::move(EC)); - return 0; - } - return createSymbol<NativeTypeEnum>(Record.ModifiedType, std::move(Record), - std::move(ER)); - } - case LF_STRUCTURE: - case LF_UNION: - case LF_CLASS: - // FIXME: Handle these - break; + // Make sure we create and cache a record for the unmodified type. + SymIndexId UnmodifiedId = findSymbolByTypeIndex(Record.ModifiedType); + NativeRawSymbol &UnmodifiedNRS = *Cache[UnmodifiedId]; + + switch (UnmodifiedNRS.getSymTag()) { + case PDB_SymType::Enum: + return createSymbol<NativeTypeEnum>( + static_cast<NativeTypeEnum &>(UnmodifiedNRS), std::move(Record)); + case PDB_SymType::UDT: + return createSymbol<NativeTypeUDT>( + static_cast<NativeTypeUDT &>(UnmodifiedNRS), std::move(Record)); default: // No other types can be modified. (LF_POINTER, for example, records // its modifiers a different way. assert(false && "Invalid LF_MODIFIER record"); break; } - return createSymbolPlaceholder(); + return 0; } SymIndexId SymbolCache::findSymbolByTypeIndex(codeview::TypeIndex Index) { @@ -150,13 +146,37 @@ SymIndexId SymbolCache::findSymbolByTypeIndex(codeview::TypeIndex Index) { } codeview::LazyRandomTypeCollection &Types = Tpi->typeCollection(); codeview::CVType CVT = Types.getType(Index); - // TODO(amccarth): Make this handle all types. - SymIndexId Id = 0; + if (isUdtForwardRef(CVT)) { + Expected<TypeIndex> EFD = Tpi->findFullDeclForForwardRef(Index); + + if (!EFD) + consumeError(EFD.takeError()); + else if (*EFD != Index) { + assert(!isUdtForwardRef(Types.getType(*EFD))); + SymIndexId Result = findSymbolByTypeIndex(*EFD); + // Record a mapping from ForwardRef -> SymIndex of complete type so that + // we'll take the fast path next time. + TypeIndexToSymbolId[Index] = Result; + return Result; + } + } + + // At this point if we still have a forward ref udt it means the full decl was + // not in the PDB. We just have to deal with it and use the forward ref. + SymIndexId Id = 0; switch (CVT.kind()) { case codeview::LF_ENUM: Id = createSymbolForType<NativeTypeEnum, EnumRecord>(Index, std::move(CVT)); break; + case codeview::LF_CLASS: + case codeview::LF_STRUCTURE: + case codeview::LF_INTERFACE: + Id = createSymbolForType<NativeTypeUDT, ClassRecord>(Index, std::move(CVT)); + break; + case codeview::LF_UNION: + Id = createSymbolForType<NativeTypeUDT, UnionRecord>(Index, std::move(CVT)); + break; case codeview::LF_POINTER: Id = createSymbolForType<NativeTypePointer, PointerRecord>(Index, std::move(CVT)); |

