summaryrefslogtreecommitdiff
path: root/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp')
-rw-r--r--lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp28
1 files changed, 11 insertions, 17 deletions
diff --git a/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp b/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp
index cfd1c5d3ab0c..e9124e68fe82 100644
--- a/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp
+++ b/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp
@@ -34,14 +34,6 @@ Error DebugSubsectionRecord::initialize(BinaryStreamRef Stream,
DebugSubsectionKind Kind =
static_cast<DebugSubsectionKind>(uint32_t(Header->Kind));
- switch (Kind) {
- case DebugSubsectionKind::FileChecksums:
- case DebugSubsectionKind::Lines:
- case DebugSubsectionKind::InlineeLines:
- break;
- default:
- llvm_unreachable("Unexpected debug fragment kind!");
- }
if (auto EC = Reader.readStreamRef(Info.Data, Header->Length))
return EC;
Info.Container = Container;
@@ -50,9 +42,7 @@ Error DebugSubsectionRecord::initialize(BinaryStreamRef Stream,
}
uint32_t DebugSubsectionRecord::getRecordLength() const {
- uint32_t Result = sizeof(DebugSubsectionHeader) + Data.getLength();
- assert(Result % alignOf(Container) == 0);
- return Result;
+ return sizeof(DebugSubsectionHeader) + Data.getLength();
}
DebugSubsectionKind DebugSubsectionRecord::kind() const { return Kind; }
@@ -64,25 +54,29 @@ DebugSubsectionRecordBuilder::DebugSubsectionRecordBuilder(
: Subsection(std::move(Subsection)), Container(Container) {}
uint32_t DebugSubsectionRecordBuilder::calculateSerializedLength() {
- uint32_t Size =
- sizeof(DebugSubsectionHeader) +
- alignTo(Subsection->calculateSerializedSize(), alignOf(Container));
+ // The length of the entire subsection is always padded to 4 bytes, regardless
+ // of the container kind.
+ uint32_t Size = sizeof(DebugSubsectionHeader) +
+ alignTo(Subsection->calculateSerializedSize(), 4);
return Size;
}
-Error DebugSubsectionRecordBuilder::commit(BinaryStreamWriter &Writer) {
+Error DebugSubsectionRecordBuilder::commit(BinaryStreamWriter &Writer) const {
assert(Writer.getOffset() % alignOf(Container) == 0 &&
"Debug Subsection not properly aligned");
DebugSubsectionHeader Header;
Header.Kind = uint32_t(Subsection->kind());
- Header.Length = calculateSerializedLength() - sizeof(DebugSubsectionHeader);
+ // The value written into the Header's Length field is only padded to the
+ // container's alignment
+ Header.Length =
+ alignTo(Subsection->calculateSerializedSize(), alignOf(Container));
if (auto EC = Writer.writeObject(Header))
return EC;
if (auto EC = Subsection->commit(Writer))
return EC;
- if (auto EC = Writer.padToAlignment(alignOf(Container)))
+ if (auto EC = Writer.padToAlignment(4))
return EC;
return Error::success();