Skip to content

Commit

Permalink
[codeview] Add support for new types and symbols.
Browse files Browse the repository at this point in the history
This patch adds support for:

S_EXPORT
LF_BITFIELD

With this patch, I have run through a couple of gigabytes of PDB
files and cannot find a type or symbol that we do not understand.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270637 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Zachary Turner committed May 25, 2016
1 parent a02a9cb commit 8d473c6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
4 changes: 2 additions & 2 deletions include/llvm/DebugInfo/CodeView/CVTypeVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CVTypeVisitor {
DerivedThis->visitTypeBegin(Record.Type, RecordData);
switch (Record.Type) {
default:
DerivedThis->visitUnknownType(Record.Type);
DerivedThis->visitUnknownType(Record.Type, RecordData);
break;
case LF_FIELDLIST:
DerivedThis->visitFieldList(Record.Type, LeafData);
Expand Down Expand Up @@ -90,7 +90,7 @@ class CVTypeVisitor {
}

/// Action to take on unknown types. By default, they are ignored.
void visitUnknownType(TypeLeafKind Leaf) {}
void visitUnknownType(TypeLeafKind Leaf, ArrayRef<uint8_t> RecordData) {}

/// Paired begin/end actions for all types. Receives all record data,
/// including the fixed-length record prefix.
Expand Down
1 change: 0 additions & 1 deletion include/llvm/DebugInfo/CodeView/CodeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ enum class TypeRecordKind : uint16_t {
#include "TypeRecords.def"
// FIXME: Add serialization support
FieldList = 0x1203,
BitField = 0x1205,
};

/// Duplicate copy of the above enum, but using the official CV names. Useful
Expand Down
19 changes: 19 additions & 0 deletions include/llvm/DebugInfo/CodeView/TypeRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -705,17 +705,36 @@ class EnumRecord : public TagRecord {
TypeIndex UnderlyingType;
};

// LF_BITFIELD
class BitFieldRecord : public TypeRecord {
public:
BitFieldRecord(TypeIndex Type, uint8_t BitSize, uint8_t BitOffset)
: TypeRecord(TypeRecordKind::BitField), Type(Type), BitSize(BitSize),
BitOffset(BitOffset) {}

/// Rewrite member type indices with IndexMap. Returns false if a type index
/// is not in the map.
bool remapTypeIndices(ArrayRef<TypeIndex> IndexMap);

static ErrorOr<BitFieldRecord> deserialize(TypeRecordKind Kind,
ArrayRef<uint8_t> &Data) {
const Layout *L = nullptr;
CV_DESERIALIZE(Data, L);

return BitFieldRecord(L->Type, L->BitSize, L->BitOffset);
}

TypeIndex getType() const { return Type; }
uint8_t getBitOffset() const { return BitOffset; }
uint8_t getBitSize() const { return BitSize; }

private:
struct Layout {
TypeIndex Type;
uint8_t BitSize;
uint8_t BitOffset;
};

TypeIndex Type;
uint8_t BitSize;
uint8_t BitOffset;
Expand Down
3 changes: 2 additions & 1 deletion include/llvm/DebugInfo/CodeView/TypeRecords.def
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ TYPE_RECORD(LF_TYPESERVER2, 0x1515, TypeServer2)
TYPE_RECORD(LF_VFTABLE, 0x151d, VFTable)
TYPE_RECORD(LF_VTSHAPE, 0x000a, VFTableShape)

TYPE_RECORD(LF_BITFIELD, 0x1205, BitField)

// Member type records. These are generally not length prefixed, and appear
// inside of a field list record.
MEMBER_RECORD(LF_BCLASS, 0x1400, BaseClass)
Expand Down Expand Up @@ -156,7 +158,6 @@ CV_TYPE(LF_SKIP, 0x1200)
CV_TYPE(LF_DEFARG_ST, 0x1202)
CV_TYPE(LF_FIELDLIST, 0x1203)
CV_TYPE(LF_DERIVED, 0x1204)
CV_TYPE(LF_BITFIELD, 0x1205)
CV_TYPE(LF_DIMCONU, 0x1207)
CV_TYPE(LF_DIMCONLU, 0x1208)
CV_TYPE(LF_DIMVARU, 0x1209)
Expand Down
15 changes: 15 additions & 0 deletions lib/DebugInfo/CodeView/TypeDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class CVTypeDumperImpl : public CVTypeVisitor<CVTypeDumperImpl> {
#include "llvm/DebugInfo/CodeView/TypeRecords.def"

void visitUnknownMember(TypeLeafKind Leaf);
void visitUnknownType(TypeLeafKind Leaf, ArrayRef<uint8_t> LeafData);

void visitTypeBegin(TypeLeafKind Leaf, ArrayRef<uint8_t> LeafData);
void visitTypeEnd(TypeLeafKind Leaf, ArrayRef<uint8_t> LeafData);
Expand Down Expand Up @@ -493,6 +494,13 @@ void CVTypeDumperImpl::visitModifier(TypeLeafKind Leaf, ModifierRecord &Mod) {
Name = CVTD.saveName(TypeName);
}

void CVTypeDumperImpl::visitBitField(TypeLeafKind Leaf,
BitFieldRecord &BitField) {
printTypeIndex("Type", BitField.getType());
W.printNumber("BitSize", BitField.getBitSize());
W.printNumber("BitOffset", BitField.getBitOffset());
}

void CVTypeDumperImpl::visitVFTableShape(TypeLeafKind Leaf,
VFTableShapeRecord &Shape) {
W.printNumber("VFEntryCount", Shape.getEntryCount());
Expand Down Expand Up @@ -538,6 +546,13 @@ void CVTypeDumperImpl::visitUnknownMember(TypeLeafKind Leaf) {
W.printHex("UnknownMember", unsigned(Leaf));
}

void CVTypeDumperImpl::visitUnknownType(TypeLeafKind Leaf,
ArrayRef<uint8_t> RecordData) {
DictScope S(W, "UnknownType");
W.printEnum("Kind", uint16_t(Leaf), makeArrayRef(LeafTypeNames));
W.printNumber("Length", uint32_t(RecordData.size()));
}

void CVTypeDumperImpl::visitNestedType(TypeLeafKind Leaf,
NestedTypeRecord &Nested) {
DictScope S(W, "NestedType");
Expand Down
4 changes: 4 additions & 0 deletions lib/DebugInfo/CodeView/TypeRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ bool EnumRecord::remapTypeIndices(ArrayRef<TypeIndex> IndexMap) {
return Success;
}

bool BitFieldRecord::remapTypeIndices(ArrayRef<TypeIndex> IndexMap) {
return remapIndex(IndexMap, Type);
}

bool VFTableShapeRecord::remapTypeIndices(ArrayRef<TypeIndex> IndexMap) {
return true;
}
Expand Down

0 comments on commit 8d473c6

Please sign in to comment.