Index: include/lldb/Symbol/ClangASTContext.h =================================================================== --- include/lldb/Symbol/ClangASTContext.h +++ include/lldb/Symbol/ClangASTContext.h @@ -30,11 +30,12 @@ // Project includes #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h" -#include "lldb/lldb-enumerations.h" #include "lldb/Core/ClangForward.h" #include "lldb/Core/ConstString.h" #include "lldb/Symbol/CompilerType.h" +#include "lldb/Symbol/DebugInfoASTParser.h" #include "lldb/Symbol/TypeSystem.h" +#include "lldb/lldb-enumerations.h" namespace lldb_private { @@ -520,8 +521,8 @@ //------------------------------------------------------------------ // TypeSystem methods //------------------------------------------------------------------ - DWARFASTParser * - GetDWARFParser () override; + DebugInfoASTParser * + GetDebugInfoASTParser() override; //------------------------------------------------------------------ // ClangASTContext callbacks for external source lookups. @@ -1212,6 +1213,7 @@ //------------------------------------------------------------------ // Classes that inherit from ClangASTContext can see and modify these //------------------------------------------------------------------ + // clang-format off std::string m_target_triple; std::unique_ptr m_ast_ap; std::unique_ptr m_language_options_ap; @@ -1225,7 +1227,7 @@ std::unique_ptr m_identifier_table_ap; std::unique_ptr m_selector_table_ap; std::unique_ptr m_builtins_ap; - std::unique_ptr m_dwarf_ast_parser_ap; + std::unique_ptr m_di_ast_parser_ap; std::unique_ptr m_scratch_ast_source_ap; std::unique_ptr m_mangle_ctx_ap; CompleteTagDeclCallback m_callback_tag_decl; @@ -1235,7 +1237,7 @@ bool m_ast_owned; bool m_can_evaluate_expressions; std::map> m_decl_objects; - + // clang-format on private: //------------------------------------------------------------------ // For ClangASTContext only Index: include/lldb/Symbol/DebugInfoASTParser.h =================================================================== --- /dev/null +++ include/lldb/Symbol/DebugInfoASTParser.h @@ -0,0 +1,56 @@ +//===-- DebugInfoASTParser.h ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_INCLUDE_SYMBOL_DEBUGINFO_AST_PARSER_H +#define LLDB_INCLUDE_SYMBOL_DEBUGINFO_AST_PARSER_H + +#include "lldb/Symbol/CompilerType.h" +#include "lldb/Symbol/SymbolFile.h" + +#include "llvm/ADT/DenseMap.h" +#include "llvm/Support/Casting.h" + +#include "clang/AST/CharUnits.h" + +#define DECLARE_DEBUG_INFO_PARSER_TYPE(TypeValue) \ + static const lldb_private::SymbolFileFormat type = TypeValue; \ + lldb_private::SymbolFileFormat GetDebugInfoFormat() const override { return TypeValue; } \ + static bool classof(const DebugInfoASTParser *parser) { return parser->GetDebugInfoFormat() == type; } + +class DebugInfoASTParser +{ +public: + virtual ~DebugInfoASTParser() {} + + virtual lldb_private::SymbolFileFormat + GetDebugInfoFormat() const = 0; + + virtual bool + CanCompleteType(const lldb_private::CompilerType &compiler_type) + { + return false; + } + + virtual bool + CompleteType(const lldb_private::CompilerType &compiler_type) + { + return false; + } + + virtual bool + LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment, + llvm::DenseMap &field_offsets, + llvm::DenseMap &base_offsets, + llvm::DenseMap &vbase_offsets) + { + return false; + } +}; + +#endif // LLDB_INCLUDE_SYMBOL_DEBUGINFO_AST_PARSER_H Index: include/lldb/Symbol/GoASTContext.h =================================================================== --- include/lldb/Symbol/GoASTContext.h +++ include/lldb/Symbol/GoASTContext.h @@ -23,6 +23,7 @@ #include "lldb/Core/ConstString.h" #include "lldb/Symbol/TypeSystem.h" #include "lldb/Symbol/CompilerType.h" +class DWARFASTParser; namespace lldb_private { @@ -59,8 +60,9 @@ static void Terminate (); - - DWARFASTParser *GetDWARFParser() override; + + DebugInfoASTParser * + GetDebugInfoASTParser() override; void SetAddressByteSize(int byte_size) Index: include/lldb/Symbol/JavaASTContext.h =================================================================== --- include/lldb/Symbol/JavaASTContext.h +++ include/lldb/Symbol/JavaASTContext.h @@ -21,6 +21,8 @@ #include "lldb/Core/ConstString.h" #include "lldb/Symbol/TypeSystem.h" +class DWARFASTParser; + namespace lldb_private { @@ -58,8 +60,8 @@ static void Terminate(); - DWARFASTParser * - GetDWARFParser() override; + DebugInfoASTParser * + GetDebugInfoASTParser() override; uint32_t GetPointerByteSize() override; Index: include/lldb/Symbol/SymbolFile.h =================================================================== --- include/lldb/Symbol/SymbolFile.h +++ include/lldb/Symbol/SymbolFile.h @@ -21,6 +21,13 @@ namespace lldb_private { +enum class SymbolFileFormat +{ + DWARF, + PDB, + Other +}; + class SymbolFile : public PluginInterface { @@ -115,6 +122,12 @@ //------------------------------------------------------------------ virtual void InitializeObject() {} + virtual SymbolFileFormat + GetSymbolFileFormat() const + { + return SymbolFileFormat::Other; + } + //------------------------------------------------------------------ // Compile Unit function calls //------------------------------------------------------------------ @@ -154,12 +167,10 @@ lldb_private::TypeList &type_list) = 0; virtual lldb_private::TypeSystem * - GetTypeSystemForLanguage (lldb::LanguageType language); + GetTypeSystemForLanguage(lldb::LanguageType language); virtual CompilerDeclContext - FindNamespace (const SymbolContext& sc, - const ConstString &name, - const CompilerDeclContext *parent_decl_ctx) + FindNamespace(const SymbolContext &sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx) { return CompilerDeclContext(); } Index: include/lldb/Symbol/TypeSystem.h =================================================================== --- include/lldb/Symbol/TypeSystem.h +++ include/lldb/Symbol/TypeSystem.h @@ -28,8 +28,7 @@ #include "lldb/Symbol/CompilerDecl.h" #include "lldb/Symbol/CompilerDeclContext.h" -class DWARFDIE; -class DWARFASTParser; +class DebugInfoASTParser; namespace lldb_private { @@ -99,8 +98,8 @@ virtual void Finalize() {} - virtual DWARFASTParser * - GetDWARFParser () + virtual DebugInfoASTParser * + GetDebugInfoASTParser() { return nullptr; } Index: source/Plugins/SymbolFile/DWARF/DWARFASTParser.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFASTParser.h +++ source/Plugins/SymbolFile/DWARF/DWARFASTParser.h @@ -14,14 +14,17 @@ #include "lldb/Core/PluginInterface.h" #include "lldb/Symbol/CompilerDecl.h" #include "lldb/Symbol/CompilerDeclContext.h" +#include "lldb/Symbol/DebugInfoASTParser.h" class DWARFDIE; -class DWARFASTParser +class DWARFASTParser : public DebugInfoASTParser { public: virtual ~DWARFASTParser() {} + DECLARE_DEBUG_INFO_PARSER_TYPE(lldb_private::SymbolFileFormat::DWARF) + virtual lldb::TypeSP ParseTypeFromDWARF (const lldb_private::SymbolContext& sc, const DWARFDIE &die, @@ -33,18 +36,6 @@ const DWARFDIE &die) = 0; virtual bool - CanCompleteType (const lldb_private::CompilerType &compiler_type) - { - return false; - } - - virtual bool - CompleteType (const lldb_private::CompilerType &compiler_type) - { - return false; - } - - virtual bool CompleteTypeFromDWARF (const DWARFDIE &die, lldb_private::Type *type, lldb_private::CompilerType &compiler_type) = 0; Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h +++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h @@ -70,12 +70,10 @@ GetDeclContextContainingUIDFromDWARF (const DWARFDIE &die) override; bool - LayoutRecordType(const clang::RecordDecl *record_decl, - uint64_t &bit_size, - uint64_t &alignment, + LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment, llvm::DenseMap &field_offsets, llvm::DenseMap &base_offsets, - llvm::DenseMap &vbase_offsets); + llvm::DenseMap &vbase_offsets) override; protected: class DelayedAddObjCClassProperty; Index: source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp @@ -9,18 +9,20 @@ #include "DWARFDIE.h" +#include "DWARFASTParser.h" #include "DWARFCompileUnit.h" +#include "DWARFDIECollection.h" #include "DWARFDebugAbbrev.h" #include "DWARFDebugAranges.h" #include "DWARFDebugInfo.h" #include "DWARFDebugInfoEntry.h" #include "DWARFDebugRanges.h" #include "DWARFDeclContext.h" -#include "DWARFDIECollection.h" #include "DWARFFormValue.h" #include "SymbolFileDWARF.h" #include "lldb/Core/Module.h" +#include "lldb/Symbol/DebugInfoASTParser.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/Type.h" #include "lldb/Symbol/TypeSystem.h" @@ -406,7 +408,7 @@ { lldb_private::TypeSystem *type_system = GetTypeSystem (); if (type_system) - return type_system->GetDWARFParser(); + return llvm::dyn_cast(type_system->GetDebugInfoASTParser()); else return nullptr; } Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -107,6 +107,9 @@ void InitializeObject() override; + lldb_private::SymbolFileFormat + GetSymbolFileFormat() const override; + //------------------------------------------------------------------ // Compile Unit function calls //------------------------------------------------------------------ @@ -243,7 +246,6 @@ const lldb_private::ConstString &name, const lldb_private::CompilerDeclContext *parent_decl_ctx) override; - //------------------------------------------------------------------ // PluginInterface protocol //------------------------------------------------------------------ Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -569,6 +569,12 @@ } } +SymbolFileFormat +SymbolFileDWARF::GetSymbolFileFormat() const +{ + return SymbolFileFormat::DWARF; +} + bool SymbolFileDWARF::SupportedVersion(uint16_t version) { @@ -996,7 +1002,7 @@ if (type_system) { - DWARFASTParser *dwarf_ast = type_system->GetDWARFParser(); + DWARFASTParser *dwarf_ast = llvm::dyn_cast_or_null(type_system->GetDebugInfoASTParser()); if (dwarf_ast) return dwarf_ast->ParseFunctionFromDWARF(sc, die); } @@ -1461,7 +1467,7 @@ SymbolFileDWARF::ParseDeclsForContext (CompilerDeclContext decl_ctx) { TypeSystem *type_system = decl_ctx.GetTypeSystem(); - DWARFASTParser *ast_parser = type_system->GetDWARFParser(); + DWARFASTParser *ast_parser = llvm::dyn_cast_or_null(type_system->GetDebugInfoASTParser()); std::vector decl_ctx_die_list = ast_parser->GetDIEForDeclContext(decl_ctx); for (DWARFDIE decl_ctx_die : decl_ctx_die_list) @@ -1611,9 +1617,9 @@ TypeSystem *type_system = compiler_type.GetTypeSystem(); if (type_system) { - DWARFASTParser *dwarf_ast = type_system->GetDWARFParser(); - if (dwarf_ast) - return dwarf_ast->CanCompleteType(compiler_type); + DebugInfoASTParser *ast_parser = type_system->GetDebugInfoASTParser(); + if (ast_parser) + return ast_parser->CanCompleteType(compiler_type); } return false; } @@ -1627,7 +1633,7 @@ TypeSystem *type_system = compiler_type.GetTypeSystem(); if (type_system) { - DWARFASTParser *dwarf_ast = type_system->GetDWARFParser(); + DebugInfoASTParser *dwarf_ast = type_system->GetDebugInfoASTParser(); if (dwarf_ast && dwarf_ast->CanCompleteType(compiler_type)) return dwarf_ast->CompleteType(compiler_type); } @@ -3823,7 +3829,7 @@ if (type_system) { - DWARFASTParser *dwarf_ast = type_system->GetDWARFParser(); + DWARFASTParser *dwarf_ast = llvm::dyn_cast_or_null(type_system->GetDebugInfoASTParser()); if (dwarf_ast) { Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); Index: source/Plugins/SymbolFile/PDB/SymbolFilePDB.h =================================================================== --- source/Plugins/SymbolFile/PDB/SymbolFilePDB.h +++ source/Plugins/SymbolFile/PDB/SymbolFilePDB.h @@ -55,6 +55,9 @@ void InitializeObject() override; + lldb_private::SymbolFileFormat + GetSymbolFileFormat() const override; + //------------------------------------------------------------------ // Compile Unit function calls //------------------------------------------------------------------ Index: source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp =================================================================== --- source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp +++ source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp @@ -118,6 +118,12 @@ m_session_up->setLoadAddress(obj_load_address); } +lldb_private::SymbolFileFormat +SymbolFilePDB::GetSymbolFileFormat() const +{ + return SymbolFileFormat::PDB; +} + uint32_t SymbolFilePDB::GetNumCompileUnits() { Index: source/Symbol/ClangASTContext.cpp =================================================================== --- source/Symbol/ClangASTContext.cpp +++ source/Symbol/ClangASTContext.cpp @@ -9653,16 +9653,17 @@ } } - -DWARFASTParser * -ClangASTContext::GetDWARFParser () +DebugInfoASTParser * +ClangASTContext::GetDebugInfoASTParser() { - if (!m_dwarf_ast_parser_ap) - m_dwarf_ast_parser_ap.reset(new DWARFASTParserClang(*this)); - return m_dwarf_ast_parser_ap.get(); + if (!m_di_ast_parser_ap) + { + if (m_sym_file->GetSymbolFileFormat() == SymbolFileFormat::DWARF) + m_di_ast_parser_ap.reset(new DWARFASTParserClang(*this)); + } + return m_di_ast_parser_ap.get(); } - bool ClangASTContext::LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, @@ -9673,8 +9674,9 @@ llvm::DenseMap &vbase_offsets) { ClangASTContext *ast = (ClangASTContext *)baton; - DWARFASTParserClang *dwarf_ast_parser = (DWARFASTParserClang *)ast->GetDWARFParser(); - return dwarf_ast_parser->LayoutRecordType(record_decl, bit_size, alignment, field_offsets, base_offsets, vbase_offsets); + DebugInfoASTParser *di_ast_parser = ast->GetDebugInfoASTParser(); + return di_ast_parser->LayoutRecordType(record_decl, bit_size, alignment, field_offsets, base_offsets, + vbase_offsets); } //---------------------------------------------------------------------- Index: source/Symbol/GoASTContext.cpp =================================================================== --- source/Symbol/GoASTContext.cpp +++ source/Symbol/GoASTContext.cpp @@ -1639,8 +1639,8 @@ return (kind & GoType::KIND_DIRECT_IFACE) == GoType::KIND_DIRECT_IFACE; } -DWARFASTParser * -GoASTContext::GetDWARFParser() +DebugInfoASTParser * +GoASTContext::GetDebugInfoASTParser() { if (!m_dwarf_ast_parser_ap) m_dwarf_ast_parser_ap.reset(new DWARFASTParserGo(*this)); Index: source/Symbol/JavaASTContext.cpp =================================================================== --- source/Symbol/JavaASTContext.cpp +++ source/Symbol/JavaASTContext.cpp @@ -496,8 +496,8 @@ return m_pointer_byte_size; } -DWARFASTParser * -JavaASTContext::GetDWARFParser() +DebugInfoASTParser * +JavaASTContext::GetDebugInfoASTParser() { if (!m_dwarf_ast_parser_ap) m_dwarf_ast_parser_ap.reset(new DWARFASTParserJava(*this));