2015-02-07 04:30:52 +08:00
|
|
|
//===- PDBSymbol.cpp - base class for user-facing symbol types --*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-02-07 04:30:52 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-02-14 11:53:56 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbol.h"
|
2015-02-07 04:30:52 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
|
2017-04-10 14:14:09 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/IPDBSession.h"
|
2016-11-24 07:16:32 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBExtras.h"
|
2015-02-07 04:30:52 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolAnnotation.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolBlock.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolCustom.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolLabel.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h"
|
2016-11-24 07:16:32 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBTypes.h"
|
|
|
|
#include <algorithm>
|
2015-02-14 11:53:56 +08:00
|
|
|
#include <memory>
|
|
|
|
|
2015-02-07 04:30:52 +08:00
|
|
|
using namespace llvm;
|
2016-05-05 04:32:13 +08:00
|
|
|
using namespace llvm::pdb;
|
2015-02-07 04:30:52 +08:00
|
|
|
|
2018-09-06 07:30:38 +08:00
|
|
|
PDBSymbol::PDBSymbol(const IPDBSession &PDBSession) : Session(PDBSession) {}
|
2015-02-07 04:30:52 +08:00
|
|
|
|
2018-09-06 07:30:38 +08:00
|
|
|
PDBSymbol::PDBSymbol(PDBSymbol &&Other)
|
|
|
|
: Session(Other.Session), RawSymbol(std::move(Other.RawSymbol)) {}
|
[llvm-pdbdump] More advanced class definition dumping.
Previously the dumping of class definitions was very primitive,
and it made it hard to do more than the most trivial of output
formats when dumping. As such, we would only dump one line for
each field, and then dump non-layout items like nested types
and enums.
With this patch, we do a complete analysis of the object
hierarchy including aggregate types, bases, virtual bases,
vftable analysis, etc. The only immediately visible effects
of this are that a) we can now dump a line for the vfptr where
before we would treat that as padding, and b) we now don't
treat virtual bases that come at the end of a class as padding
since we have a more detailed analysis of the class's storage
usage.
In subsequent patches, we should be able to use this analysis
to display a complete graphical view of a class's layout including
recursing arbitrarily deep into an object's base class / aggregate
member hierarchy.
llvm-svn: 300133
2017-04-13 07:18:21 +08:00
|
|
|
|
2016-11-24 07:16:32 +08:00
|
|
|
PDBSymbol::~PDBSymbol() = default;
|
2015-02-07 04:30:52 +08:00
|
|
|
|
|
|
|
#define FACTORY_SYMTAG_CASE(Tag, Type) \
|
|
|
|
case PDB_SymType::Tag: \
|
2018-09-06 07:30:38 +08:00
|
|
|
return std::unique_ptr<PDBSymbol>(new Type(PDBSession));
|
2015-02-07 04:30:52 +08:00
|
|
|
|
|
|
|
std::unique_ptr<PDBSymbol>
|
2018-09-06 07:30:38 +08:00
|
|
|
PDBSymbol::createSymbol(const IPDBSession &PDBSession, PDB_SymType Tag) {
|
|
|
|
switch (Tag) {
|
2015-02-07 04:30:52 +08:00
|
|
|
FACTORY_SYMTAG_CASE(Exe, PDBSymbolExe)
|
|
|
|
FACTORY_SYMTAG_CASE(Compiland, PDBSymbolCompiland)
|
|
|
|
FACTORY_SYMTAG_CASE(CompilandDetails, PDBSymbolCompilandDetails)
|
|
|
|
FACTORY_SYMTAG_CASE(CompilandEnv, PDBSymbolCompilandEnv)
|
|
|
|
FACTORY_SYMTAG_CASE(Function, PDBSymbolFunc)
|
|
|
|
FACTORY_SYMTAG_CASE(Block, PDBSymbolBlock)
|
|
|
|
FACTORY_SYMTAG_CASE(Data, PDBSymbolData)
|
|
|
|
FACTORY_SYMTAG_CASE(Annotation, PDBSymbolAnnotation)
|
|
|
|
FACTORY_SYMTAG_CASE(Label, PDBSymbolLabel)
|
|
|
|
FACTORY_SYMTAG_CASE(PublicSymbol, PDBSymbolPublicSymbol)
|
|
|
|
FACTORY_SYMTAG_CASE(UDT, PDBSymbolTypeUDT)
|
|
|
|
FACTORY_SYMTAG_CASE(Enum, PDBSymbolTypeEnum)
|
|
|
|
FACTORY_SYMTAG_CASE(FunctionSig, PDBSymbolTypeFunctionSig)
|
|
|
|
FACTORY_SYMTAG_CASE(PointerType, PDBSymbolTypePointer)
|
|
|
|
FACTORY_SYMTAG_CASE(ArrayType, PDBSymbolTypeArray)
|
|
|
|
FACTORY_SYMTAG_CASE(BuiltinType, PDBSymbolTypeBuiltin)
|
|
|
|
FACTORY_SYMTAG_CASE(Typedef, PDBSymbolTypeTypedef)
|
|
|
|
FACTORY_SYMTAG_CASE(BaseClass, PDBSymbolTypeBaseClass)
|
|
|
|
FACTORY_SYMTAG_CASE(Friend, PDBSymbolTypeFriend)
|
|
|
|
FACTORY_SYMTAG_CASE(FunctionArg, PDBSymbolTypeFunctionArg)
|
|
|
|
FACTORY_SYMTAG_CASE(FuncDebugStart, PDBSymbolFuncDebugStart)
|
|
|
|
FACTORY_SYMTAG_CASE(FuncDebugEnd, PDBSymbolFuncDebugEnd)
|
|
|
|
FACTORY_SYMTAG_CASE(UsingNamespace, PDBSymbolUsingNamespace)
|
|
|
|
FACTORY_SYMTAG_CASE(VTableShape, PDBSymbolTypeVTableShape)
|
|
|
|
FACTORY_SYMTAG_CASE(VTable, PDBSymbolTypeVTable)
|
|
|
|
FACTORY_SYMTAG_CASE(Custom, PDBSymbolCustom)
|
|
|
|
FACTORY_SYMTAG_CASE(Thunk, PDBSymbolThunk)
|
|
|
|
FACTORY_SYMTAG_CASE(CustomType, PDBSymbolTypeCustom)
|
|
|
|
FACTORY_SYMTAG_CASE(ManagedType, PDBSymbolTypeManaged)
|
|
|
|
FACTORY_SYMTAG_CASE(Dimension, PDBSymbolTypeDimension)
|
|
|
|
default:
|
2018-09-06 07:30:38 +08:00
|
|
|
return std::unique_ptr<PDBSymbol>(new PDBSymbolUnknown(PDBSession));
|
2015-02-07 04:30:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-06 07:30:38 +08:00
|
|
|
std::unique_ptr<PDBSymbol>
|
|
|
|
PDBSymbol::create(const IPDBSession &PDBSession,
|
|
|
|
std::unique_ptr<IPDBRawSymbol> RawSymbol) {
|
|
|
|
auto SymbolPtr = createSymbol(PDBSession, RawSymbol->getSymTag());
|
|
|
|
SymbolPtr->RawSymbol = RawSymbol.get();
|
|
|
|
SymbolPtr->OwnedRawSymbol = std::move(RawSymbol);
|
2018-09-06 08:06:20 +08:00
|
|
|
return SymbolPtr;
|
2018-09-06 07:30:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<PDBSymbol> PDBSymbol::create(const IPDBSession &PDBSession,
|
|
|
|
IPDBRawSymbol &RawSymbol) {
|
|
|
|
auto SymbolPtr = createSymbol(PDBSession, RawSymbol.getSymTag());
|
|
|
|
SymbolPtr->RawSymbol = &RawSymbol;
|
2018-09-06 08:06:20 +08:00
|
|
|
return SymbolPtr;
|
2018-09-06 07:30:38 +08:00
|
|
|
}
|
|
|
|
|
2018-09-19 00:35:05 +08:00
|
|
|
void PDBSymbol::defaultDump(raw_ostream &OS, int Indent,
|
|
|
|
PdbSymbolIdField ShowFlags,
|
|
|
|
PdbSymbolIdField RecurseFlags) const {
|
|
|
|
RawSymbol->dump(OS, Indent, ShowFlags, RecurseFlags);
|
2015-02-11 06:43:25 +08:00
|
|
|
}
|
2015-02-07 04:30:52 +08:00
|
|
|
|
2017-04-10 14:14:09 +08:00
|
|
|
void PDBSymbol::dumpProperties() const {
|
|
|
|
outs() << "\n";
|
2018-09-19 00:35:05 +08:00
|
|
|
defaultDump(outs(), 0, PdbSymbolIdField::All, PdbSymbolIdField::None);
|
2017-04-10 14:14:09 +08:00
|
|
|
outs().flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PDBSymbol::dumpChildStats() const {
|
|
|
|
TagStats Stats;
|
|
|
|
getChildStats(Stats);
|
|
|
|
outs() << "\n";
|
|
|
|
for (auto &Stat : Stats) {
|
|
|
|
outs() << Stat.first << ": " << Stat.second << "\n";
|
|
|
|
}
|
|
|
|
outs().flush();
|
|
|
|
}
|
|
|
|
|
2015-02-07 04:30:52 +08:00
|
|
|
PDB_SymType PDBSymbol::getSymTag() const { return RawSymbol->getSymTag(); }
|
2016-02-18 05:13:34 +08:00
|
|
|
uint32_t PDBSymbol::getSymIndexId() const { return RawSymbol->getSymIndexId(); }
|
2015-02-07 04:30:52 +08:00
|
|
|
|
2015-02-13 05:09:24 +08:00
|
|
|
std::unique_ptr<IPDBEnumSymbols> PDBSymbol::findAllChildren() const {
|
2015-02-14 11:54:28 +08:00
|
|
|
return findAllChildren(PDB_SymType::None);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IPDBEnumSymbols>
|
|
|
|
PDBSymbol::findAllChildren(PDB_SymType Type) const {
|
|
|
|
return RawSymbol->findChildren(Type);
|
2015-02-11 06:43:25 +08:00
|
|
|
}
|
|
|
|
|
2015-02-07 04:30:52 +08:00
|
|
|
std::unique_ptr<IPDBEnumSymbols>
|
|
|
|
PDBSymbol::findChildren(PDB_SymType Type, StringRef Name,
|
|
|
|
PDB_NameSearchFlags Flags) const {
|
|
|
|
return RawSymbol->findChildren(Type, Name, Flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IPDBEnumSymbols>
|
|
|
|
PDBSymbol::findChildrenByRVA(PDB_SymType Type, StringRef Name,
|
|
|
|
PDB_NameSearchFlags Flags, uint32_t RVA) const {
|
|
|
|
return RawSymbol->findChildrenByRVA(Type, Name, Flags, RVA);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IPDBEnumSymbols>
|
|
|
|
PDBSymbol::findInlineFramesByRVA(uint32_t RVA) const {
|
|
|
|
return RawSymbol->findInlineFramesByRVA(RVA);
|
|
|
|
}
|
2015-02-11 06:43:25 +08:00
|
|
|
|
|
|
|
std::unique_ptr<IPDBEnumSymbols>
|
|
|
|
PDBSymbol::getChildStats(TagStats &Stats) const {
|
2015-02-13 05:09:24 +08:00
|
|
|
std::unique_ptr<IPDBEnumSymbols> Result(findAllChildren());
|
2017-04-14 05:11:00 +08:00
|
|
|
if (!Result)
|
|
|
|
return nullptr;
|
2015-02-11 06:43:25 +08:00
|
|
|
Stats.clear();
|
|
|
|
while (auto Child = Result->getNext()) {
|
|
|
|
++Stats[Child->getSymTag()];
|
|
|
|
}
|
|
|
|
Result->reset();
|
|
|
|
return Result;
|
|
|
|
}
|
2017-04-10 14:14:09 +08:00
|
|
|
|
|
|
|
std::unique_ptr<PDBSymbol> PDBSymbol::getSymbolByIdHelper(uint32_t Id) const {
|
|
|
|
return Session.getSymbolById(Id);
|
|
|
|
}
|
2018-09-19 00:35:05 +08:00
|
|
|
|
|
|
|
void llvm::pdb::dumpSymbolIdField(raw_ostream &OS, StringRef Name,
|
|
|
|
SymIndexId Value, int Indent,
|
|
|
|
const IPDBSession &Session,
|
|
|
|
PdbSymbolIdField FieldId,
|
|
|
|
PdbSymbolIdField ShowFlags,
|
|
|
|
PdbSymbolIdField RecurseFlags) {
|
|
|
|
if ((FieldId & ShowFlags) == PdbSymbolIdField::None)
|
|
|
|
return;
|
|
|
|
|
|
|
|
OS << "\n";
|
|
|
|
OS.indent(Indent);
|
|
|
|
OS << Name << ": " << Value;
|
|
|
|
// Don't recurse unless the user requested it.
|
|
|
|
if ((FieldId & RecurseFlags) == PdbSymbolIdField::None)
|
|
|
|
return;
|
|
|
|
// And obviously don't recurse on the symbol itself.
|
|
|
|
if (FieldId == PdbSymbolIdField::SymIndexId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto Child = Session.getSymbolById(Value);
|
|
|
|
|
|
|
|
// It could have been a placeholder symbol for a type we don't yet support,
|
|
|
|
// so just exit in that case.
|
|
|
|
if (!Child)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Don't recurse more than once, so pass PdbSymbolIdField::None) for the
|
|
|
|
// recurse flags.
|
|
|
|
Child->defaultDump(OS, Indent + 2, ShowFlags, PdbSymbolIdField::None);
|
|
|
|
}
|