[Offload] Fix offload-info interface
[llvm-project.git] / llvm / lib / DebugInfo / CodeView / DebugFrameDataSubsection.cpp
blobbb3a838d3ec0c0c9bf5a4a94f34d9c084e1aa90a
1 //===- DebugFrameDataSubsection.cpp -----------------------------*- C++ -*-===//
2 //
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
6 //
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"
14 using namespace llvm;
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))
20 return EC;
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))
29 return EC;
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();
40 if (IncludeRelocPtr)
41 Size += sizeof(uint32_t);
42 return Size;
45 Error DebugFrameDataSubsection::commit(BinaryStreamWriter &Writer) const {
46 if (IncludeRelocPtr) {
47 if (auto EC = Writer.writeInteger<uint32_t>(0))
48 return EC;
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;
54 });
55 if (auto EC = Writer.writeArray(ArrayRef(SortedFrames)))
56 return EC;
57 return Error::success();
60 void DebugFrameDataSubsection::addFrameData(const FrameData &Frame) {
61 Frames.push_back(Frame);