LLVM  14.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 
16 
17 using namespace llvm;
18 using namespace llvm::codeview;
19 using namespace llvm::pdb;
20 
21 NativeFunctionSymbol::NativeFunctionSymbol(NativeSession &Session,
22  SymIndexId Id,
23  const codeview::ProcSym &Sym,
25  : NativeRawSymbol(Session, PDB_SymType::Function, Id), Sym(Sym),
26  RecordOffset(Offset) {}
27 
29 
31  PdbSymbolIdField ShowIdFields,
32  PdbSymbolIdField RecurseIdFields) const {
33  NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
34  dumpSymbolField(OS, "name", getName(), Indent);
35  dumpSymbolField(OS, "length", getLength(), Indent);
36  dumpSymbolField(OS, "offset", getAddressOffset(), Indent);
37  dumpSymbolField(OS, "section", getAddressSection(), Indent);
38 }
39 
41  return Sym.CodeOffset;
42 }
43 
45 std::string NativeFunctionSymbol::getName() const {
46  return std::string(Sym.Name);
47 }
48 
50 
53 }
54 
57 }
58 
60  uint32_t OffsetInFunc) {
61  // Returns true if inline site contains the offset.
62  bool Found = false;
63  uint32_t CodeOffset = 0;
64  for (auto &Annot : IS.annotations()) {
65  switch (Annot.OpCode) {
66  case BinaryAnnotationsOpCode::CodeOffset:
67  case BinaryAnnotationsOpCode::ChangeCodeOffset:
68  case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset:
69  CodeOffset += Annot.U1;
70  if (OffsetInFunc >= CodeOffset)
71  Found = true;
72  break;
73  case BinaryAnnotationsOpCode::ChangeCodeLength:
74  CodeOffset += Annot.U1;
75  if (Found && OffsetInFunc < CodeOffset)
76  return true;
77  Found = false;
78  break;
79  case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset:
80  CodeOffset += Annot.U2;
81  if (OffsetInFunc >= CodeOffset && OffsetInFunc < CodeOffset + Annot.U1)
82  return true;
83  Found = false;
84  break;
85  default:
86  break;
87  }
88  }
89  return false;
90 }
91 
92 std::unique_ptr<IPDBEnumSymbols>
94  uint16_t Modi;
95  if (!Session.moduleIndexForVA(VA, Modi))
96  return nullptr;
97 
99  if (!ModS) {
100  consumeError(ModS.takeError());
101  return nullptr;
102  }
103  CVSymbolArray Syms = ModS->getSymbolArray();
104 
105  // Search for inline sites. There should be one matching top level inline
106  // site. Then search in its nested inline sites.
107  std::vector<SymIndexId> Frames;
109  auto Start = Syms.at(RecordOffset);
110  auto End = Syms.at(Sym.End);
111  while (Start != End) {
112  bool Found = false;
113  // Find matching inline site within Start and End.
114  for (; Start != End; ++Start) {
115  if (Start->kind() != S_INLINESITE)
116  continue;
117 
118  InlineSiteSym IS =
119  cantFail(SymbolDeserializer::deserializeAs<InlineSiteSym>(*Start));
121  // Insert frames in reverse order.
123  IS, getVirtualAddress(), Modi, Start.offset());
124  Frames.insert(Frames.begin(), Id);
125 
126  // Update offsets to search within this inline site.
127  ++Start;
128  End = Syms.at(IS.End);
129  Found = true;
130  break;
131  }
132 
133  Start = Syms.at(IS.End);
134  if (Start == End)
135  break;
136  }
137 
138  if (!Found)
139  break;
140  }
141 
142  return std::make_unique<NativeEnumSymbols>(Session, std::move(Frames));
143 }
llvm::pdb::NativeFunctionSymbol::getAddressSection
uint32_t getAddressSection() const override
Definition: NativeFunctionSymbol.cpp:44
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::pdb::NativeSession::getRVAFromSectOffset
uint32_t getRVAFromSectOffset(uint32_t Section, uint32_t Offset) const
Definition: NativeSession.cpp:373
inlineSiteContainsAddress
static bool inlineSiteContainsAddress(InlineSiteSym &IS, uint32_t OffsetInFunc)
Definition: NativeFunctionSymbol.cpp:59
llvm::Function
Definition: Function.h:62
SymbolRecord.h
llvm::pdb::SymbolCache::getOrCreateInlineSymbol
SymIndexId getOrCreateInlineSymbol(codeview::InlineSiteSym Sym, uint64_t ParentAddr, uint16_t Modi, uint32_t RecordOffset) const
Definition: SymbolCache.cpp:295
llvm::pdb::NativeSession::getVAFromSectOffset
uint64_t getVAFromSectOffset(uint32_t Section, uint32_t Offset) const
Definition: NativeSession.cpp:389
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
NativeFunctionSymbol.h
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::pdb::NativeFunctionSymbol::getAddressOffset
uint32_t getAddressOffset() const override
Definition: NativeFunctionSymbol.cpp:40
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::pdb::NativeSession::moduleIndexForVA
bool moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const
Definition: NativeSession.cpp:394
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:53
llvm::pdb::NativeFunctionSymbol::getLength
uint64_t getLength() const override
Definition: NativeFunctionSymbol.cpp:49
llvm::codeview::BinaryAnnotationsOpCode::CodeOffset
@ CodeOffset
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:40
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:109
llvm::pdb::NativeFunctionSymbol::getRelativeVirtualAddress
uint32_t getRelativeVirtualAddress() const override
Definition: NativeFunctionSymbol.cpp:51
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::NativeFunctionSymbol::dump
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Definition: NativeFunctionSymbol.cpp:30
llvm::pdb::NativeFunctionSymbol::~NativeFunctionSymbol
~NativeFunctionSymbol() override
Definition: NativeFunctionSymbol.cpp:28
llvm::pdb::NativeFunctionSymbol::getName
std::string getName() const override
Definition: NativeFunctionSymbol.cpp:45
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:93
llvm::pdb::NativeFunctionSymbol::getVirtualAddress
uint64_t getVirtualAddress() const override
Definition: NativeFunctionSymbol.cpp:55
llvm::pdb::NativeRawSymbol::dump
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Definition: NativeRawSymbol.cpp:22
llvm::pdb::NativeSession
Definition: NativeSession.h:28
NativeTypeEnum.h
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::pdb::NativeFunctionSymbol::RecordOffset
uint32_t RecordOffset
Definition: NativeFunctionSymbol.h:41
NativeTypeBuiltin.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:132
llvm::pdb::NativeRawSymbol::Session
NativeSession & Session
Definition: NativeRawSymbol.h:232
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:231
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