#include "SymbolFileNativePDB.h"
#include "Plugins/ExpressionParser/Clang/ClangUtil.h"
#include "Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.h"
#include "Plugins/ObjectFile/PDB/ObjectFilePDB.h"
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Symbol/Variable.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "llvm/DebugInfo/CodeView/CVRecord.h"
#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
#include "llvm/DebugInfo/CodeView/RecordName.h"
#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
#include "llvm/DebugInfo/CodeView/SymbolRecordHelpers.h"
#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
#include "llvm/DebugInfo/PDB/PDB.h"
#include "llvm/DebugInfo/PDB/PDBTypes.h"
#include "llvm/Demangle/MicrosoftDemangle.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/BinaryStreamReader.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/MemoryBuffer.h"
#include "DWARFLocationExpression.h"
#include "PdbSymUid.h"
#include "PdbUtil.h"
#include "UdtRecordCompleter.h"
#include <optional>
#include <string_view>
usingnamespacelldb;
usingnamespacelldb_private;
usingnamespacenpdb;
usingnamespacellvm::codeview;
usingnamespacellvm::pdb;
char SymbolFileNativePDB::ID;
static lldb::LanguageType TranslateLanguage(PDB_Lang lang) { … }
static std::unique_ptr<PDBFile>
loadMatchingPDBFile(std::string exe_path, llvm::BumpPtrAllocator &allocator) { … }
static bool IsFunctionPrologue(const CompilandIndexItem &cci,
lldb::addr_t addr) { … }
static bool IsFunctionEpilogue(const CompilandIndexItem &cci,
lldb::addr_t addr) { … }
static llvm::StringRef GetSimpleTypeName(SimpleTypeKind kind) { … }
static bool IsClassRecord(TypeLeafKind kind) { … }
static std::optional<CVTagRecord>
GetNestedTagDefinition(const NestedTypeRecord &Record,
const CVTagRecord &parent, TpiStream &tpi) { … }
void SymbolFileNativePDB::Initialize() { … }
void SymbolFileNativePDB::Terminate() { … }
void SymbolFileNativePDB::DebuggerInitialize(Debugger &debugger) { … }
llvm::StringRef SymbolFileNativePDB::GetPluginDescriptionStatic() { … }
SymbolFile *SymbolFileNativePDB::CreateInstance(ObjectFileSP objfile_sp) { … }
SymbolFileNativePDB::SymbolFileNativePDB(ObjectFileSP objfile_sp)
: … { … }
SymbolFileNativePDB::~SymbolFileNativePDB() = default;
uint32_t SymbolFileNativePDB::CalculateAbilities() { … }
void SymbolFileNativePDB::InitializeObject() { … }
uint32_t SymbolFileNativePDB::CalculateNumCompileUnits() { … }
Block &SymbolFileNativePDB::CreateBlock(PdbCompilandSymId block_id) { … }
lldb::FunctionSP SymbolFileNativePDB::CreateFunction(PdbCompilandSymId func_id,
CompileUnit &comp_unit) { … }
CompUnitSP
SymbolFileNativePDB::CreateCompileUnit(const CompilandIndexItem &cci) { … }
lldb::TypeSP SymbolFileNativePDB::CreateModifierType(PdbTypeSymId type_id,
const ModifierRecord &mr,
CompilerType ct) { … }
lldb::TypeSP
SymbolFileNativePDB::CreatePointerType(PdbTypeSymId type_id,
const llvm::codeview::PointerRecord &pr,
CompilerType ct) { … }
lldb::TypeSP SymbolFileNativePDB::CreateSimpleType(TypeIndex ti,
CompilerType ct) { … }
static std::string GetUnqualifiedTypeName(const TagRecord &record) { … }
lldb::TypeSP
SymbolFileNativePDB::CreateClassStructUnion(PdbTypeSymId type_id,
const TagRecord &record,
size_t size, CompilerType ct) { … }
lldb::TypeSP SymbolFileNativePDB::CreateTagType(PdbTypeSymId type_id,
const ClassRecord &cr,
CompilerType ct) { … }
lldb::TypeSP SymbolFileNativePDB::CreateTagType(PdbTypeSymId type_id,
const UnionRecord &ur,
CompilerType ct) { … }
lldb::TypeSP SymbolFileNativePDB::CreateTagType(PdbTypeSymId type_id,
const EnumRecord &er,
CompilerType ct) { … }
TypeSP SymbolFileNativePDB::CreateArrayType(PdbTypeSymId type_id,
const ArrayRecord &ar,
CompilerType ct) { … }
TypeSP SymbolFileNativePDB::CreateFunctionType(PdbTypeSymId type_id,
const MemberFunctionRecord &mfr,
CompilerType ct) { … }
TypeSP SymbolFileNativePDB::CreateProcedureType(PdbTypeSymId type_id,
const ProcedureRecord &pr,
CompilerType ct) { … }
TypeSP SymbolFileNativePDB::CreateType(PdbTypeSymId type_id, CompilerType ct) { … }
TypeSP SymbolFileNativePDB::CreateAndCacheType(PdbTypeSymId type_id) { … }
TypeSP SymbolFileNativePDB::GetOrCreateType(PdbTypeSymId type_id) { … }
VariableSP SymbolFileNativePDB::CreateGlobalVariable(PdbGlobalSymId var_id) { … }
lldb::VariableSP
SymbolFileNativePDB::CreateConstantSymbol(PdbGlobalSymId var_id,
const CVSymbol &cvs) { … }
VariableSP
SymbolFileNativePDB::GetOrCreateGlobalVariable(PdbGlobalSymId var_id) { … }
lldb::TypeSP SymbolFileNativePDB::GetOrCreateType(TypeIndex ti) { … }
FunctionSP SymbolFileNativePDB::GetOrCreateFunction(PdbCompilandSymId func_id,
CompileUnit &comp_unit) { … }
CompUnitSP
SymbolFileNativePDB::GetOrCreateCompileUnit(const CompilandIndexItem &cci) { … }
Block &SymbolFileNativePDB::GetOrCreateBlock(PdbCompilandSymId block_id) { … }
void SymbolFileNativePDB::ParseDeclsForContext(
lldb_private::CompilerDeclContext decl_ctx) { … }
lldb::CompUnitSP SymbolFileNativePDB::ParseCompileUnitAtIndex(uint32_t index) { … }
lldb::LanguageType SymbolFileNativePDB::ParseLanguage(CompileUnit &comp_unit) { … }
void SymbolFileNativePDB::AddSymbols(Symtab &symtab) { … }
size_t SymbolFileNativePDB::ParseFunctions(CompileUnit &comp_unit) { … }
static bool NeedsResolvedCompileUnit(uint32_t resolve_scope) { … }
uint32_t SymbolFileNativePDB::ResolveSymbolContext(
const Address &addr, SymbolContextItem resolve_scope, SymbolContext &sc) { … }
uint32_t SymbolFileNativePDB::ResolveSymbolContext(
const SourceLocationSpec &src_location_spec,
lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) { … }
bool SymbolFileNativePDB::ParseLineTable(CompileUnit &comp_unit) { … }
bool SymbolFileNativePDB::ParseDebugMacros(CompileUnit &comp_unit) { … }
llvm::Expected<uint32_t>
SymbolFileNativePDB::GetFileIndex(const CompilandIndexItem &cii,
uint32_t file_id) { … }
bool SymbolFileNativePDB::ParseSupportFiles(CompileUnit &comp_unit,
SupportFileList &support_files) { … }
bool SymbolFileNativePDB::ParseImportedModules(
const SymbolContext &sc, std::vector<SourceModule> &imported_modules) { … }
void SymbolFileNativePDB::ParseInlineSite(PdbCompilandSymId id,
Address func_addr) { … }
size_t SymbolFileNativePDB::ParseBlocksRecursive(Function &func) { … }
size_t SymbolFileNativePDB::ParseSymbolArrayInScope(
PdbCompilandSymId parent_id,
llvm::function_ref<bool(SymbolKind, PdbCompilandSymId)> fn) { … }
void SymbolFileNativePDB::DumpClangAST(Stream &s) { … }
void SymbolFileNativePDB::FindGlobalVariables(
ConstString name, const CompilerDeclContext &parent_decl_ctx,
uint32_t max_matches, VariableList &variables) { … }
void SymbolFileNativePDB::FindFunctions(
const Module::LookupInfo &lookup_info,
const CompilerDeclContext &parent_decl_ctx, bool include_inlines,
SymbolContextList &sc_list) { … }
void SymbolFileNativePDB::FindFunctions(const RegularExpression ®ex,
bool include_inlines,
SymbolContextList &sc_list) { … }
void SymbolFileNativePDB::FindTypes(const lldb_private::TypeQuery &query,
lldb_private::TypeResults &results) { … }
void SymbolFileNativePDB::FindTypesByName(llvm::StringRef name,
uint32_t max_matches,
TypeMap &types) { … }
size_t SymbolFileNativePDB::ParseTypes(CompileUnit &comp_unit) { … }
size_t
SymbolFileNativePDB::ParseVariablesForCompileUnit(CompileUnit &comp_unit,
VariableList &variables) { … }
VariableSP SymbolFileNativePDB::CreateLocalVariable(PdbCompilandSymId scope_id,
PdbCompilandSymId var_id,
bool is_param) { … }
VariableSP SymbolFileNativePDB::GetOrCreateLocalVariable(
PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param) { … }
TypeSP SymbolFileNativePDB::CreateTypedef(PdbGlobalSymId id) { … }
TypeSP SymbolFileNativePDB::GetOrCreateTypedef(PdbGlobalSymId id) { … }
size_t SymbolFileNativePDB::ParseVariablesForBlock(PdbCompilandSymId block_id) { … }
size_t SymbolFileNativePDB::ParseVariablesForContext(const SymbolContext &sc) { … }
CompilerDecl SymbolFileNativePDB::GetDeclForUID(lldb::user_id_t uid) { … }
CompilerDeclContext
SymbolFileNativePDB::GetDeclContextForUID(lldb::user_id_t uid) { … }
CompilerDeclContext
SymbolFileNativePDB::GetDeclContextContainingUID(lldb::user_id_t uid) { … }
Type *SymbolFileNativePDB::ResolveTypeUID(lldb::user_id_t type_uid) { … }
std::optional<SymbolFile::ArrayInfo>
SymbolFileNativePDB::GetDynamicArrayInfoForUID(
lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) { … }
bool SymbolFileNativePDB::CompleteType(CompilerType &compiler_type) { … }
void SymbolFileNativePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope,
TypeClass type_mask,
lldb_private::TypeList &type_list) { … }
CompilerDeclContext SymbolFileNativePDB::FindNamespace(
ConstString name, const CompilerDeclContext &parent_decl_ctx, bool) { … }
llvm::Expected<lldb::TypeSystemSP>
SymbolFileNativePDB::GetTypeSystemForLanguage(lldb::LanguageType language) { … }
uint64_t SymbolFileNativePDB::GetDebugInfoSize(bool load_all_debug_info) { … }
void SymbolFileNativePDB::BuildParentMap() { … }
std::optional<PdbCompilandSymId>
SymbolFileNativePDB::FindSymbolScope(PdbCompilandSymId id) { … }
std::optional<llvm::codeview::TypeIndex>
SymbolFileNativePDB::GetParentType(llvm::codeview::TypeIndex ti) { … }