LLVM 20.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
21using namespace llvm;
22using 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
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(ArrayRef(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();
124 Entry.Header.SourceLineNum = SourceLine;
126}
uint64_t Size
Profile::FuncID FuncId
Definition: Profile.cpp:321
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Provides read only access to a subclass of BinaryStream.
Error readEnum(T &Dest)
Similar to readInteger.
uint64_t bytesRemaining() const
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 ...
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Provides write only access to a subclass of WritableBinaryStream.
Error writeArray(ArrayRef< T > Array)
Writes an array of objects of type T to the underlying stream, as if by using memcpy.
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
Error writeEnum(T Num)
Similar to writeInteger.
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
const Extractor & getExtractor() const
uint32_t mapChecksumOffset(StringRef FileName) const
void addInlineSite(TypeIndex FuncId, StringRef FileName, uint32_t SourceLine)
Error commit(BinaryStreamWriter &Writer) const override
DebugInlineeLinesSubsection(DebugChecksumsSubsection &Checksums, bool HasExtraFiles=false)
A 32-bit type reference.
Definition: TypeIndex.h:96
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
Error operator()(BinaryStreamRef Stream, uint32_t &Len, T &Item) const =delete
FixedStreamArray< support::ulittle32_t > ExtraFiles
const InlineeSourceLineHeader * Header