LLVM  14.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"
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 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
BinaryStreamReader.h
llvm::codeview::DebugInlineeLinesSubsection::calculateSerializedSize
uint32_t calculateSerializedSize() const override
Definition: DebugInlineeLinesSubsection.cpp:66
llvm::codeview::InlineeSourceLine
Definition: DebugInlineeLinesSubsection.h:45
llvm::codeview::DebugSubsectionKind::InlineeLines
@ InlineeLines
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::BinaryStreamWriter::writeInteger
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
Definition: BinaryStreamWriter.h:64
llvm::BinaryStreamWriter::writeEnum
Error writeEnum(T Num)
Similar to writeInteger.
Definition: BinaryStreamWriter.h:74
llvm::codeview::DebugChecksumsSubsection
Definition: DebugChecksumsSubsection.h:75
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
Error.h
llvm::codeview::InlineeLinesSignature::ExtraFiles
@ ExtraFiles
llvm::BinaryStreamReader::bytesRemaining
uint64_t bytesRemaining() const
Definition: BinaryStreamReader.h:257
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
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:151
llvm::codeview::InlineeSourceLine::Header
const InlineeSourceLineHeader * Header
Definition: DebugInlineeLinesSubsection.h:46
llvm::codeview::InlineeSourceLineHeader::FileID
support::ulittle32_t FileID
Definition: DebugInlineeLinesSubsection.h:38
llvm::codeview::DebugInlineeLinesSubsectionRef::initialize
Error initialize(BinaryStreamReader Reader)
Definition: DebugInlineeLinesSubsection.cpp:45
DebugChecksumsSubsection.h
llvm::codeview::InlineeLinesSignature
InlineeLinesSignature
Definition: DebugInlineeLinesSubsection.h:31
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::codeview::DebugSubsectionRef
Definition: DebugSubsection.h:19
llvm::codeview::InlineeSourceLineHeader
Definition: DebugInlineeLinesSubsection.h:36
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:57
llvm::codeview::DebugInlineeLinesSubsection::Entry::ExtraFiles
std::vector< support::ulittle32_t > ExtraFiles
Definition: DebugInlineeLinesSubsection.h:91
llvm::codeview::InlineeSourceLine::ExtraFiles
FixedStreamArray< support::ulittle32_t > ExtraFiles
Definition: DebugInlineeLinesSubsection.h:47
CodeView.h
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:31
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:39
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:115
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
llvm::codeview::DebugInlineeLinesSubsection::Entry
Definition: DebugInlineeLinesSubsection.h:90
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:61
llvm::codeview::DebugInlineeLinesSubsection::Entry::Header
InlineeSourceLineHeader Header
Definition: DebugInlineeLinesSubsection.h:92
DebugInlineeLinesSubsection.h
llvm::codeview::DebugSubsection
Definition: DebugSubsection.h:32
llvm::codeview::InlineeLinesSignature::Normal
@ Normal
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::BinaryStreamReader::readEnum
Error readEnum(T &Dest)
Similar to readInteger.
Definition: BinaryStreamReader.h:89
llvm::codeview::DebugSubsectionKind
DebugSubsectionKind
Definition: CodeView.h:313
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
llvm::codeview::DebugInlineeLinesSubsectionRef::DebugInlineeLinesSubsectionRef
DebugInlineeLinesSubsectionRef()
Definition: DebugInlineeLinesSubsection.cpp:42
llvm::VarStreamArray::getExtractor
const Extractor & getExtractor() const
Definition: BinaryStreamArray.h:136
llvm::codeview::DebugInlineeLinesSubsection::commit
Error commit(BinaryStreamWriter &Writer) const override
Definition: DebugInlineeLinesSubsection.cpp:83
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:107
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:187
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition: BinaryStreamRef.h:156
llvm::codeview::InlineeSourceLineHeader::Inlinee
TypeIndex Inlinee
Definition: DebugInlineeLinesSubsection.h:37