1 //===- DebugFrameDataSubsection.cpp -----------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"
10 #include "llvm/DebugInfo/CodeView/CodeViewError.h"
11 #include "llvm/Support/BinaryStreamReader.h"
12 #include "llvm/Support/BinaryStreamWriter.h"
15 using namespace llvm::codeview
;
17 Error
DebugFrameDataSubsectionRef::initialize(BinaryStreamReader Reader
) {
18 if (Reader
.bytesRemaining() % sizeof(FrameData
) != 0) {
19 if (auto EC
= Reader
.readObject(RelocPtr
))
23 if (Reader
.bytesRemaining() % sizeof(FrameData
) != 0)
24 return make_error
<CodeViewError
>(cv_error_code::corrupt_record
,
25 "Invalid frame data record format!");
27 uint32_t Count
= Reader
.bytesRemaining() / sizeof(FrameData
);
28 if (auto EC
= Reader
.readArray(Frames
, Count
))
30 return Error::success();
33 Error
DebugFrameDataSubsectionRef::initialize(BinaryStreamRef Section
) {
34 BinaryStreamReader
Reader(Section
);
35 return initialize(Reader
);
38 uint32_t DebugFrameDataSubsection::calculateSerializedSize() const {
39 uint32_t Size
= sizeof(FrameData
) * Frames
.size();
41 Size
+= sizeof(uint32_t);
45 Error
DebugFrameDataSubsection::commit(BinaryStreamWriter
&Writer
) const {
46 if (IncludeRelocPtr
) {
47 if (auto EC
= Writer
.writeInteger
<uint32_t>(0))
51 std::vector
<FrameData
> SortedFrames(Frames
.begin(), Frames
.end());
52 llvm::sort(SortedFrames
, [](const FrameData
&LHS
, const FrameData
&RHS
) {
53 return LHS
.RvaStart
< RHS
.RvaStart
;
55 if (auto EC
= Writer
.writeArray(ArrayRef(SortedFrames
)))
57 return Error::success();
60 void DebugFrameDataSubsection::addFrameData(const FrameData
&Frame
) {
61 Frames
.push_back(Frame
);