DebugFrameDataSubsection.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. //===----------------------------------------------------------------------===//
  8. #include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"
  9. #include "llvm/DebugInfo/CodeView/CodeViewError.h"
  10. using namespace llvm;
  11. using namespace llvm::codeview;
  12. Error DebugFrameDataSubsectionRef::initialize(BinaryStreamReader Reader) {
  13. if (Reader.bytesRemaining() % sizeof(FrameData) != 0) {
  14. if (auto EC = Reader.readObject(RelocPtr))
  15. return EC;
  16. }
  17. if (Reader.bytesRemaining() % sizeof(FrameData) != 0)
  18. return make_error<CodeViewError>(cv_error_code::corrupt_record,
  19. "Invalid frame data record format!");
  20. uint32_t Count = Reader.bytesRemaining() / sizeof(FrameData);
  21. if (auto EC = Reader.readArray(Frames, Count))
  22. return EC;
  23. return Error::success();
  24. }
  25. Error DebugFrameDataSubsectionRef::initialize(BinaryStreamRef Section) {
  26. BinaryStreamReader Reader(Section);
  27. return initialize(Reader);
  28. }
  29. uint32_t DebugFrameDataSubsection::calculateSerializedSize() const {
  30. uint32_t Size = sizeof(FrameData) * Frames.size();
  31. if (IncludeRelocPtr)
  32. Size += sizeof(uint32_t);
  33. return Size;
  34. }
  35. Error DebugFrameDataSubsection::commit(BinaryStreamWriter &Writer) const {
  36. if (IncludeRelocPtr) {
  37. if (auto EC = Writer.writeInteger<uint32_t>(0))
  38. return EC;
  39. }
  40. std::vector<FrameData> SortedFrames(Frames.begin(), Frames.end());
  41. llvm::sort(SortedFrames, [](const FrameData &LHS, const FrameData &RHS) {
  42. return LHS.RvaStart < RHS.RvaStart;
  43. });
  44. if (auto EC = Writer.writeArray(makeArrayRef(SortedFrames)))
  45. return EC;
  46. return Error::success();
  47. }
  48. void DebugFrameDataSubsection::addFrameData(const FrameData &Frame) {
  49. Frames.push_back(Frame);
  50. }