2017-05-31 01:13:33 +08:00
|
|
|
//===- DebugFrameDataSubsection.cpp -----------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-05-31 01:13:33 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"
|
|
|
|
#include "llvm/DebugInfo/CodeView/CodeViewError.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::codeview;
|
|
|
|
|
|
|
|
Error DebugFrameDataSubsectionRef::initialize(BinaryStreamReader Reader) {
|
2018-09-12 06:35:01 +08:00
|
|
|
if (Reader.bytesRemaining() % sizeof(FrameData) != 0) {
|
|
|
|
if (auto EC = Reader.readObject(RelocPtr))
|
|
|
|
return EC;
|
|
|
|
}
|
|
|
|
|
2017-05-31 01:13:33 +08:00
|
|
|
if (Reader.bytesRemaining() % sizeof(FrameData) != 0)
|
|
|
|
return make_error<CodeViewError>(cv_error_code::corrupt_record,
|
|
|
|
"Invalid frame data record format!");
|
|
|
|
|
|
|
|
uint32_t Count = Reader.bytesRemaining() / sizeof(FrameData);
|
|
|
|
if (auto EC = Reader.readArray(Frames, Count))
|
|
|
|
return EC;
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2018-09-12 06:35:01 +08:00
|
|
|
Error DebugFrameDataSubsectionRef::initialize(BinaryStreamRef Section) {
|
|
|
|
BinaryStreamReader Reader(Section);
|
|
|
|
return initialize(Reader);
|
|
|
|
}
|
|
|
|
|
2017-05-31 01:13:33 +08:00
|
|
|
uint32_t DebugFrameDataSubsection::calculateSerializedSize() const {
|
2018-09-12 06:35:01 +08:00
|
|
|
uint32_t Size = sizeof(FrameData) * Frames.size();
|
|
|
|
if (IncludeRelocPtr)
|
|
|
|
Size += sizeof(uint32_t);
|
|
|
|
return Size;
|
2017-05-31 01:13:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Error DebugFrameDataSubsection::commit(BinaryStreamWriter &Writer) const {
|
2018-09-12 06:35:01 +08:00
|
|
|
if (IncludeRelocPtr) {
|
|
|
|
if (auto EC = Writer.writeInteger<uint32_t>(0))
|
|
|
|
return EC;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<FrameData> SortedFrames(Frames.begin(), Frames.end());
|
2019-05-20 18:18:35 +08:00
|
|
|
llvm::sort(SortedFrames, [](const FrameData &LHS, const FrameData &RHS) {
|
|
|
|
return LHS.RvaStart < RHS.RvaStart;
|
|
|
|
});
|
2018-09-12 06:35:01 +08:00
|
|
|
if (auto EC = Writer.writeArray(makeArrayRef(SortedFrames)))
|
2017-05-31 01:13:33 +08:00
|
|
|
return EC;
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugFrameDataSubsection::addFrameData(const FrameData &Frame) {
|
|
|
|
Frames.push_back(Frame);
|
|
|
|
}
|