Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
39642 views
//===-- SymbolFileNativePDB.h -----------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H9#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H1011#include "lldb/Symbol/LineTable.h"12#include "lldb/Symbol/SymbolFile.h"1314#include "llvm/ADT/DenseMap.h"15#include "llvm/DebugInfo/CodeView/CVRecord.h"16#include "llvm/DebugInfo/CodeView/SymbolRecord.h"17#include "llvm/DebugInfo/PDB/PDBTypes.h"1819#include "CompileUnitIndex.h"20#include "PdbIndex.h"21#include "PdbAstBuilder.h"22#include <optional>2324namespace clang {25class TagDecl;26}2728namespace llvm {29namespace codeview {30class ClassRecord;31class EnumRecord;32class ModifierRecord;33class PointerRecord;34struct UnionRecord;35} // namespace codeview36} // namespace llvm3738namespace lldb_private {3940namespace npdb {4142class SymbolFileNativePDB : public SymbolFileCommon {43friend class UdtRecordCompleter;4445/// LLVM RTTI support.46static char ID;4748public:49/// LLVM RTTI support.50/// \{51bool isA(const void *ClassID) const override {52return ClassID == &ID || SymbolFileCommon::isA(ClassID);53}54static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }55/// \}5657// Static Functions58static void Initialize();5960static void Terminate();6162static void DebuggerInitialize(Debugger &debugger);6364static llvm::StringRef GetPluginNameStatic() { return "native-pdb"; }6566static llvm::StringRef GetPluginDescriptionStatic();6768static SymbolFile *CreateInstance(lldb::ObjectFileSP objfile_sp);6970// Constructors and Destructors71SymbolFileNativePDB(lldb::ObjectFileSP objfile_sp);7273~SymbolFileNativePDB() override;7475uint32_t CalculateAbilities() override;7677void InitializeObject() override;7879uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override;8081// Compile Unit function calls8283void84ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;8586lldb::LanguageType87ParseLanguage(lldb_private::CompileUnit &comp_unit) override;8889size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;9091bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;9293bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;9495bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit,96SupportFileList &support_files) override;97size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;9899bool ParseImportedModules(100const SymbolContext &sc,101std::vector<lldb_private::SourceModule> &imported_modules) override;102103size_t ParseBlocksRecursive(Function &func) override;104105void FindGlobalVariables(ConstString name,106const CompilerDeclContext &parent_decl_ctx,107uint32_t max_matches,108VariableList &variables) override;109110size_t ParseVariablesForContext(const SymbolContext &sc) override;111112void AddSymbols(Symtab &symtab) override;113114CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;115CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override;116CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override;117Type *ResolveTypeUID(lldb::user_id_t type_uid) override;118std::optional<ArrayInfo> GetDynamicArrayInfoForUID(119lldb::user_id_t type_uid,120const lldb_private::ExecutionContext *exe_ctx) override;121122bool CompleteType(CompilerType &compiler_type) override;123uint32_t ResolveSymbolContext(const Address &so_addr,124lldb::SymbolContextItem resolve_scope,125SymbolContext &sc) override;126uint32_t ResolveSymbolContext(const SourceLocationSpec &src_location_spec,127lldb::SymbolContextItem resolve_scope,128SymbolContextList &sc_list) override;129130void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,131TypeList &type_list) override;132133void FindFunctions(const Module::LookupInfo &lookup_info,134const CompilerDeclContext &parent_decl_ctx,135bool include_inlines, SymbolContextList &sc_list) override;136137void FindFunctions(const RegularExpression ®ex, bool include_inlines,138SymbolContextList &sc_list) override;139140std::optional<PdbCompilandSymId> FindSymbolScope(PdbCompilandSymId id);141142void FindTypes(const lldb_private::TypeQuery &match,143lldb_private::TypeResults &results) override;144145llvm::Expected<lldb::TypeSystemSP>146GetTypeSystemForLanguage(lldb::LanguageType language) override;147148CompilerDeclContext FindNamespace(ConstString name,149const CompilerDeclContext &parent_decl_ctx,150bool only_root_namespaces) override;151152llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }153154llvm::pdb::PDBFile &GetPDBFile() { return m_index->pdb(); }155const llvm::pdb::PDBFile &GetPDBFile() const { return m_index->pdb(); }156157PdbIndex &GetIndex() { return *m_index; };158159void DumpClangAST(Stream &s) override;160161std::optional<llvm::codeview::TypeIndex>162GetParentType(llvm::codeview::TypeIndex ti);163164private:165struct LineTableEntryComparator {166bool operator()(const lldb_private::LineTable::Entry &lhs,167const lldb_private::LineTable::Entry &rhs) const {168return lhs.file_addr < rhs.file_addr;169}170};171172// From address range relative to function base to source line number.173using RangeSourceLineVector =174lldb_private::RangeDataVector<uint32_t, uint32_t, int32_t>;175// InlineSite contains information in a S_INLINESITE record.176struct InlineSite {177PdbCompilandSymId parent_id;178std::shared_ptr<InlineFunctionInfo> inline_function_info;179RangeSourceLineVector ranges;180std::vector<lldb_private::LineTable::Entry> line_entries;181InlineSite(PdbCompilandSymId parent_id) : parent_id(parent_id){};182};183184void BuildParentMap();185186uint32_t CalculateNumCompileUnits() override;187188lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;189190void FindTypesByName(llvm::StringRef name, uint32_t max_matches,191TypeMap &types);192193lldb::TypeSP CreateModifierType(PdbTypeSymId type_id,194const llvm::codeview::ModifierRecord &mr,195CompilerType ct);196lldb::TypeSP CreatePointerType(PdbTypeSymId type_id,197const llvm::codeview::PointerRecord &pr,198CompilerType ct);199lldb::TypeSP CreateSimpleType(llvm::codeview::TypeIndex ti, CompilerType ct);200lldb::TypeSP CreateTagType(PdbTypeSymId type_id,201const llvm::codeview::ClassRecord &cr,202CompilerType ct);203lldb::TypeSP CreateTagType(PdbTypeSymId type_id,204const llvm::codeview::EnumRecord &er,205CompilerType ct);206lldb::TypeSP CreateTagType(PdbTypeSymId type_id,207const llvm::codeview::UnionRecord &ur,208CompilerType ct);209lldb::TypeSP CreateArrayType(PdbTypeSymId type_id,210const llvm::codeview::ArrayRecord &ar,211CompilerType ct);212lldb::TypeSP CreateFunctionType(PdbTypeSymId type_id,213const llvm::codeview::MemberFunctionRecord &pr,214CompilerType ct);215lldb::TypeSP CreateProcedureType(PdbTypeSymId type_id,216const llvm::codeview::ProcedureRecord &pr,217CompilerType ct);218lldb::TypeSP CreateClassStructUnion(PdbTypeSymId type_id,219const llvm::codeview::TagRecord &record,220size_t size, CompilerType ct);221222lldb::FunctionSP GetOrCreateFunction(PdbCompilandSymId func_id,223CompileUnit &comp_unit);224lldb::CompUnitSP GetOrCreateCompileUnit(const CompilandIndexItem &cci);225lldb::TypeSP GetOrCreateType(PdbTypeSymId type_id);226lldb::TypeSP GetOrCreateType(llvm::codeview::TypeIndex ti);227lldb::VariableSP GetOrCreateGlobalVariable(PdbGlobalSymId var_id);228Block &GetOrCreateBlock(PdbCompilandSymId block_id);229lldb::VariableSP GetOrCreateLocalVariable(PdbCompilandSymId scope_id,230PdbCompilandSymId var_id,231bool is_param);232lldb::TypeSP GetOrCreateTypedef(PdbGlobalSymId id);233234lldb::FunctionSP CreateFunction(PdbCompilandSymId func_id,235CompileUnit &comp_unit);236Block &CreateBlock(PdbCompilandSymId block_id);237lldb::VariableSP CreateLocalVariable(PdbCompilandSymId scope_id,238PdbCompilandSymId var_id, bool is_param);239lldb::TypeSP CreateTypedef(PdbGlobalSymId id);240lldb::CompUnitSP CreateCompileUnit(const CompilandIndexItem &cci);241lldb::TypeSP CreateType(PdbTypeSymId type_id, CompilerType ct);242lldb::TypeSP CreateAndCacheType(PdbTypeSymId type_id);243lldb::VariableSP CreateGlobalVariable(PdbGlobalSymId var_id);244lldb::VariableSP CreateConstantSymbol(PdbGlobalSymId var_id,245const llvm::codeview::CVSymbol &cvs);246size_t ParseVariablesForCompileUnit(CompileUnit &comp_unit,247VariableList &variables);248size_t ParseVariablesForBlock(PdbCompilandSymId block_id);249250llvm::Expected<uint32_t> GetFileIndex(const CompilandIndexItem &cii,251uint32_t file_id);252253size_t ParseSymbolArrayInScope(254PdbCompilandSymId parent,255llvm::function_ref<bool(llvm::codeview::SymbolKind, PdbCompilandSymId)>256fn);257258void ParseInlineSite(PdbCompilandSymId inline_site_id, Address func_addr);259260llvm::BumpPtrAllocator m_allocator;261262lldb::addr_t m_obj_load_address = 0;263bool m_done_full_type_scan = false;264// UID for anonymous union and anonymous struct as they don't have entities in265// pdb debug info.266lldb::user_id_t anonymous_id = LLDB_INVALID_UID - 1;267268std::unique_ptr<llvm::pdb::PDBFile> m_file_up;269std::unique_ptr<PdbIndex> m_index;270271llvm::DenseMap<lldb::user_id_t, lldb::VariableSP> m_global_vars;272llvm::DenseMap<lldb::user_id_t, lldb::VariableSP> m_local_variables;273llvm::DenseMap<lldb::user_id_t, lldb::BlockSP> m_blocks;274llvm::DenseMap<lldb::user_id_t, lldb::FunctionSP> m_functions;275llvm::DenseMap<lldb::user_id_t, lldb::CompUnitSP> m_compilands;276llvm::DenseMap<lldb::user_id_t, lldb::TypeSP> m_types;277llvm::DenseMap<lldb::user_id_t, std::shared_ptr<InlineSite>> m_inline_sites;278llvm::DenseMap<llvm::codeview::TypeIndex, llvm::codeview::TypeIndex>279m_parent_types;280};281282} // namespace npdb283} // namespace lldb_private284285#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H286287288