LLVM  15.0.0git
NativeFunctionSymbol.cpp
Go to the documentation of this file.
1 //===- NativeFunctionSymbol.cpp - info about function symbols----*- 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 
20 
21 using namespace llvm;
22 using namespace llvm::codeview;
23 using namespace llvm::pdb;
24 
25 NativeFunctionSymbol::NativeFunctionSymbol(NativeSession &Session,
26  SymIndexId Id,
27  const codeview::ProcSym &Sym,
28  uint32_t Offset)
29  : NativeRawSymbol(Session, PDB_SymType::Function, Id), Sym(Sym),
30  RecordOffset(Offset) {}
31 
33 
35  PdbSymbolIdField ShowIdFields,
36  PdbSymbolIdField RecurseIdFields) const {
37  NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
38  dumpSymbolField(OS, "name", getName(), Indent);
39  dumpSymbolField(OS, "length", getLength(), Indent);
40  dumpSymbolField(OS, "offset", getAddressOffset(), Indent);
41  dumpSymbolField(OS, "section", getAddressSection(), Indent);
42 }
43 
45  return Sym.CodeOffset;
46 }
47 
49 std::string NativeFunctionSymbol::getName() const {
50  return std::string(Sym.Name);
51 }
52 
54 
57 }
58 
61 }
62 
64  uint32_t OffsetInFunc) {
65  // Returns true if inline site contains the offset.
66  bool Found = false;
67  uint32_t CodeOffset = 0;
68  for (auto &Annot : IS.annotations()) {
69  switch (Annot.OpCode) {
70  case BinaryAnnotationsOpCode::CodeOffset:
71  case BinaryAnnotationsOpCode::ChangeCodeOffset:
72  case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset:
73  CodeOffset += Annot.U1;
74  if (OffsetInFunc >= CodeOffset)
75  Found = true;
76  break;
77  case BinaryAnnotationsOpCode::ChangeCodeLength:
78  CodeOffset += Annot.U1;
79  if (Found && OffsetInFunc < CodeOffset)
80  return true;
81  Found = false;
82  break;
83  case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset:
84  CodeOffset += Annot.U2;
85  if (OffsetInFunc >= CodeOffset && OffsetInFunc < CodeOffset + Annot.U1)
86  return true;
87  Found = false;
88  break;
89  default:
90  break;
91  }
92  }
93  return false;
94 }
95 
96 std::unique_ptr<IPDBEnumSymbols>
98  uint16_t Modi;
99  if (!Session.moduleIndexForVA(VA, Modi))
100  return nullptr;
101 
103  if (!ModS) {
104  consumeError(ModS.takeError());
105  return nullptr;
106  }
107  CVSymbolArray Syms = ModS->getSymbolArray();
108 
109  // Search for inline sites. There should be one matching top level inline
110  // site. Then search in its nested inline sites.
111  std::vector<SymIndexId> Frames;
113  auto Start = Syms.at(RecordOffset);
114  auto End = Syms.at(Sym.End);
115  while (Start != End) {
116  bool Found = false;
117  // Find matching inline site within Start and End.
118  for (; Start != End; ++Start) {
119  if (Start->kind() != S_INLINESITE)
120  continue;
121 
122  InlineSiteSym IS =
123  cantFail(SymbolDeserializer::deserializeAs<InlineSiteSym>(*Start));
125  // Insert frames in reverse order.
127  IS, getVirtualAddress(), Modi, Start.offset());
128  Frames.insert(Frames.begin(), Id);
129 
130  // Update offsets to search within this inline site.
131  ++Start;
132  End = Syms.at(IS.End);
133  Found = true;
134  break;
135  }
136 
137  Start = Syms.at(IS.End);
138  if (Start == End)
139  break;
140  }
141 
142  if (!Found)
143  break;
144  }
145 
146  return std::make_unique<NativeEnumSymbols>(Session, std::move(Frames));
147 }
llvm::pdb::NativeFunctionSymbol::getAddressSection
uint32_t getAddressSection() const override
Definition: NativeFunctionSymbol.cpp:48
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::pdb::NativeSession::getRVAFromSectOffset
uint32_t getRVAFromSectOffset(uint32_t Section, uint32_t Offset) const
Definition: NativeSession.cpp:381
inlineSiteContainsAddress
static bool inlineSiteContainsAddress(InlineSiteSym &IS, uint32_t OffsetInFunc)
Definition: NativeFunctionSymbol.cpp:63
llvm::Function
Definition: Function.h:60
SymbolRecord.h
llvm::pdb::SymbolCache::getOrCreateInlineSymbol
SymIndexId getOrCreateInlineSymbol(codeview::InlineSiteSym Sym, uint64_t ParentAddr, uint16_t Modi, uint32_t RecordOffset) const
Definition: SymbolCache.cpp:300
llvm::pdb::NativeSession::getVAFromSectOffset
uint64_t getVAFromSectOffset(uint32_t Section, uint32_t Offset) const
Definition: NativeSession.cpp:397
NativeFunctionSymbol.h
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::pdb::NativeFunctionSymbol::getAddressOffset
uint32_t getAddressOffset() const override
Definition: NativeFunctionSymbol.cpp:44
llvm::pdb::NativeSession::getModuleDebugStream
Expected< ModuleDebugStreamRef > getModuleDebugStream(uint32_t Index) const
Definition: NativeSession.cpp:453
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1043
llvm::pdb::PDB_SymType
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:243
llvm::pdb::NativeSession::moduleIndexForVA
bool moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const
Definition: NativeSession.cpp:402
llvm::codeview::ProcSym::End
uint32_t End
Definition: SymbolRecord.h:55
NativeEnumSymbols.h
llvm::codeview::InlineSiteSym
Definition: SymbolRecord.h:333
SymbolDeserializer.h
llvm::VarStreamArray< CVSymbol >
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::pdb::NativeFunctionSymbol::getLength
uint64_t getLength() const override
Definition: NativeFunctionSymbol.cpp:53
llvm::codeview::BinaryAnnotationsOpCode::CodeOffset
@ CodeOffset
CodeView.h
llvm::codeview::InlineSiteSym::End
uint32_t End
Definition: SymbolRecord.h:346
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::codeview::ProcSym
Definition: SymbolRecord.h:42
llvm::pdb::NativeFunctionSymbol::Sym
const codeview::ProcSym Sym
Definition: NativeFunctionSymbol.h:43
uint64_t
llvm::codeview::ProcSym::Name
StringRef Name
Definition: SymbolRecord.h:64
llvm::pdb::dumpSymbolField
void dumpSymbolField(raw_ostream &OS, StringRef Name, T Value, int Indent)
Definition: PDBExtras.h:47
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::codeview::ProcSym::Segment
uint16_t Segment
Definition: SymbolRecord.h:62
llvm::pdb::NativeSession::getSymbolCache
SymbolCache & getSymbolCache()
Definition: NativeSession.h:113
llvm::pdb::NativeFunctionSymbol::getRelativeVirtualAddress
uint32_t getRelativeVirtualAddress() const override
Definition: NativeFunctionSymbol.cpp:55
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:745
uint32_t
llvm::pdb::NativeFunctionSymbol::dump
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Definition: NativeFunctionSymbol.cpp:34
llvm::pdb::NativeFunctionSymbol::~NativeFunctionSymbol
~NativeFunctionSymbol() override
llvm::pdb::NativeFunctionSymbol::getName
std::string getName() const override
Definition: NativeFunctionSymbol.cpp:49
llvm::codeview::ProcSym::CodeOffset
uint32_t CodeOffset
Definition: SymbolRecord.h:61
uint16_t
llvm::pdb::NativeFunctionSymbol::findInlineFramesByVA
std::unique_ptr< IPDBEnumSymbols > findInlineFramesByVA(uint64_t VA) const override
Definition: NativeFunctionSymbol.cpp:97
CVRecord.h
llvm::pdb::NativeFunctionSymbol::getVirtualAddress
uint64_t getVirtualAddress() const override
Definition: NativeFunctionSymbol.cpp:59
llvm::pdb::NativeRawSymbol::dump
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Definition: NativeRawSymbol.cpp:21
ModuleDebugStream.h
llvm::pdb::NativeSession
Definition: NativeSession.h:32
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:597
llvm::pdb::NativeFunctionSymbol::RecordOffset
uint32_t RecordOffset
Definition: NativeFunctionSymbol.h:44
PDBExtras.h
SymbolCache.h
llvm::VarStreamArray::at
Iterator at(uint32_t Offset) const
given an offset into the array's underlying stream, return an iterator to the record at that offset.
Definition: BinaryStreamArray.h:134
llvm::pdb::NativeRawSymbol::Session
NativeSession & Session
Definition: NativeRawSymbol.h:232
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:238
llvm::codeview::ProcSym::CodeSize
uint32_t CodeSize
Definition: SymbolRecord.h:57
llvm::codeview::InlineSiteSym::annotations
iterator_range< BinaryAnnotationIterator > annotations() const
Definition: SymbolRecord.h:340
llvm::pdb::NativeRawSymbol
Definition: NativeRawSymbol.h:21
NativeSession.h