LLVM  15.0.0git
DebugSubsectionRecord.cpp
Go to the documentation of this file.
1 //===- DebugSubsectionRecord.cpp ------------------------------------------===//
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 
14 #include "llvm/Support/Error.h"
16 #include <cassert>
17 #include <cstdint>
18 
19 using namespace llvm;
20 using namespace llvm::codeview;
21 
23 
25  BinaryStreamRef Data)
26  : Kind(Kind), Data(Data) {}
27 
30  const DebugSubsectionHeader *Header;
31  BinaryStreamReader Reader(Stream);
32  if (auto EC = Reader.readObject(Header))
33  return EC;
34 
35  DebugSubsectionKind Kind =
36  static_cast<DebugSubsectionKind>(uint32_t(Header->Kind));
37  if (auto EC = Reader.readStreamRef(Info.Data, Header->Length))
38  return EC;
39  Info.Kind = Kind;
40  return Error::success();
41 }
42 
44  return sizeof(DebugSubsectionHeader) + Data.getLength();
45 }
46 
48 
50 
52  std::shared_ptr<DebugSubsection> Subsection)
53  : Subsection(std::move(Subsection)) {}
54 
56  const DebugSubsectionRecord &Contents)
57  : Contents(Contents) {}
58 
60  uint32_t DataSize = Subsection ? Subsection->calculateSerializedSize()
61  : Contents.getRecordData().getLength();
62  // The length of the entire subsection is always padded to 4 bytes,
63  // regardless of the container kind.
64  return sizeof(DebugSubsectionHeader) + alignTo(DataSize, 4);
65 }
66 
68  CodeViewContainer Container) const {
69  assert(Writer.getOffset() % alignOf(Container) == 0 &&
70  "Debug Subsection not properly aligned");
71 
72  DebugSubsectionHeader Header;
73  Header.Kind = uint32_t(Subsection ? Subsection->kind() : Contents.kind());
74  // The value written into the Header's Length field is only padded to the
75  // container's alignment
76  uint32_t DataSize = Subsection ? Subsection->calculateSerializedSize()
77  : Contents.getRecordData().getLength();
78  Header.Length = alignTo(DataSize, alignOf(Container));
79 
80  if (auto EC = Writer.writeObject(Header))
81  return EC;
82  if (Subsection) {
83  if (auto EC = Subsection->commit(Writer))
84  return EC;
85  } else {
86  if (auto EC = Writer.writeStreamRef(Contents.getRecordData()))
87  return EC;
88  }
89  if (auto EC = Writer.padToAlignment(4))
90  return EC;
91 
92  return Error::success();
93 }
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:156
BinaryStreamReader.h
MathExtras.h
llvm::codeview::DebugSubsectionHeader
Definition: DebugSubsectionRecord.h:30
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::codeview::DebugSubsectionHeader::Length
support::ulittle32_t Length
Definition: DebugSubsectionRecord.h:32
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition: BinaryStreamWriter.h:30
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
llvm::codeview::DebugSubsectionRecord::initialize
static Error initialize(BinaryStreamRef Stream, DebugSubsectionRecord &Info)
Definition: DebugSubsectionRecord.cpp:28
llvm::BinaryStreamWriter::writeStreamRef
Error writeStreamRef(BinaryStreamRef Ref)
Efficiently reads all data from Ref, and writes it to this stream.
Definition: BinaryStreamWriter.cpp:60
Error.h
llvm::codeview::DebugSubsectionRecordBuilder::DebugSubsectionRecordBuilder
DebugSubsectionRecordBuilder(std::shared_ptr< DebugSubsection > Subsection)
Definition: DebugSubsectionRecord.cpp:51
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
DebugSubsectionRecord.h
llvm::BinaryStreamRefBase::getLength
uint64_t getLength() const
Definition: BinaryStreamRef.h:50
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::BinaryStreamReader::readStreamRef
Error readStreamRef(BinaryStreamRef &Ref)
Read the entire remainder of the underlying stream into Ref.
Definition: BinaryStreamReader.cpp:130
CodeView.h
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:29
llvm::codeview::DebugSubsectionHeader::Kind
support::ulittle32_t Kind
Definition: DebugSubsectionRecord.h:31
DebugSubsection.h
llvm::codeview::alignOf
uint32_t alignOf(CodeViewContainer Container)
Definition: CodeView.h:611
llvm::codeview::DebugSubsectionRecord::getRecordLength
uint32_t getRecordLength() const
Definition: DebugSubsectionRecord.cpp:43
llvm::BinaryStreamWriter::getOffset
uint64_t getOffset() const
Definition: BinaryStreamWriter.h:178
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1675
llvm::codeview::DebugSubsectionRecord
Definition: DebugSubsectionRecord.h:35
llvm::codeview::DebugSubsectionRecordBuilder::calculateSerializedLength
uint32_t calculateSerializedLength() const
Definition: DebugSubsectionRecord.cpp:59
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm::BinaryStreamReader::readObject
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...
Definition: BinaryStreamReader.h:162
llvm::BinaryStreamWriter::writeObject
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
Definition: BinaryStreamWriter.h:129
uint32_t
std
Definition: BitVector.h:851
llvm::BinaryStreamWriter::padToAlignment
Error padToAlignment(uint32_t Align)
Definition: BinaryStreamWriter.cpp:94
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::codeview::DebugSubsectionRecord::kind
DebugSubsectionKind kind() const
Definition: DebugSubsectionRecord.cpp:47
llvm::codeview::DebugSubsectionRecord::DebugSubsectionRecord
DebugSubsectionRecord()
llvm::codeview::DebugSubsectionKind
DebugSubsectionKind
Definition: CodeView.h:315
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::codeview::DebugSubsectionRecordBuilder::commit
Error commit(BinaryStreamWriter &Writer, CodeViewContainer Container) const
Definition: DebugSubsectionRecord.cpp:67
llvm::codeview::DebugSubsectionRecord::getRecordData
BinaryStreamRef getRecordData() const
Definition: DebugSubsectionRecord.cpp:49
llvm::codeview::CodeViewContainer
CodeViewContainer
Definition: CodeView.h:609
BinaryStreamWriter.h
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition: BinaryStreamRef.h:155