LLVM  8.0.1
DebugSubsectionRecord.cpp
Go to the documentation of this file.
1 //===- DebugSubsectionRecord.cpp ------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
15 #include "llvm/Support/Error.h"
17 #include <algorithm>
18 #include <cassert>
19 #include <cstdint>
20 
21 using namespace llvm;
22 using namespace llvm::codeview;
23 
25 
27  BinaryStreamRef Data,
28  CodeViewContainer Container)
29  : Container(Container), Kind(Kind), Data(Data) {}
30 
33  CodeViewContainer Container) {
34  const DebugSubsectionHeader *Header;
35  BinaryStreamReader Reader(Stream);
36  if (auto EC = Reader.readObject(Header))
37  return EC;
38 
39  DebugSubsectionKind Kind =
40  static_cast<DebugSubsectionKind>(uint32_t(Header->Kind));
41  if (auto EC = Reader.readStreamRef(Info.Data, Header->Length))
42  return EC;
43  Info.Container = Container;
44  Info.Kind = Kind;
45  return Error::success();
46 }
47 
49  return sizeof(DebugSubsectionHeader) + Data.getLength();
50 }
51 
53 
55 
57  std::shared_ptr<DebugSubsection> Subsection, CodeViewContainer Container)
58  : Subsection(std::move(Subsection)), Container(Container) {}
59 
61  const DebugSubsectionRecord &Contents, CodeViewContainer Container)
62  : Contents(Contents), Container(Container) {}
63 
65  uint32_t DataSize = Subsection ? Subsection->calculateSerializedSize()
66  : Contents.getRecordData().getLength();
67  // The length of the entire subsection is always padded to 4 bytes,
68  // regardless of the container kind.
69  return sizeof(DebugSubsectionHeader) + alignTo(DataSize, 4);
70 }
71 
73  assert(Writer.getOffset() % alignOf(Container) == 0 &&
74  "Debug Subsection not properly aligned");
75 
76  DebugSubsectionHeader Header;
77  Header.Kind = uint32_t(Subsection ? Subsection->kind() : Contents.kind());
78  // The value written into the Header's Length field is only padded to the
79  // container's alignment
80  uint32_t DataSize = Subsection ? Subsection->calculateSerializedSize()
81  : Contents.getRecordData().getLength();
82  Header.Length = alignTo(DataSize, alignOf(Container));
83 
84  if (auto EC = Writer.writeObject(Header))
85  return EC;
86  if (Subsection) {
87  if (auto EC = Subsection->commit(Writer))
88  return EC;
89  } else {
90  if (auto EC = Writer.writeStreamRef(Contents.getRecordData()))
91  return EC;
92  }
93  if (auto EC = Writer.padToAlignment(4))
94  return EC;
95 
96  return Error::success();
97 }
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Error readObject(const T *&Dest)
Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the resul...
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:685
uint32_t alignOf(CodeViewContainer Container)
Definition: CodeView.h:589
Definition: BitVector.h:938
Analysis containing CSE Info
Definition: CSEInfo.cpp:21
Error writeStreamRef(BinaryStreamRef Ref)
Efficiently reads all data from Ref, and writes it to this stream.
Provides write only access to a subclass of WritableBinaryStream.
uint32_t getLength() const
static ErrorSuccess success()
Create a success value.
Definition: Error.h:327
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
static Error initialize(BinaryStreamRef Stream, DebugSubsectionRecord &Info, CodeViewContainer Container)
Error padToAlignment(uint32_t Align)
Error readStreamRef(BinaryStreamRef &Ref)
Read the entire remainder of the underlying stream into Ref.
const unsigned Kind
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
Provides read only access to a subclass of BinaryStream.
DebugSubsectionRecordBuilder(std::shared_ptr< DebugSubsection > Subsection, CodeViewContainer Container)
Error commit(BinaryStreamWriter &Writer) const