2015-02-06 21:30:52 +01:00
|
|
|
//===- PDBSymbol.h - base class for user-facing symbol types -----*- C++-*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-08-05 00:37:58 +02:00
|
|
|
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOL_H
|
|
|
|
#define LLVM_DEBUGINFO_PDB_PDBSYMBOL_H
|
2015-02-06 21:30:52 +01:00
|
|
|
|
2015-02-12 22:09:24 +01:00
|
|
|
#include "ConcreteSymbolEnumerator.h"
|
2015-02-06 21:30:52 +01:00
|
|
|
#include "IPDBRawSymbol.h"
|
2015-02-10 23:43:25 +01:00
|
|
|
#include "PDBExtras.h"
|
2015-02-06 21:30:52 +01:00
|
|
|
#include "PDBTypes.h"
|
2015-02-13 10:09:03 +01:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
2015-02-06 21:30:52 +01:00
|
|
|
|
|
|
|
#define FORWARD_SYMBOL_METHOD(MethodName) \
|
|
|
|
auto MethodName() const->decltype(RawSymbol->MethodName()) { \
|
|
|
|
return RawSymbol->MethodName(); \
|
|
|
|
}
|
|
|
|
|
2017-04-10 08:14:09 +02:00
|
|
|
#define FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(ConcreteType, PrivateName, \
|
|
|
|
PublicName) \
|
|
|
|
auto PublicName##Id() const->decltype(RawSymbol->PrivateName##Id()) { \
|
|
|
|
return RawSymbol->PrivateName##Id(); \
|
|
|
|
} \
|
|
|
|
std::unique_ptr<ConcreteType> PublicName() const { \
|
|
|
|
uint32_t Id = PublicName##Id(); \
|
|
|
|
return getConcreteSymbolByIdHelper<ConcreteType>(Id); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FORWARD_SYMBOL_ID_METHOD_WITH_NAME(PrivateName, PublicName) \
|
|
|
|
FORWARD_CONCRETE_SYMBOL_ID_METHOD_WITH_NAME(PDBSymbol, PrivateName, \
|
|
|
|
PublicName)
|
|
|
|
|
|
|
|
#define FORWARD_SYMBOL_ID_METHOD(MethodName) \
|
|
|
|
FORWARD_SYMBOL_ID_METHOD_WITH_NAME(MethodName, MethodName)
|
|
|
|
|
2015-02-06 21:30:52 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2016-04-18 11:17:29 +02:00
|
|
|
class StringRef;
|
2015-02-08 01:29:29 +01:00
|
|
|
class raw_ostream;
|
2015-02-06 21:30:52 +01:00
|
|
|
|
2016-05-04 22:32:13 +02:00
|
|
|
namespace pdb {
|
|
|
|
class IPDBRawSymbol;
|
2017-04-10 08:14:09 +02:00
|
|
|
class IPDBSession;
|
2016-05-04 22:32:13 +02:00
|
|
|
|
2015-02-12 22:09:24 +01:00
|
|
|
#define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue) \
|
2018-09-06 01:30:38 +02:00
|
|
|
private: \
|
|
|
|
using PDBSymbol::PDBSymbol; \
|
|
|
|
friend class PDBSymbol; \
|
|
|
|
\
|
|
|
|
public: \
|
2015-02-12 22:09:24 +01:00
|
|
|
static const PDB_SymType Tag = TagValue; \
|
|
|
|
static bool classof(const PDBSymbol *S) { return S->getSymTag() == Tag; }
|
|
|
|
|
2018-09-06 01:30:38 +02:00
|
|
|
#define DECLARE_PDB_SYMBOL_CUSTOM_TYPE(Condition) \
|
|
|
|
private: \
|
|
|
|
using PDBSymbol::PDBSymbol; \
|
|
|
|
friend class PDBSymbol; \
|
|
|
|
\
|
|
|
|
public: \
|
|
|
|
static bool classof(const PDBSymbol *S) { return Condition; }
|
|
|
|
|
2015-02-06 21:30:52 +01:00
|
|
|
/// PDBSymbol defines the base of the inheritance hierarchy for concrete symbol
|
|
|
|
/// types (e.g. functions, executables, vtables, etc). All concrete symbol
|
|
|
|
/// types inherit from PDBSymbol and expose the exact set of methods that are
|
|
|
|
/// valid for that particular symbol type, as described in the Microsoft
|
|
|
|
/// reference "Lexical and Class Hierarchy of Symbol Types":
|
|
|
|
/// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx
|
|
|
|
class PDBSymbol {
|
2018-09-06 01:30:38 +02:00
|
|
|
static std::unique_ptr<PDBSymbol> createSymbol(const IPDBSession &PDBSession,
|
|
|
|
PDB_SymType Tag);
|
|
|
|
|
2015-02-06 21:30:52 +01:00
|
|
|
protected:
|
2018-09-06 01:30:38 +02:00
|
|
|
explicit PDBSymbol(const IPDBSession &PDBSession);
|
|
|
|
PDBSymbol(PDBSymbol &&Other);
|
2015-02-06 21:30:52 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
static std::unique_ptr<PDBSymbol>
|
2018-09-06 01:30:38 +02:00
|
|
|
create(const IPDBSession &PDBSession,
|
|
|
|
std::unique_ptr<IPDBRawSymbol> RawSymbol);
|
|
|
|
static std::unique_ptr<PDBSymbol> create(const IPDBSession &PDBSession,
|
|
|
|
IPDBRawSymbol &RawSymbol);
|
|
|
|
|
|
|
|
template <typename ConcreteT>
|
|
|
|
static std::unique_ptr<ConcreteT>
|
|
|
|
createAs(const IPDBSession &PDBSession,
|
|
|
|
std::unique_ptr<IPDBRawSymbol> RawSymbol) {
|
|
|
|
std::unique_ptr<PDBSymbol> S = create(PDBSession, std::move(RawSymbol));
|
|
|
|
return unique_dyn_cast_or_null<ConcreteT>(std::move(S));
|
|
|
|
}
|
|
|
|
template <typename ConcreteT>
|
|
|
|
static std::unique_ptr<ConcreteT> createAs(const IPDBSession &PDBSession,
|
|
|
|
IPDBRawSymbol &RawSymbol) {
|
|
|
|
std::unique_ptr<PDBSymbol> S = create(PDBSession, RawSymbol);
|
|
|
|
return unique_dyn_cast_or_null<ConcreteT>(std::move(S));
|
|
|
|
}
|
2015-02-06 21:30:52 +01:00
|
|
|
|
|
|
|
virtual ~PDBSymbol();
|
|
|
|
|
|
|
|
/// Dumps the contents of a symbol a raw_ostream. By default this will just
|
|
|
|
/// call dump() on the underlying RawSymbol, which allows us to discover
|
|
|
|
/// unknown properties, but individual implementations of PDBSymbol may
|
|
|
|
/// override the behavior to only dump known fields.
|
2015-03-01 07:51:29 +01:00
|
|
|
virtual void dump(PDBSymDumper &Dumper) const = 0;
|
2017-04-10 18:43:09 +02:00
|
|
|
|
|
|
|
/// For certain PDBSymbolTypes, dumps additional information for the type that
|
|
|
|
/// normally goes on the right side of the symbol.
|
|
|
|
virtual void dumpRight(PDBSymDumper &Dumper) const {}
|
|
|
|
|
2015-02-23 06:59:14 +01:00
|
|
|
void defaultDump(raw_ostream &OS, int Indent) const;
|
2017-04-10 08:14:09 +02:00
|
|
|
void dumpProperties() const;
|
|
|
|
void dumpChildStats() const;
|
2015-02-06 21:30:52 +01:00
|
|
|
|
|
|
|
PDB_SymType getSymTag() const;
|
2016-02-17 22:13:34 +01:00
|
|
|
uint32_t getSymIndexId() const;
|
2015-02-06 21:30:52 +01:00
|
|
|
|
2015-02-12 22:09:24 +01:00
|
|
|
template <typename T> std::unique_ptr<T> findOneChild() const {
|
|
|
|
auto Enumerator(findAllChildren<T>());
|
2017-06-08 18:00:40 +02:00
|
|
|
if (!Enumerator)
|
|
|
|
return nullptr;
|
2015-02-12 22:09:24 +01:00
|
|
|
return Enumerator->getNext();
|
|
|
|
}
|
|
|
|
|
2017-04-10 08:14:09 +02:00
|
|
|
std::unique_ptr<PDBSymbol> clone() const;
|
|
|
|
|
2015-02-12 22:09:24 +01:00
|
|
|
template <typename T>
|
|
|
|
std::unique_ptr<ConcreteSymbolEnumerator<T>> findAllChildren() const {
|
|
|
|
auto BaseIter = RawSymbol->findChildren(T::Tag);
|
2017-06-08 18:00:40 +02:00
|
|
|
if (!BaseIter)
|
|
|
|
return nullptr;
|
2015-02-12 22:17:07 +01:00
|
|
|
return llvm::make_unique<ConcreteSymbolEnumerator<T>>(std::move(BaseIter));
|
2015-02-12 22:09:24 +01:00
|
|
|
}
|
2015-02-14 04:54:28 +01:00
|
|
|
std::unique_ptr<IPDBEnumSymbols> findAllChildren(PDB_SymType Type) const;
|
2015-02-12 22:09:24 +01:00
|
|
|
std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
|
2015-02-14 04:54:28 +01:00
|
|
|
|
2015-02-06 21:30:52 +01:00
|
|
|
std::unique_ptr<IPDBEnumSymbols>
|
|
|
|
findChildren(PDB_SymType Type, StringRef Name,
|
|
|
|
PDB_NameSearchFlags Flags) const;
|
|
|
|
std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type,
|
|
|
|
StringRef Name,
|
|
|
|
PDB_NameSearchFlags Flags,
|
|
|
|
uint32_t RVA) const;
|
|
|
|
std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
|
|
|
|
|
2015-02-10 23:43:25 +01:00
|
|
|
const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
|
|
|
|
IPDBRawSymbol &getRawSymbol() { return *RawSymbol; }
|
|
|
|
|
2015-02-22 23:03:38 +01:00
|
|
|
const IPDBSession &getSession() const { return Session; }
|
|
|
|
|
2015-02-10 23:43:25 +01:00
|
|
|
std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
|
|
|
|
|
2015-02-23 06:58:34 +01:00
|
|
|
protected:
|
2017-04-10 08:14:09 +02:00
|
|
|
std::unique_ptr<PDBSymbol> getSymbolByIdHelper(uint32_t Id) const;
|
|
|
|
|
|
|
|
template <typename ConcreteType>
|
|
|
|
std::unique_ptr<ConcreteType> getConcreteSymbolByIdHelper(uint32_t Id) const {
|
[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 01:18:21 +02:00
|
|
|
return unique_dyn_cast_or_null<ConcreteType>(getSymbolByIdHelper(Id));
|
2017-04-10 08:14:09 +02:00
|
|
|
}
|
|
|
|
|
2015-02-08 23:53:53 +01:00
|
|
|
const IPDBSession &Session;
|
2018-09-06 01:30:38 +02:00
|
|
|
std::unique_ptr<IPDBRawSymbol> OwnedRawSymbol;
|
|
|
|
IPDBRawSymbol *RawSymbol = nullptr;
|
2015-02-06 21:30:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace llvm
|
2016-05-04 22:32:13 +02:00
|
|
|
}
|
2015-02-06 21:30:52 +01:00
|
|
|
|
|
|
|
#endif
|