LLVM  14.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 <algorithm>
17 #include <cassert>
18 #include <cstdint>
19 
20 using namespace llvm;
21 using namespace llvm::codeview;
22 
24 
26  BinaryStreamRef Data)
27  : Kind(Kind), Data(Data) {}
28 
31  const DebugSubsectionHeader *Header;
32  BinaryStreamReader Reader(Stream);
33  if (auto EC = Reader.readObject(Header))
34  return EC;
35 
36  DebugSubsectionKind Kind =
37  static_cast<DebugSubsectionKind>(uint32_t(Header->Kind));
38  if (auto EC = Reader.readStreamRef(Info.Data, Header->Length))
39  return EC;
40  Info.Kind = Kind;
41  return Error::success();
42 }
43 
45  return sizeof(DebugSubsectionHeader) + Data.getLength();
46 }
47 
49 
51 
53  std::shared_ptr<DebugSubsection> Subsection)
54  : Subsection(std::move(Subsection)) {}
55 
57  const DebugSubsectionRecord &Contents)
58  : Contents(Contents) {}
59 
61  uint32_t DataSize = Subsection ? Subsection->calculateSerializedSize()
62  : Contents.getRecordData().getLength();
63  // The length of the entire subsection is always padded to 4 bytes,
64  // regardless of the container kind.
65  return sizeof(DebugSubsectionHeader) + alignTo(DataSize, 4);
66 }
67 
69  CodeViewContainer Container) const {
70  assert(Writer.getOffset() % alignOf(Container) == 0 &&
71  "Debug Subsection not properly aligned");
72 
73  DebugSubsectionHeader Header;
74  Header.Kind = uint32_t(Subsection ? Subsection->kind() : Contents.kind());
75  // The value written into the Header's Length field is only padded to the
76  // container's alignment
77  uint32_t DataSize = Subsection ? Subsection->calculateSerializedSize()
78  : Contents.getRecordData().getLength();
79  Header.Length = alignTo(DataSize, alignOf(Container));
80 
81  if (auto EC = Writer.writeObject(Header))
82  return EC;
83  if (Subsection) {
84  if (auto EC = Subsection->commit(Writer))
85  return EC;
86  } else {
87  if (auto EC = Writer.writeStreamRef(Contents.getRecordData()))
88  return EC;
89  }
90  if (auto EC = Writer.padToAlignment(4))
91  return EC;
92 
93  return Error::success();
94 }
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:148
BinaryStreamReader.h
MathExtras.h
llvm::codeview::DebugSubsectionHeader
Definition: DebugSubsectionRecord.h:30
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
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:31
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::codeview::DebugSubsectionRecord::initialize
static Error initialize(BinaryStreamRef Stream, DebugSubsectionRecord &Info)
Definition: DebugSubsectionRecord.cpp:29
llvm::BinaryStreamWriter::writeStreamRef
Error writeStreamRef(BinaryStreamRef Ref)
Efficiently reads all data from Ref, and writes it to this stream.
Definition: BinaryStreamWriter.cpp:61
Error.h
llvm::codeview::DebugSubsectionRecordBuilder::DebugSubsectionRecordBuilder
DebugSubsectionRecordBuilder(std::shared_ptr< DebugSubsection > Subsection)
Definition: DebugSubsectionRecord.cpp:52
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
DebugSubsectionRecord.h
llvm::BinaryStreamRefBase::getLength
uint64_t getLength() const
Definition: BinaryStreamRef.h:51
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:31
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:609
llvm::codeview::DebugSubsectionRecord::getRecordLength
uint32_t getRecordLength() const
Definition: DebugSubsectionRecord.cpp:44
llvm::BinaryStreamWriter::getOffset
uint64_t getOffset() const
Definition: BinaryStreamWriter.h:184
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:1658
llvm::codeview::DebugSubsectionRecord
Definition: DebugSubsectionRecord.h:35
llvm::codeview::DebugSubsectionRecordBuilder::calculateSerializedLength
uint32_t calculateSerializedLength() const
Definition: DebugSubsectionRecord.cpp:60
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:169
llvm::BinaryStreamWriter::writeObject
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
Definition: BinaryStreamWriter.h:135
uint32_t
std
Definition: BitVector.h:838
llvm::BinaryStreamWriter::padToAlignment
Error padToAlignment(uint32_t Align)
Definition: BinaryStreamWriter.cpp:95
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::codeview::DebugSubsectionRecord::kind
DebugSubsectionKind kind() const
Definition: DebugSubsectionRecord.cpp:48
llvm::codeview::DebugSubsectionRecord::DebugSubsectionRecord
DebugSubsectionRecord()
llvm::codeview::DebugSubsectionKind
DebugSubsectionKind
Definition: CodeView.h:313
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::codeview::DebugSubsectionRecordBuilder::commit
Error commit(BinaryStreamWriter &Writer, CodeViewContainer Container) const
Definition: DebugSubsectionRecord.cpp:68
llvm::codeview::DebugSubsectionRecord::getRecordData
BinaryStreamRef getRecordData() const
Definition: DebugSubsectionRecord.cpp:50
llvm::codeview::CodeViewContainer
CodeViewContainer
Definition: CodeView.h:607
BinaryStreamWriter.h
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition: BinaryStreamRef.h:156