Path: blob/main/contrib/llvm-project/llvm/lib/DebugInfo/CodeView/DebugFrameDataSubsection.cpp
35271 views
//===- DebugFrameDataSubsection.cpp -----------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"9#include "llvm/DebugInfo/CodeView/CodeViewError.h"10#include "llvm/Support/BinaryStreamReader.h"11#include "llvm/Support/BinaryStreamWriter.h"1213using namespace llvm;14using namespace llvm::codeview;1516Error DebugFrameDataSubsectionRef::initialize(BinaryStreamReader Reader) {17if (Reader.bytesRemaining() % sizeof(FrameData) != 0) {18if (auto EC = Reader.readObject(RelocPtr))19return EC;20}2122if (Reader.bytesRemaining() % sizeof(FrameData) != 0)23return make_error<CodeViewError>(cv_error_code::corrupt_record,24"Invalid frame data record format!");2526uint32_t Count = Reader.bytesRemaining() / sizeof(FrameData);27if (auto EC = Reader.readArray(Frames, Count))28return EC;29return Error::success();30}3132Error DebugFrameDataSubsectionRef::initialize(BinaryStreamRef Section) {33BinaryStreamReader Reader(Section);34return initialize(Reader);35}3637uint32_t DebugFrameDataSubsection::calculateSerializedSize() const {38uint32_t Size = sizeof(FrameData) * Frames.size();39if (IncludeRelocPtr)40Size += sizeof(uint32_t);41return Size;42}4344Error DebugFrameDataSubsection::commit(BinaryStreamWriter &Writer) const {45if (IncludeRelocPtr) {46if (auto EC = Writer.writeInteger<uint32_t>(0))47return EC;48}4950std::vector<FrameData> SortedFrames(Frames.begin(), Frames.end());51llvm::sort(SortedFrames, [](const FrameData &LHS, const FrameData &RHS) {52return LHS.RvaStart < RHS.RvaStart;53});54if (auto EC = Writer.writeArray(ArrayRef(SortedFrames)))55return EC;56return Error::success();57}5859void DebugFrameDataSubsection::addFrameData(const FrameData &Frame) {60Frames.push_back(Frame);61}626364