DebugFrameDataSubsection.cpp 2.0 KB

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