summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/PDB/Native
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2018-09-18 16:35:05 +0000
committerZachary Turner <zturner@google.com>2018-09-18 16:35:05 +0000
commitc41ce8355f88ce522dabde2b435bfe83d550a379 (patch)
treee3606b39394096113cd7d0e3c4b1c8ecd644b650 /llvm/lib/DebugInfo/PDB/Native
parentc1e2f39b3503869bd471a867c177f6486da5fee0 (diff)
downloadbcm5719-llvm-c41ce8355f88ce522dabde2b435bfe83d550a379.tar.gz
bcm5719-llvm-c41ce8355f88ce522dabde2b435bfe83d550a379.zip
[PDB] Better support for enumerating pointer types.
There were several issues with the previous implementation. 1) There were no tests. 2) We didn't support creating PDBSymbolTypePointer records for builtin types since those aren't described by LF_POINTER records. 3) We didn't support a wide enough variety of builtin types even ignoring pointers. This patch fixes all of these issues. In order to add tests, it's helpful to be able to ignore the symbol index id hierarchy because it makes the golden output from the DIA version not match our output, so I've extended the dumper to disable dumping of id fields. llvm-svn: 342493
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Native')
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/NativeCompilandSymbol.cpp11
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp11
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/NativeSymbolEnumerator.cpp17
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/NativeTypeBuiltin.cpp5
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/NativeTypeEnum.cpp17
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/NativeTypePointer.cpp79
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp24
7 files changed, 122 insertions, 42 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeCompilandSymbol.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeCompilandSymbol.cpp
index 64ddf75c6d2..efa70b0e7bd 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeCompilandSymbol.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeCompilandSymbol.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h"
+#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/ADT/STLExtras.h"
@@ -23,10 +24,14 @@ PDB_SymType NativeCompilandSymbol::getSymTag() const {
return PDB_SymType::Compiland;
}
-void NativeCompilandSymbol::dump(raw_ostream &OS, int Indent) const {
- NativeRawSymbol::dump(OS, Indent);
+void NativeCompilandSymbol::dump(raw_ostream &OS, int Indent,
+ PdbSymbolIdField ShowIdFields,
+ PdbSymbolIdField RecurseIdFields) const {
+ NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
- dumpSymbolField(OS, "lexicalParentId", 0, Indent);
+ dumpSymbolIdField(OS, "lexicalParentId", 0, Indent, Session,
+ PdbSymbolIdField::LexicalParent, ShowIdFields,
+ RecurseIdFields);
dumpSymbolField(OS, "libraryName", getLibraryName(), Indent);
dumpSymbolField(OS, "name", getName(), Indent);
dumpSymbolField(OS, "editAndContinueEnabled", isEditAndContinueEnabled(),
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp
index e36d5343a41..1a8c75db998 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp
@@ -9,6 +9,7 @@
#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h"
#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
+#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
#include "llvm/Support/FormatVariadic.h"
@@ -19,9 +20,13 @@ NativeRawSymbol::NativeRawSymbol(NativeSession &PDBSession, PDB_SymType Tag,
SymIndexId SymbolId)
: Session(PDBSession), Tag(Tag), SymbolId(SymbolId) {}
-void NativeRawSymbol::dump(raw_ostream &OS, int Indent) const {
- dumpSymbolField(OS, "symIndexId", SymbolId, Indent);
- dumpSymbolField(OS, "symTag", static_cast<uint32_t>(Tag), Indent);
+void NativeRawSymbol::dump(raw_ostream &OS, int Indent,
+ PdbSymbolIdField ShowIdFields,
+ PdbSymbolIdField RecurseIdFields) const {
+ dumpSymbolIdField(OS, "symIndexId", SymbolId, Indent, Session,
+ PdbSymbolIdField::SymIndexId, ShowIdFields,
+ RecurseIdFields);
+ dumpSymbolField(OS, "symTag", Tag, Indent);
}
std::unique_ptr<IPDBEnumSymbols>
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeSymbolEnumerator.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSymbolEnumerator.cpp
index 18b13b07607..6ebb8cae3a6 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeSymbolEnumerator.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeSymbolEnumerator.cpp
@@ -25,12 +25,19 @@ NativeSymbolEnumerator::NativeSymbolEnumerator(
NativeSymbolEnumerator::~NativeSymbolEnumerator() {}
-void NativeSymbolEnumerator::dump(raw_ostream &OS, int Indent) const {
- NativeRawSymbol::dump(OS, Indent);
- dumpSymbolField(OS, "classParentId", getClassParentId(), Indent);
- dumpSymbolField(OS, "lexicalParentId", getLexicalParentId(), Indent);
+void NativeSymbolEnumerator::dump(raw_ostream &OS, int Indent,
+ PdbSymbolIdField ShowIdFields,
+ PdbSymbolIdField RecurseIdFields) const {
+ NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
+ dumpSymbolIdField(OS, "classParentId", getClassParentId(), Indent, Session,
+ PdbSymbolIdField::ClassParent, ShowIdFields,
+ RecurseIdFields);
+ dumpSymbolIdField(OS, "lexicalParentId", getLexicalParentId(), Indent,
+ Session, PdbSymbolIdField::LexicalParent, ShowIdFields,
+ RecurseIdFields);
dumpSymbolField(OS, "name", getName(), Indent);
- dumpSymbolField(OS, "typeId", getTypeId(), Indent);
+ dumpSymbolIdField(OS, "typeId", getTypeId(), Indent, Session,
+ PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
dumpSymbolField(OS, "dataKind", getDataKind(), Indent);
dumpSymbolField(OS, "locationType", getLocationType(), Indent);
dumpSymbolField(OS, "constType", isConstType(), Indent);
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeTypeBuiltin.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeTypeBuiltin.cpp
index a9197b7afda..824d9bd8a94 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeTypeBuiltin.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeTypeBuiltin.cpp
@@ -21,8 +21,9 @@ NativeTypeBuiltin::NativeTypeBuiltin(NativeSession &PDBSession, SymIndexId Id,
NativeTypeBuiltin::~NativeTypeBuiltin() {}
-void NativeTypeBuiltin::dump(raw_ostream &OS, int Indent) const {
-}
+void NativeTypeBuiltin::dump(raw_ostream &OS, int Indent,
+ PdbSymbolIdField ShowIdFields,
+ PdbSymbolIdField RecurseIdFields) const {}
PDB_SymType NativeTypeBuiltin::getSymTag() const {
return PDB_SymType::BuiltinType;
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeTypeEnum.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeTypeEnum.cpp
index e833b6dddd9..0994be4af42 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeTypeEnum.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeTypeEnum.cpp
@@ -130,16 +130,23 @@ NativeTypeEnum::NativeTypeEnum(NativeSession &Session, SymIndexId Id,
NativeTypeEnum::~NativeTypeEnum() {}
-void NativeTypeEnum::dump(raw_ostream &OS, int Indent) const {
- NativeRawSymbol::dump(OS, Indent);
+void NativeTypeEnum::dump(raw_ostream &OS, int Indent,
+ PdbSymbolIdField ShowIdFields,
+ PdbSymbolIdField RecurseIdFields) const {
+ NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
dumpSymbolField(OS, "baseType", static_cast<uint32_t>(getBuiltinType()),
Indent);
- dumpSymbolField(OS, "lexicalParentId", 0, Indent);
+ dumpSymbolIdField(OS, "lexicalParentId", 0, Indent, Session,
+ PdbSymbolIdField::LexicalParent, ShowIdFields,
+ RecurseIdFields);
dumpSymbolField(OS, "name", getName(), Indent);
- dumpSymbolField(OS, "typeId", getTypeId(), Indent);
+ dumpSymbolIdField(OS, "typeId", getTypeId(), Indent, Session,
+ PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
if (Modifiers.hasValue())
- dumpSymbolField(OS, "unmodifiedTypeId", getUnmodifiedTypeId(), Indent);
+ dumpSymbolIdField(OS, "unmodifiedTypeId", getUnmodifiedTypeId(), Indent,
+ Session, PdbSymbolIdField::UnmodifiedType, ShowIdFields,
+ RecurseIdFields);
dumpSymbolField(OS, "length", getLength(), Indent);
dumpSymbolField(OS, "constructor", hasConstructor(), Indent);
dumpSymbolField(OS, "constType", isConstType(), Indent);
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeTypePointer.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeTypePointer.cpp
index f41d0a2e493..4545f7ea769 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeTypePointer.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeTypePointer.cpp
@@ -18,6 +18,13 @@ using namespace llvm::codeview;
using namespace llvm::pdb;
NativeTypePointer::NativeTypePointer(NativeSession &Session, SymIndexId Id,
+ codeview::TypeIndex TI)
+ : NativeRawSymbol(Session, PDB_SymType::PointerType, Id), TI(TI) {
+ assert(TI.isSimple());
+ assert(TI.getSimpleMode() != SimpleTypeMode::Direct);
+}
+
+NativeTypePointer::NativeTypePointer(NativeSession &Session, SymIndexId Id,
codeview::TypeIndex TI,
codeview::PointerRecord Record)
: NativeRawSymbol(Session, PDB_SymType::PointerType, Id), TI(TI),
@@ -25,11 +32,16 @@ NativeTypePointer::NativeTypePointer(NativeSession &Session, SymIndexId Id,
NativeTypePointer::~NativeTypePointer() {}
-void NativeTypePointer::dump(raw_ostream &OS, int Indent) const {
- NativeRawSymbol::dump(OS, Indent);
+void NativeTypePointer::dump(raw_ostream &OS, int Indent,
+ PdbSymbolIdField ShowIdFields,
+ PdbSymbolIdField RecurseIdFields) const {
+ NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
- dumpSymbolField(OS, "lexicalParentId", 0, Indent);
- dumpSymbolField(OS, "typeId", getTypeId(), Indent);
+ dumpSymbolIdField(OS, "lexicalParentId", 0, Indent, Session,
+ PdbSymbolIdField::LexicalParent, ShowIdFields,
+ RecurseIdFields);
+ dumpSymbolIdField(OS, "typeId", getTypeId(), Indent, Session,
+ PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
dumpSymbolField(OS, "length", getLength(), Indent);
dumpSymbolField(OS, "constType", isConstType(), Indent);
dumpSymbolField(OS, "isPointerToDataMember", isPointerToDataMember(), Indent);
@@ -42,45 +54,82 @@ void NativeTypePointer::dump(raw_ostream &OS, int Indent) const {
dumpSymbolField(OS, "volatileType", isVolatileType(), Indent);
}
-uint64_t NativeTypePointer::getLength() const { return Record.getSize(); }
+uint64_t NativeTypePointer::getLength() const {
+ if (Record)
+ return Record->getSize();
+
+ switch (TI.getSimpleMode()) {
+ case SimpleTypeMode::NearPointer:
+ case SimpleTypeMode::FarPointer:
+ case SimpleTypeMode::HugePointer:
+ return 2;
+ case SimpleTypeMode::NearPointer32:
+ case SimpleTypeMode::FarPointer32:
+ return 4;
+ case SimpleTypeMode::NearPointer64:
+ return 8;
+ case SimpleTypeMode::NearPointer128:
+ return 16;
+ default:
+ assert(false && "invalid simple type mode!");
+ }
+ return 0;
+}
SymIndexId NativeTypePointer::getTypeId() const {
// This is the pointee SymIndexId.
- return Session.getSymbolCache().findSymbolByTypeIndex(Record.ReferentType);
+ TypeIndex Referent = Record ? Record->ReferentType : TI.makeDirect();
+
+ return Session.getSymbolCache().findSymbolByTypeIndex(Referent);
}
bool NativeTypePointer::isReference() const {
- return Record.getMode() == PointerMode::LValueReference ||
- isRValueReference();
+ if (!Record)
+ return false;
+ return Record->getMode() == PointerMode::LValueReference;
}
bool NativeTypePointer::isRValueReference() const {
- return Record.getMode() == PointerMode::RValueReference;
+ if (!Record)
+ return false;
+ return Record->getMode() == PointerMode::RValueReference;
}
bool NativeTypePointer::isPointerToDataMember() const {
- return Record.getMode() == PointerMode::PointerToDataMember;
+ if (!Record)
+ return false;
+ return Record->getMode() == PointerMode::PointerToDataMember;
}
bool NativeTypePointer::isPointerToMemberFunction() const {
- return Record.getMode() == PointerMode::PointerToMemberFunction;
+ if (!Record)
+ return false;
+ return Record->getMode() == PointerMode::PointerToMemberFunction;
}
bool NativeTypePointer::isConstType() const {
- return (Record.getOptions() & PointerOptions::Const) != PointerOptions::None;
+ if (!Record)
+ return false;
+ return (Record->getOptions() & PointerOptions::Const) != PointerOptions::None;
}
bool NativeTypePointer::isRestrictedType() const {
- return (Record.getOptions() & PointerOptions::Restrict) !=
+ if (!Record)
+ return false;
+ return (Record->getOptions() & PointerOptions::Restrict) !=
PointerOptions::None;
}
bool NativeTypePointer::isVolatileType() const {
- return (Record.getOptions() & PointerOptions::Volatile) !=
+ if (!Record)
+ return false;
+ return (Record->getOptions() & PointerOptions::Volatile) !=
PointerOptions::None;
}
bool NativeTypePointer::isUnalignedType() const {
- return (Record.getOptions() & PointerOptions::Unaligned) !=
+ if (!Record)
+ return false;
+ return (Record->getOptions() & PointerOptions::Unaligned) !=
PointerOptions::None;
}
diff --git a/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp b/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
index a4b1ecfb770..a661227f9b6 100644
--- a/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
@@ -65,18 +65,20 @@ SymbolCache::createTypeEnumerator(codeview::TypeLeafKind Kind) {
SymIndexId SymbolCache::createSimpleType(TypeIndex Index,
ModifierOptions Mods) {
- // FIXME: We will eventually need to handle pointers to other simple types,
- // which are still simple types in the world of CodeView TypeIndexes.
- if (Index.getSimpleMode() != codeview::SimpleTypeMode::Direct)
- return 0;
+ if (Index.getSimpleMode() != codeview::SimpleTypeMode::Direct) {
+ SymIndexId Id = Cache.size();
+ Cache.emplace_back(
+ llvm::make_unique<NativeTypePointer>(Session, Id, Index));
+ return Id;
+ }
+ SymIndexId Id = Cache.size();
const auto Kind = Index.getSimpleKind();
const auto It = std::find_if(
std::begin(BuiltinTypes), std::end(BuiltinTypes),
[Kind](const BuiltinTypeEntry &Builtin) { return Builtin.Kind == Kind; });
if (It == std::end(BuiltinTypes))
return 0;
- SymIndexId Id = Cache.size();
Cache.emplace_back(llvm::make_unique<NativeTypeBuiltin>(Session, Id, Mods,
It->Type, It->Size));
TypeIndexToSymbolId[Index] = Id;
@@ -175,12 +177,16 @@ SymbolCache::getSymbolById(SymIndexId SymbolId) const {
assert(SymbolId < Cache.size());
// Id 0 is reserved.
- if (SymbolId == 0)
+ if (SymbolId == 0 || SymbolId >= Cache.size())
+ return nullptr;
+
+ // Make sure to handle the case where we've inserted a placeholder symbol
+ // for types we don't yet suppport.
+ NativeRawSymbol *NRS = Cache[SymbolId].get();
+ if (!NRS)
return nullptr;
- // If the caller has a SymbolId, it'd better be in our SymbolCache.
- return SymbolId < Cache.size() ? PDBSymbol::create(Session, *Cache[SymbolId])
- : nullptr;
+ return PDBSymbol::create(Session, *NRS);
}
NativeRawSymbol &SymbolCache::getNativeSymbolById(SymIndexId SymbolId) const {
OpenPOWER on IntegriCloud