189cb50c9SDimitry Andric //===- DebugFrameDataSubsection.cpp -----------------------------*- C++ -*-===// 289cb50c9SDimitry Andric // 389cb50c9SDimitry Andric // The LLVM Compiler Infrastructure 489cb50c9SDimitry Andric // 589cb50c9SDimitry Andric // This file is distributed under the University of Illinois Open Source 689cb50c9SDimitry Andric // License. See LICENSE.TXT for details. 789cb50c9SDimitry Andric // 889cb50c9SDimitry Andric //===----------------------------------------------------------------------===// 989cb50c9SDimitry Andric 1089cb50c9SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h" 1189cb50c9SDimitry Andric #include "llvm/DebugInfo/CodeView/CodeViewError.h" 1289cb50c9SDimitry Andric 1389cb50c9SDimitry Andric using namespace llvm; 1489cb50c9SDimitry Andric using namespace llvm::codeview; 1589cb50c9SDimitry Andric 1689cb50c9SDimitry Andric Error DebugFrameDataSubsectionRef::initialize(BinaryStreamReader Reader) { 1789cb50c9SDimitry Andric if (auto EC = Reader.readObject(RelocPtr)) 1889cb50c9SDimitry Andric return EC; 1989cb50c9SDimitry Andric if (Reader.bytesRemaining() % sizeof(FrameData) != 0) 2089cb50c9SDimitry Andric return make_error<CodeViewError>(cv_error_code::corrupt_record, 2189cb50c9SDimitry Andric "Invalid frame data record format!"); 2289cb50c9SDimitry Andric 2389cb50c9SDimitry Andric uint32_t Count = Reader.bytesRemaining() / sizeof(FrameData); 2489cb50c9SDimitry Andric if (auto EC = Reader.readArray(Frames, Count)) 2589cb50c9SDimitry Andric return EC; 2689cb50c9SDimitry Andric return Error::success(); 2789cb50c9SDimitry Andric } 2889cb50c9SDimitry Andric 2989cb50c9SDimitry Andric uint32_t DebugFrameDataSubsection::calculateSerializedSize() const { 3089cb50c9SDimitry Andric return 4 + sizeof(FrameData) * Frames.size(); 3189cb50c9SDimitry Andric } 3289cb50c9SDimitry Andric 3389cb50c9SDimitry Andric Error DebugFrameDataSubsection::commit(BinaryStreamWriter &Writer) const { 3489cb50c9SDimitry Andric if (auto EC = Writer.writeInteger<uint32_t>(0)) 3589cb50c9SDimitry Andric return EC; 3689cb50c9SDimitry Andric 3789cb50c9SDimitry Andric if (auto EC = Writer.writeArray(makeArrayRef(Frames))) 3889cb50c9SDimitry Andric return EC; 3989cb50c9SDimitry Andric return Error::success(); 4089cb50c9SDimitry Andric } 4189cb50c9SDimitry Andric 4289cb50c9SDimitry Andric void DebugFrameDataSubsection::addFrameData(const FrameData &Frame) { 4389cb50c9SDimitry Andric Frames.push_back(Frame); 4489cb50c9SDimitry Andric } 45