1 //===- DebugFrameDataSubsection.cpp -----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"
11 #include "llvm/DebugInfo/CodeView/CodeViewError.h"
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
))
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
))
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();
40 Size
+= sizeof(uint32_t);
44 Error
DebugFrameDataSubsection::commit(BinaryStreamWriter
&Writer
) const {
45 if (IncludeRelocPtr
) {
46 if (auto EC
= Writer
.writeInteger
<uint32_t>(0))
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
;
55 if (auto EC
= Writer
.writeArray(makeArrayRef(SortedFrames
)))
57 return Error::success();
60 void DebugFrameDataSubsection::addFrameData(const FrameData
&Frame
) {
61 Frames
.push_back(Frame
);