LLVM  14.0.0git
NativeInlineSiteSymbol.cpp
Go to the documentation of this file.
1 //===- NativeInlineSiteSymbol.cpp - info about inline sites -----*- C++ -*-===//
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 
17 
18 using namespace llvm;
19 using namespace llvm::codeview;
20 using namespace llvm::pdb;
21 
22 NativeInlineSiteSymbol::NativeInlineSiteSymbol(
23  NativeSession &Session, SymIndexId Id, const codeview::InlineSiteSym &Sym,
24  uint64_t ParentAddr)
25  : NativeRawSymbol(Session, PDB_SymType::InlineSite, Id), Sym(Sym),
26  ParentAddr(ParentAddr) {}
27 
29 
31  PdbSymbolIdField ShowIdFields,
32  PdbSymbolIdField RecurseIdFields) const {
33  NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
34  dumpSymbolField(OS, "name", getName(), Indent);
35 }
36 
39  for (const auto &SS : ModS.getSubsectionsArray()) {
40  if (SS.kind() != DebugSubsectionKind::InlineeLines)
41  continue;
42 
44  BinaryStreamReader Reader(SS.getRecordData());
45  if (auto EC = InlineeLines.initialize(Reader)) {
47  continue;
48  }
49 
50  for (const InlineeSourceLine &Line : InlineeLines)
51  if (Line.Header->Inlinee == Id)
52  return Line;
53  }
54  return None;
55 }
56 
57 std::string NativeInlineSiteSymbol::getName() const {
58  auto Tpi = Session.getPDBFile().getPDBTpiStream();
59  if (!Tpi) {
60  consumeError(Tpi.takeError());
61  return "";
62  }
63  auto Ipi = Session.getPDBFile().getPDBIpiStream();
64  if (!Ipi) {
65  consumeError(Ipi.takeError());
66  return "";
67  }
68 
69  LazyRandomTypeCollection &Types = Tpi->typeCollection();
70  LazyRandomTypeCollection &Ids = Ipi->typeCollection();
71  CVType InlineeType = Ids.getType(Sym.Inlinee);
72  std::string QualifiedName;
73  if (InlineeType.kind() == LF_MFUNC_ID) {
74  MemberFuncIdRecord MFRecord;
75  cantFail(TypeDeserializer::deserializeAs<MemberFuncIdRecord>(InlineeType,
76  MFRecord));
77  TypeIndex ClassTy = MFRecord.getClassType();
78  QualifiedName.append(std::string(Types.getTypeName(ClassTy)));
79  QualifiedName.append("::");
80  } else if (InlineeType.kind() == LF_FUNC_ID) {
81  FuncIdRecord FRecord;
82  cantFail(
83  TypeDeserializer::deserializeAs<FuncIdRecord>(InlineeType, FRecord));
84  TypeIndex ParentScope = FRecord.getParentScope();
85  if (!ParentScope.isNoneType()) {
86  QualifiedName.append(std::string(Ids.getTypeName(ParentScope)));
87  QualifiedName.append("::");
88  }
89  }
90 
91  QualifiedName.append(std::string(Ids.getTypeName(Sym.Inlinee)));
92  return QualifiedName;
93 }
94 
95 void NativeInlineSiteSymbol::getLineOffset(uint32_t OffsetInFunc,
96  uint32_t &LineOffset,
97  uint32_t &FileOffset) const {
98  LineOffset = 0;
99  FileOffset = 0;
100  uint32_t CodeOffset = 0;
101  for (const auto &Annot : Sym.annotations()) {
102  switch (Annot.OpCode) {
103  case BinaryAnnotationsOpCode::CodeOffset:
104  case BinaryAnnotationsOpCode::ChangeCodeOffset:
105  case BinaryAnnotationsOpCode::ChangeCodeLength:
106  CodeOffset += Annot.U1;
107  break;
108  case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset:
109  CodeOffset += Annot.U2;
110  break;
111  case BinaryAnnotationsOpCode::ChangeLineOffset:
112  case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset:
113  CodeOffset += Annot.U1;
114  LineOffset += Annot.S1;
115  break;
116  case BinaryAnnotationsOpCode::ChangeFile:
117  FileOffset = Annot.U1;
118  break;
119  default:
120  break;
121  }
122 
123  if (CodeOffset >= OffsetInFunc)
124  return;
125  }
126 }
127 
128 std::unique_ptr<IPDBEnumLineNumbers>
130  uint32_t Length) const {
131  uint16_t Modi;
132  if (!Session.moduleIndexForVA(VA, Modi))
133  return nullptr;
134 
136  if (!ModS) {
137  consumeError(ModS.takeError());
138  return nullptr;
139  }
140 
142  ModS->findChecksumsSubsection();
143  if (!Checksums) {
144  consumeError(Checksums.takeError());
145  return nullptr;
146  }
147 
148  // Get the line number offset and source file offset.
149  uint32_t SrcLineOffset;
150  uint32_t SrcFileOffset;
151  getLineOffset(VA - ParentAddr, SrcLineOffset, SrcFileOffset);
152 
153  // Get line info from inlinee line table.
155  findInlineeByTypeIndex(Sym.Inlinee, ModS.get());
156 
157  if (!Inlinee)
158  return nullptr;
159 
160  uint32_t SrcLine = Inlinee->Header->SourceLineNum + SrcLineOffset;
161  uint32_t SrcCol = 0; // Inline sites don't seem to have column info.
162  uint32_t FileChecksumOffset =
163  (SrcFileOffset == 0) ? Inlinee->Header->FileID : SrcFileOffset;
164 
165  auto ChecksumIter = Checksums->getArray().at(FileChecksumOffset);
166  uint32_t SrcFileId =
168 
169  uint32_t LineSect, LineOff;
170  Session.addressForVA(VA, LineSect, LineOff);
171  NativeLineNumber LineNum(Session, SrcLine, SrcCol, LineSect, LineOff, Length,
172  SrcFileId, Modi);
173  auto SrcFile = Session.getSymbolCache().getSourceFileById(SrcFileId);
174  std::vector<NativeLineNumber> Lines{LineNum};
175 
176  return std::make_unique<NativeEnumLineNumbers>(std::move(Lines));
177 }
llvm::codeview::TypeIndex::isNoneType
bool isNoneType() const
Definition: TypeIndex.h:116
llvm::codeview::InlineeSourceLine
Definition: DebugInlineeLinesSubsection.h:45
llvm::codeview::DebugSubsectionKind::InlineeLines
@ InlineeLines
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::InlineSite
std::tuple< uint64_t, uint32_t > InlineSite
Definition: MCPseudoProbe.h:90
TpiStream.h
llvm::pdb::ModuleDebugStreamRef
Definition: ModuleDebugStream.h:28
llvm::codeview::DebugSubsectionKind::Lines
@ Lines
SymbolRecord.h
llvm::pdb::SymbolCache::getSourceFileById
std::unique_ptr< IPDBSourceFile > getSourceFileById(SymIndexId FileId) const
Definition: SymbolCache.cpp:609
llvm::codeview::Line
Definition: Line.h:91
NativeEnumLineNumbers.h
llvm::pdb::NativeSession::getPDBFile
PDBFile & getPDBFile()
Definition: NativeSession.h:105
llvm::pdb::NativeInlineSiteSymbol::dump
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Definition: NativeInlineSiteSymbol.cpp:30
llvm::Optional
Definition: APInt.h:33
llvm::pdb::NativeLineNumber
Definition: NativeLineNumber.h:18
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::codeview::FuncIdRecord::getParentScope
TypeIndex getParentScope() const
Definition: TypeRecord.h:617
llvm::pdb::NativeSession::getModuleDebugStream
Expected< ModuleDebugStreamRef > getModuleDebugStream(uint32_t Index) const
Definition: NativeSession.cpp:445
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1045
llvm::pdb::PDB_SymType
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:243
llvm::codeview::LazyRandomTypeCollection::getTypeName
StringRef getTypeName(TypeIndex Index) override
Definition: LazyRandomTypeCollection.cpp:113
llvm::pdb::NativeSession::moduleIndexForVA
bool moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const
Definition: NativeSession.cpp:394
llvm::pdb::PDBFile::getPDBIpiStream
Expected< TpiStream & > getPDBIpiStream()
Definition: PDBFile.cpp:315
NativeInlineSiteSymbol.h
llvm::codeview::InlineSiteSym
Definition: SymbolRecord.h:333
LazyRandomTypeCollection.h
llvm::codeview::LazyRandomTypeCollection
Provides amortized O(1) random access to a CodeView type stream.
Definition: LazyRandomTypeCollection.h:49
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::codeview::BinaryAnnotationsOpCode::CodeOffset
@ CodeOffset
llvm::pdb::NativeInlineSiteSymbol::findInlineeLinesByVA
std::unique_ptr< IPDBEnumLineNumbers > findInlineeLinesByVA(uint64_t VA, uint32_t Length) const override
Definition: NativeInlineSiteSymbol.cpp:129
llvm::None
const NoneType None
Definition: None.h:23
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:31
llvm::pdb::NativeInlineSiteSymbol::~NativeInlineSiteSymbol
~NativeInlineSiteSymbol() override
Definition: NativeInlineSiteSymbol.cpp:28
uint64_t
llvm::pdb::dumpSymbolField
void dumpSymbolField(raw_ostream &OS, StringRef Name, T Value, int Indent)
Definition: PDBExtras.h:47
llvm::codeview::InlineSiteSym::Inlinee
TypeIndex Inlinee
Definition: SymbolRecord.h:347
llvm::codeview::CVRecord::kind
Kind kind() const
Definition: CVRecord.h:42
QualifiedName
Definition: ItaniumDemangle.h:1017
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::pdb::NativeSession::addressForVA
bool addressForVA(uint64_t VA, uint32_t &Section, uint32_t &Offset) const override
Definition: NativeSession.cpp:212
llvm::pdb::NativeSession::getSymbolCache
SymbolCache & getSymbolCache()
Definition: NativeSession.h:109
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm::codeview::FuncIdRecord
Definition: TypeRecord.h:609
llvm::codeview::MemberFuncIdRecord::getClassType
TypeIndex getClassType() const
Definition: TypeRecord.h:225
llvm::codeview::CVRecord< TypeLeafKind >
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition: Error.h:569
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:747
uint32_t
llvm::pdb::PDBFile::getPDBTpiStream
Expected< TpiStream & > getPDBTpiStream()
Definition: PDBFile.cpp:302
DebugInlineeLinesSubsection.h
llvm::pdb::PDB_SymType::Inlinee
@ Inlinee
uint16_t
TypeDeserializer.h
llvm::pdb::NativeRawSymbol::dump
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Definition: NativeRawSymbol.cpp:22
llvm::codeview::DebugInlineeLinesSubsectionRef
Definition: DebugInlineeLinesSubsection.h:61
llvm::pdb::NativeSession
Definition: NativeSession.h:28
llvm::codeview::MemberFuncIdRecord
Definition: TypeRecord.h:216
llvm::pdb::NativeInlineSiteSymbol::getName
std::string getName() const override
Definition: NativeInlineSiteSymbol.cpp:57
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::pdb::PdbSymbolIdField
PdbSymbolIdField
Definition: IPDBRawSymbol.h:24
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:599
llvm::X86AS::SS
@ SS
Definition: X86.h:189
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:96
llvm::pdb::ModuleDebugStreamRef::getSubsectionsArray
codeview::DebugSubsectionArray getSubsectionsArray() const
Definition: ModuleDebugStream.h:59
llvm::pdb::NativeRawSymbol::Session
NativeSession & Session
Definition: NativeRawSymbol.h:232
llvm::codeview::LazyRandomTypeCollection::getType
CVType getType(TypeIndex Index) override
Definition: LazyRandomTypeCollection.cpp:90
llvm::pdb::SymbolCache::getOrCreateSourceFile
SymIndexId getOrCreateSourceFile(const codeview::FileChecksumEntry &Checksum) const
Definition: SymbolCache.cpp:621
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:231
llvm::codeview::InlineSiteSym::annotations
iterator_range< BinaryAnnotationIterator > annotations() const
Definition: SymbolRecord.h:340
llvm::pdb::NativeRawSymbol
Definition: NativeRawSymbol.h:21
findInlineeByTypeIndex
static Optional< InlineeSourceLine > findInlineeByTypeIndex(TypeIndex Id, ModuleDebugStreamRef &ModS)
Definition: NativeInlineSiteSymbol.cpp:38