LLVM  15.0.0git
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"
16 #include "llvm/Support/Endian.h"
17 #include "llvm/Support/Error.h"
18 #include <cassert>
19 #include <cstdint>
20 
21 using namespace llvm;
22 using namespace llvm::codeview;
23 
26  BinaryStreamReader Reader(Stream);
27 
28  if (auto EC = Reader.readObject(Item.Header))
29  return EC;
30 
31  if (HasExtraFiles) {
32  uint32_t ExtraFileCount;
33  if (auto EC = Reader.readInteger(ExtraFileCount))
34  return EC;
35  if (auto EC = Reader.readArray(Item.ExtraFiles, ExtraFileCount))
36  return EC;
37  }
38 
39  Len = Reader.getOffset();
40  return Error::success();
41 }
42 
45 
47  if (auto EC = Reader.readEnum(Signature))
48  return EC;
49 
50  Lines.getExtractor().HasExtraFiles = hasExtraFiles();
51  if (auto EC = Reader.readArray(Lines, Reader.bytesRemaining()))
52  return EC;
53 
54  assert(Reader.bytesRemaining() == 0);
55  return Error::success();
56 }
57 
59  return Signature == InlineeLinesSignature::ExtraFiles;
60 }
61 
63  DebugChecksumsSubsection &Checksums, bool HasExtraFiles)
64  : DebugSubsection(DebugSubsectionKind::InlineeLines), Checksums(Checksums),
65  HasExtraFiles(HasExtraFiles) {}
66 
68  // 4 bytes for the signature
69  uint32_t Size = sizeof(InlineeLinesSignature);
70 
71  // one header for each entry.
72  Size += Entries.size() * sizeof(InlineeSourceLineHeader);
73  if (HasExtraFiles) {
74  // If extra files are enabled, one count for each entry.
75  Size += Entries.size() * sizeof(uint32_t);
76 
77  // And one file id for each file.
78  Size += ExtraFileCount * sizeof(uint32_t);
79  }
80  assert(Size % 4 == 0);
81  return Size;
82 }
83 
86  if (HasExtraFiles)
88 
89  if (auto EC = Writer.writeEnum(Sig))
90  return EC;
91 
92  for (const auto &E : Entries) {
93  if (auto EC = Writer.writeObject(E.Header))
94  return EC;
95 
96  if (!HasExtraFiles)
97  continue;
98 
99  if (auto EC = Writer.writeInteger<uint32_t>(E.ExtraFiles.size()))
100  return EC;
101  if (auto EC = Writer.writeArray(makeArrayRef(E.ExtraFiles)))
102  return EC;
103  }
104 
105  return Error::success();
106 }
107 
109  uint32_t Offset = Checksums.mapChecksumOffset(FileName);
110 
111  auto &Entry = Entries.back();
112  Entry.ExtraFiles.push_back(ulittle32_t(Offset));
113  ++ExtraFileCount;
114 }
115 
117  StringRef FileName,
118  uint32_t SourceLine) {
119  uint32_t Offset = Checksums.mapChecksumOffset(FileName);
120 
121  Entries.emplace_back();
122  auto &Entry = Entries.back();
123  Entry.Header.FileID = Offset;
124  Entry.Header.SourceLineNum = SourceLine;
126 }
BinaryStreamReader.h
llvm::codeview::DebugInlineeLinesSubsection::calculateSerializedSize
uint32_t calculateSerializedSize() const override
Definition: DebugInlineeLinesSubsection.cpp:67
llvm::codeview::InlineeSourceLine
Definition: DebugInlineeLinesSubsection.h:44
llvm::codeview::DebugSubsectionKind::InlineeLines
@ InlineeLines
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::BinaryStreamWriter::writeInteger
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
Definition: BinaryStreamWriter.h:58
RecordSerialization.h
llvm::BinaryStreamWriter::writeEnum
Error writeEnum(T Num)
Similar to writeInteger.
Definition: BinaryStreamWriter.h:68
llvm::codeview::DebugChecksumsSubsection
Definition: DebugChecksumsSubsection.h:77
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
Error.h
llvm::codeview::InlineeLinesSignature::ExtraFiles
@ ExtraFiles
llvm::BinaryStreamReader::bytesRemaining
uint64_t bytesRemaining() const
Definition: BinaryStreamReader.h:250
llvm::BinaryStreamWriter::writeArray
Error writeArray(ArrayRef< T > Array)
Writes an array of objects of type T to the underlying stream, as if by using memcpy.
Definition: BinaryStreamWriter.h:145
llvm::codeview::InlineeSourceLine::Header
const InlineeSourceLineHeader * Header
Definition: DebugInlineeLinesSubsection.h:45
llvm::codeview::InlineeSourceLineHeader::FileID
support::ulittle32_t FileID
Definition: DebugInlineeLinesSubsection.h:37
llvm::codeview::DebugInlineeLinesSubsectionRef::initialize
Error initialize(BinaryStreamReader Reader)
Definition: DebugInlineeLinesSubsection.cpp:46
DebugChecksumsSubsection.h
llvm::codeview::InlineeLinesSignature
InlineeLinesSignature
Definition: DebugInlineeLinesSubsection.h:30
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::codeview::DebugSubsectionRef
Definition: DebugSubsection.h:21
llvm::codeview::InlineeSourceLineHeader
Definition: DebugInlineeLinesSubsection.h:35
llvm::VarStreamArrayExtractor::operator()
Error operator()(BinaryStreamRef Stream, uint32_t &Len, T &Item) const =delete
Definition: DebugChecksumsSubsection.cpp:35
llvm::codeview::DebugInlineeLinesSubsectionRef::hasExtraFiles
bool hasExtraFiles() const
Definition: DebugInlineeLinesSubsection.cpp:58
llvm::codeview::DebugInlineeLinesSubsection::Entry::ExtraFiles
std::vector< support::ulittle32_t > ExtraFiles
Definition: DebugInlineeLinesSubsection.h:90
llvm::codeview::InlineeSourceLine::ExtraFiles
FixedStreamArray< support::ulittle32_t > ExtraFiles
Definition: DebugInlineeLinesSubsection.h:46
CodeView.h
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:29
llvm::support::ulittle32_t
detail::packed_endian_specific_integral< uint32_t, little, unaligned > ulittle32_t
Definition: Endian.h:272
llvm::codeview::InlineeSourceLineHeader::SourceLineNum
support::ulittle32_t SourceLineNum
Definition: DebugInlineeLinesSubsection.h:38
llvm::codeview::DebugChecksumsSubsection::mapChecksumOffset
uint32_t mapChecksumOffset(StringRef FileName) const
Definition: DebugChecksumsSubsection.cpp:110
FuncId
Profile::FuncID FuncId
Definition: Profile.cpp:321
ArrayRef.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm::codeview::DebugInlineeLinesSubsection::addInlineSite
void addInlineSite(TypeIndex FuncId, StringRef FileName, uint32_t SourceLine)
Definition: DebugInlineeLinesSubsection.cpp:116
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
llvm::codeview::DebugInlineeLinesSubsection::Entry
Definition: DebugInlineeLinesSubsection.h:89
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
llvm::codeview::DebugInlineeLinesSubsection::DebugInlineeLinesSubsection
DebugInlineeLinesSubsection(DebugChecksumsSubsection &Checksums, bool HasExtraFiles=false)
Definition: DebugInlineeLinesSubsection.cpp:62
llvm::codeview::DebugInlineeLinesSubsection::Entry::Header
InlineeSourceLineHeader Header
Definition: DebugInlineeLinesSubsection.h:91
DebugInlineeLinesSubsection.h
llvm::codeview::DebugSubsection
Definition: DebugSubsection.h:34
llvm::codeview::InlineeLinesSignature::Normal
@ Normal
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::BinaryStreamReader::readEnum
Error readEnum(T &Dest)
Similar to readInteger.
Definition: BinaryStreamReader.h:82
llvm::codeview::DebugSubsectionKind
DebugSubsectionKind
Definition: CodeView.h:315
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:475
llvm::codeview::DebugInlineeLinesSubsectionRef::DebugInlineeLinesSubsectionRef
DebugInlineeLinesSubsectionRef()
Definition: DebugInlineeLinesSubsection.cpp:43
llvm::VarStreamArray::getExtractor
const Extractor & getExtractor() const
Definition: BinaryStreamArray.h:136
llvm::codeview::DebugInlineeLinesSubsection::commit
Error commit(BinaryStreamWriter &Writer) const override
Definition: DebugInlineeLinesSubsection.cpp:84
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:96
BinaryStreamWriter.h
Endian.h
llvm::codeview::DebugInlineeLinesSubsection::addExtraFile
void addExtraFile(StringRef FileName)
Definition: DebugInlineeLinesSubsection.cpp:108
llvm::BinaryStreamReader::readArray
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 ...
Definition: BinaryStreamReader.h:180
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition: BinaryStreamRef.h:155
llvm::codeview::InlineeSourceLineHeader::Inlinee
TypeIndex Inlinee
Definition: DebugInlineeLinesSubsection.h:36