[llvm-exegesis][NFC] Fix typo
[llvm-complete.git] / lib / DebugInfo / CodeView / DebugFrameDataSubsection.cpp
blob5881bf177a55765b0c127c910c14cc40e2688708
1 //===- DebugFrameDataSubsection.cpp -----------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"
11 #include "llvm/DebugInfo/CodeView/CodeViewError.h"
13 using namespace llvm;
14 using namespace llvm::codeview;
16 Error DebugFrameDataSubsectionRef::initialize(BinaryStreamReader Reader) {
17 if (Reader.bytesRemaining() % sizeof(FrameData) != 0) {
18 if (auto EC = Reader.readObject(RelocPtr))
19 return EC;
22 if (Reader.bytesRemaining() % sizeof(FrameData) != 0)
23 return make_error<CodeViewError>(cv_error_code::corrupt_record,
24 "Invalid frame data record format!");
26 uint32_t Count = Reader.bytesRemaining() / sizeof(FrameData);
27 if (auto EC = Reader.readArray(Frames, Count))
28 return EC;
29 return Error::success();
32 Error DebugFrameDataSubsectionRef::initialize(BinaryStreamRef Section) {
33 BinaryStreamReader Reader(Section);
34 return initialize(Reader);
37 uint32_t DebugFrameDataSubsection::calculateSerializedSize() const {
38 uint32_t Size = sizeof(FrameData) * Frames.size();
39 if (IncludeRelocPtr)
40 Size += sizeof(uint32_t);
41 return Size;
44 Error DebugFrameDataSubsection::commit(BinaryStreamWriter &Writer) const {
45 if (IncludeRelocPtr) {
46 if (auto EC = Writer.writeInteger<uint32_t>(0))
47 return EC;
50 std::vector<FrameData> SortedFrames(Frames.begin(), Frames.end());
51 std::sort(SortedFrames.begin(), SortedFrames.end(),
52 [](const FrameData &LHS, const FrameData &RHS) {
53 return LHS.RvaStart < RHS.RvaStart;
54 });
55 if (auto EC = Writer.writeArray(makeArrayRef(SortedFrames)))
56 return EC;
57 return Error::success();
60 void DebugFrameDataSubsection::addFrameData(const FrameData &Frame) {
61 Frames.push_back(Frame);