LLVM  10.0.0svn
DebugInlineeLinesSubsection.cpp
Go to the documentation of this file.
1 //===- DebugInlineeLinesSubsection.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 
10 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/Support/Endian.h"
16 #include "llvm/Support/Error.h"
17 #include <cassert>
18 #include <cstdint>
19 
20 using namespace llvm;
21 using namespace llvm::codeview;
22 
25  BinaryStreamReader Reader(Stream);
26 
27  if (auto EC = Reader.readObject(Item.Header))
28  return EC;
29 
30  if (HasExtraFiles) {
31  uint32_t ExtraFileCount;
32  if (auto EC = Reader.readInteger(ExtraFileCount))
33  return EC;
34  if (auto EC = Reader.readArray(Item.ExtraFiles, ExtraFileCount))
35  return EC;
36  }
37 
38  Len = Reader.getOffset();
39  return Error::success();
40 }
41 
44 
46  if (auto EC = Reader.readEnum(Signature))
47  return EC;
48 
49  Lines.getExtractor().HasExtraFiles = hasExtraFiles();
50  if (auto EC = Reader.readArray(Lines, Reader.bytesRemaining()))
51  return EC;
52 
53  assert(Reader.bytesRemaining() == 0);
54  return Error::success();
55 }
56 
58  return Signature == InlineeLinesSignature::ExtraFiles;
59 }
60 
62  DebugChecksumsSubsection &Checksums, bool HasExtraFiles)
63  : DebugSubsection(DebugSubsectionKind::InlineeLines), Checksums(Checksums),
64  HasExtraFiles(HasExtraFiles) {}
65 
67  // 4 bytes for the signature
69 
70  // one header for each entry.
71  Size += Entries.size() * sizeof(InlineeSourceLineHeader);
72  if (HasExtraFiles) {
73  // If extra files are enabled, one count for each entry.
74  Size += Entries.size() * sizeof(uint32_t);
75 
76  // And one file id for each file.
77  Size += ExtraFileCount * sizeof(uint32_t);
78  }
79  assert(Size % 4 == 0);
80  return Size;
81 }
82 
85  if (HasExtraFiles)
87 
88  if (auto EC = Writer.writeEnum(Sig))
89  return EC;
90 
91  for (const auto &E : Entries) {
92  if (auto EC = Writer.writeObject(E.Header))
93  return EC;
94 
95  if (!HasExtraFiles)
96  continue;
97 
98  if (auto EC = Writer.writeInteger<uint32_t>(E.ExtraFiles.size()))
99  return EC;
100  if (auto EC = Writer.writeArray(makeArrayRef(E.ExtraFiles)))
101  return EC;
102  }
103 
104  return Error::success();
105 }
106 
108  uint32_t Offset = Checksums.mapChecksumOffset(FileName);
109 
110  auto &Entry = Entries.back();
111  Entry.ExtraFiles.push_back(ulittle32_t(Offset));
112  ++ExtraFileCount;
113 }
114 
116  StringRef FileName,
117  uint32_t SourceLine) {
118  uint32_t Offset = Checksums.mapChecksumOffset(FileName);
119 
120  Entries.emplace_back();
121  auto &Entry = Entries.back();
123  Entry.Header.SourceLineNum = SourceLine;
125 }
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
Profile::FuncID FuncId
Definition: Profile.cpp:321
This class represents lattice values for constants.
Definition: AllocatorList.h:23
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:450
Error commit(BinaryStreamWriter &Writer) const override
DebugInlineeLinesSubsection(DebugChecksumsSubsection &Checksums, bool HasExtraFiles=false)
A 32-bit type reference.
Definition: TypeIndex.h:95
Error writeArray(ArrayRef< T > Array)
Writes an array of objects of type T to the underlying stream, as if by using memcpy.
uint32_t mapChecksumOffset(StringRef FileName) const
detail::packed_endian_specific_integral< uint32_t, little, unaligned > ulittle32_t
Definition: Endian.h:274
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Provides write only access to a subclass of WritableBinaryStream.
const InlineeSourceLineHeader * Header
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
static ErrorSuccess success()
Create a success value.
Definition: Error.h:326
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Error writeEnum(T Num)
Similar to writeInteger.
uint32_t Size
Definition: Profile.cpp:46
uint32_t bytesRemaining() const
Error operator()(BinaryStreamRef Stream, uint32_t &Len, T &Item) const =delete
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const Extractor & getExtractor() const
FixedStreamArray< support::ulittle32_t > ExtraFiles
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
void addInlineSite(TypeIndex FuncId, StringRef FileName, uint32_t SourceLine)
Provides read only access to a subclass of BinaryStream.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Error readEnum(T &Dest)
Similar to readInteger.
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Get a reference to a NumElements element array of objects of type T from the underlying stream as if ...