Files
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm
bindings
cmake
docs
examples
include
lib
Analysis
AsmParser
BinaryFormat
Bitcode
CodeGen
DebugInfo
CodeView
DWARF
MSF
PDB
DIA
Native
CMakeLists.txt
GenericError.cpp
IPDBSourceFile.cpp
LLVMBuild.txt
PDB.cpp
PDBContext.cpp
PDBExtras.cpp
PDBInterfaceAnchors.cpp
PDBSymDumper.cpp
PDBSymbol.cpp
PDBSymbolAnnotation.cpp
PDBSymbolBlock.cpp
PDBSymbolCompiland.cpp
PDBSymbolCompilandDetails.cpp
PDBSymbolCompilandEnv.cpp
PDBSymbolCustom.cpp
PDBSymbolData.cpp
PDBSymbolExe.cpp
PDBSymbolFunc.cpp
PDBSymbolFuncDebugEnd.cpp
PDBSymbolFuncDebugStart.cpp
PDBSymbolLabel.cpp
PDBSymbolPublicSymbol.cpp
PDBSymbolThunk.cpp
PDBSymbolTypeArray.cpp
PDBSymbolTypeBaseClass.cpp
PDBSymbolTypeBuiltin.cpp
PDBSymbolTypeCustom.cpp
PDBSymbolTypeDimension.cpp
PDBSymbolTypeEnum.cpp
PDBSymbolTypeFriend.cpp
PDBSymbolTypeFunctionArg.cpp
PDBSymbolTypeFunctionSig.cpp
PDBSymbolTypeManaged.cpp
PDBSymbolTypePointer.cpp
PDBSymbolTypeTypedef.cpp
PDBSymbolTypeUDT.cpp
PDBSymbolTypeVTable.cpp
PDBSymbolTypeVTableShape.cpp
PDBSymbolUnknown.cpp
PDBSymbolUsingNamespace.cpp
UDTLayout.cpp
Symbolize
CMakeLists.txt
LLVMBuild.txt
Demangle
ExecutionEngine
FuzzMutate
Fuzzer
IR
IRReader
LTO
LineEditor
Linker
MC
Object
ObjectYAML
Option
Passes
ProfileData
Support
TableGen
Target
Testing
ToolDrivers
Transforms
WindowsManifest
XRay
CMakeLists.txt
LLVMBuild.txt
projects
resources
runtimes
scripts
test
tools
unittests
utils
.arcconfig
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
CREDITS.TXT
LICENSE.TXT
LLVMBuild.txt
README.txt
RELEASE_TESTERS.TXT
configure
llvm.spec.in
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
libgc
llvm
m4
man
mcs
mk
mono
msvc
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
linux-packaging-mono/external/llvm/lib/DebugInfo/PDB/PDBContext.cpp

120 lines
4.4 KiB
C++
Raw Normal View History

//===-- PDBContext.cpp ------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===/
#include "llvm/DebugInfo/PDB/PDBContext.h"
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
#include "llvm/DebugInfo/PDB/PDBSymbol.h"
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
#include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
#include "llvm/Object/COFF.h"
using namespace llvm;
using namespace llvm::object;
using namespace llvm::pdb;
PDBContext::PDBContext(const COFFObjectFile &Object,
std::unique_ptr<IPDBSession> PDBSession)
: DIContext(CK_PDB), Session(std::move(PDBSession)) {
ErrorOr<uint64_t> ImageBase = Object.getImageBase();
if (ImageBase)
Session->setLoadAddress(ImageBase.get());
}
void PDBContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts){}
DILineInfo PDBContext::getLineInfoForAddress(uint64_t Address,
DILineInfoSpecifier Specifier) {
DILineInfo Result;
Result.FunctionName = getFunctionName(Address, Specifier.FNKind);
uint32_t Length = 1;
std::unique_ptr<PDBSymbol> Symbol =
Session->findSymbolByAddress(Address, PDB_SymType::None);
if (auto Func = dyn_cast_or_null<PDBSymbolFunc>(Symbol.get())) {
Length = Func->getLength();
} else if (auto Data = dyn_cast_or_null<PDBSymbolData>(Symbol.get())) {
Length = Data->getLength();
}
// If we couldn't find a symbol, then just assume 1 byte, so that we get
// only the line number of the first instruction.
auto LineNumbers = Session->findLineNumbersByAddress(Address, Length);
if (!LineNumbers || LineNumbers->getChildCount() == 0)
return Result;
auto LineInfo = LineNumbers->getNext();
assert(LineInfo);
auto SourceFile = Session->getSourceFileById(LineInfo->getSourceFileId());
if (SourceFile &&
Specifier.FLIKind != DILineInfoSpecifier::FileLineInfoKind::None)
Result.FileName = SourceFile->getFileName();
Result.Column = LineInfo->getColumnNumber();
Result.Line = LineInfo->getLineNumber();
return Result;
}
DILineInfoTable
PDBContext::getLineInfoForAddressRange(uint64_t Address, uint64_t Size,
DILineInfoSpecifier Specifier) {
if (Size == 0)
return DILineInfoTable();
DILineInfoTable Table;
auto LineNumbers = Session->findLineNumbersByAddress(Address, Size);
if (!LineNumbers || LineNumbers->getChildCount() == 0)
return Table;
while (auto LineInfo = LineNumbers->getNext()) {
DILineInfo LineEntry =
getLineInfoForAddress(LineInfo->getVirtualAddress(), Specifier);
Table.push_back(std::make_pair(LineInfo->getVirtualAddress(), LineEntry));
}
return Table;
}
DIInliningInfo
PDBContext::getInliningInfoForAddress(uint64_t Address,
DILineInfoSpecifier Specifier) {
DIInliningInfo InlineInfo;
DILineInfo Frame = getLineInfoForAddress(Address, Specifier);
InlineInfo.addFrame(Frame);
return InlineInfo;
}
std::string PDBContext::getFunctionName(uint64_t Address,
DINameKind NameKind) const {
if (NameKind == DINameKind::None)
return std::string();
std::unique_ptr<PDBSymbol> FuncSymbol =
Session->findSymbolByAddress(Address, PDB_SymType::Function);
auto *Func = dyn_cast_or_null<PDBSymbolFunc>(FuncSymbol.get());
if (NameKind == DINameKind::LinkageName) {
// It is not possible to get the mangled linkage name through a
// PDBSymbolFunc. For that we have to specifically request a
// PDBSymbolPublicSymbol.
auto PublicSym =
Session->findSymbolByAddress(Address, PDB_SymType::PublicSymbol);
if (auto *PS = dyn_cast_or_null<PDBSymbolPublicSymbol>(PublicSym.get())) {
// If we also have a function symbol, prefer the use of public symbol name
// only if it refers to the same address. The public symbol uses the
// linkage name while the function does not.
if (!Func || Func->getVirtualAddress() == PS->getVirtualAddress())
return PS->getName();
}
}
return Func ? Func->getName() : std::string();
}