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/ClangTypeImportHelper.h =================================================================== --- /dev/null +++ include/lldb/Symbol/ClangTypeImportHelper.h @@ -0,0 +1,61 @@ +//===-- ClangTypeImportHelper.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_SYMBOL_CLANG_TYPE_IMPORT_HELPER_H +#define LLDB_SYMBOL_CLANG_TYPE_IMPORT_HELPER_H + +#include "clang/AST/CharUnits.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" + +#include "lldb/Symbol/ClangASTImporter.h" + +#include "llvm/ADT/DenseMap.h" + +namespace lldb_private +{ + +class ClangASTImporter; + +class ClangTypeImportHelper +{ +public: + struct LayoutInfo + { + LayoutInfo() : bit_size(0), alignment(0), field_offsets(), base_offsets(), vbase_offsets() {} + uint64_t bit_size; + uint64_t alignment; + llvm::DenseMap field_offsets; + llvm::DenseMap base_offsets; + llvm::DenseMap vbase_offsets; + }; + + bool + CanCompleteType(const lldb_private::CompilerType &compiler_type, ClangASTImporter &importer); + + bool + CompleteType(const lldb_private::CompilerType &compiler_type, ClangASTImporter &importer); + + void + InsertRecordDecl(clang::RecordDecl *decl, const LayoutInfo &layout); + + 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); + +private: + typedef llvm::DenseMap RecordDeclToLayoutMap; + + RecordDeclToLayoutMap m_record_decl_to_layout_map; +}; +} + +#endif 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 @@ -19,11 +19,12 @@ #include "clang/AST/CharUnits.h" // Project includes +#include "DWARFASTParser.h" +#include "DWARFDefines.h" #include "lldb/Core/ClangForward.h" #include "lldb/Core/PluginInterface.h" #include "lldb/Symbol/ClangASTContext.h" -#include "DWARFDefines.h" -#include "DWARFASTParser.h" +#include "lldb/Symbol/ClangTypeImportHelper.h" class DWARFDebugInfoEntry; class DWARFDIECollection; @@ -35,17 +36,7 @@ ~DWARFASTParserClang() override; - lldb::TypeSP - ParseTypeFromDWARF (const lldb_private::SymbolContext& sc, - const DWARFDIE &die, - lldb_private::Log *log, - bool *type_is_new_ptr) override; - - - lldb_private::Function * - ParseFunctionFromDWARF (const lldb_private::SymbolContext& sc, - const DWARFDIE &die) override; - + // DebugInfoASTParser interface bool CanCompleteType (const lldb_private::CompilerType &compiler_type) override; @@ -53,9 +44,22 @@ CompleteType (const lldb_private::CompilerType &compiler_type) override; bool - CompleteTypeFromDWARF (const DWARFDIE &die, - lldb_private::Type *type, - lldb_private::CompilerType &compiler_type) override; + 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) override; + + // DWARFASTParser interface. + lldb::TypeSP + ParseTypeFromDWARF(const lldb_private::SymbolContext &sc, const DWARFDIE &die, lldb_private::Log *log, + bool *type_is_new_ptr) override; + + lldb_private::Function * + ParseFunctionFromDWARF(const lldb_private::SymbolContext &sc, const DWARFDIE &die) override; + + bool + CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type, + lldb_private::CompilerType &compiler_type) override; lldb_private::CompilerDecl GetDeclForUIDFromDWARF (const DWARFDIE &die) override; @@ -69,43 +73,16 @@ lldb_private::CompilerDeclContext GetDeclContextContainingUIDFromDWARF (const DWARFDIE &die) override; - 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); - protected: class DelayedAddObjCClassProperty; typedef std::vector DelayedPropertyList; - struct LayoutInfo - { - LayoutInfo () : - bit_size(0), - alignment(0), - field_offsets(), - base_offsets(), - vbase_offsets() - { - } - uint64_t bit_size; - uint64_t alignment; - llvm::DenseMap field_offsets; - llvm::DenseMap base_offsets; - llvm::DenseMap vbase_offsets; - }; - clang::BlockDecl * ResolveBlockDIE (const DWARFDIE &die); clang::NamespaceDecl * ResolveNamespaceDIE (const DWARFDIE &die); - typedef llvm::DenseMap RecordDeclToLayoutMap; - bool ParseTemplateDIE (const DWARFDIE &die, lldb_private::ClangASTContext::TemplateParameterInfos &template_param_infos); @@ -114,17 +91,12 @@ lldb_private::ClangASTContext::TemplateParameterInfos &template_param_infos); bool - ParseChildMembers (const lldb_private::SymbolContext& sc, - const DWARFDIE &die, - lldb_private::CompilerType &class_compiler_type, - const lldb::LanguageType class_language, - std::vector& base_classes, - std::vector& member_accessibilities, - DWARFDIECollection& member_function_dies, - DelayedPropertyList& delayed_properties, - lldb::AccessType &default_accessibility, - bool &is_a_class, - LayoutInfo &layout_info); + ParseChildMembers(const lldb_private::SymbolContext &sc, const DWARFDIE &die, + lldb_private::CompilerType &class_compiler_type, const lldb::LanguageType class_language, + std::vector &base_classes, std::vector &member_accessibilities, + DWARFDIECollection &member_function_dies, DelayedPropertyList &delayed_properties, + lldb::AccessType &default_accessibility, bool &is_a_class, + lldb_private::ClangTypeImportHelper::LayoutInfo &layout_info); size_t ParseChildParameters (const lldb_private::SymbolContext& sc, @@ -207,7 +179,7 @@ DeclToDIEMap m_decl_to_die; DIEToDeclContextMap m_die_to_decl_ctx; DeclContextToDIEMap m_decl_ctx_to_die; - RecordDeclToLayoutMap m_record_decl_to_layout_map; + lldb_private::ClangTypeImportHelper m_type_import_helper; std::unique_ptr m_clang_ast_importer_ap; }; Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -123,9 +123,7 @@ DWARFASTParserClang::GetClangASTImporter() { if (!m_clang_ast_importer_ap) - { m_clang_ast_importer_ap.reset (new ClangASTImporter); - } return *m_clang_ast_importer_ap; } @@ -865,7 +863,8 @@ clang::RecordDecl *record_decl = ClangASTContext::GetAsRecordDecl(clang_type); if (record_decl) - m_record_decl_to_layout_map.insert(std::make_pair(record_decl, LayoutInfo())); + m_type_import_helper.InsertRecordDecl(record_decl, + ClangTypeImportHelper::LayoutInfo()); } } else if (clang_type_was_created) @@ -1990,34 +1989,27 @@ bool DWARFASTParserClang::CanCompleteType (const lldb_private::CompilerType &compiler_type) { - if (m_clang_ast_importer_ap) - return ClangASTContext::CanImport(compiler_type, GetClangASTImporter()); - else - return false; + return m_type_import_helper.CanCompleteType(compiler_type, GetClangASTImporter()); } bool DWARFASTParserClang::CompleteType (const lldb_private::CompilerType &compiler_type) { - if (CanCompleteType(compiler_type)) - { - if (ClangASTContext::Import(compiler_type, GetClangASTImporter())) - { - ClangASTContext::CompleteTagDeclarationDefinition(compiler_type); - return true; - } - else - { - ClangASTContext::SetHasExternalStorage (compiler_type.GetOpaqueQualType(), false); - } - } - return false; + return m_type_import_helper.CompleteType(compiler_type, GetClangASTImporter()); } bool -DWARFASTParserClang::CompleteTypeFromDWARF (const DWARFDIE &die, - lldb_private::Type *type, - CompilerType &clang_type) +DWARFASTParserClang::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 m_type_import_helper.LayoutRecordType(record_decl, bit_size, alignment, field_offsets, base_offsets, + vbase_offsets); +} + +bool +DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type, CompilerType &clang_type) { SymbolFileDWARF *dwarf = die.GetDWARF(); @@ -2047,7 +2039,7 @@ case DW_TAG_union_type: case DW_TAG_class_type: { - LayoutInfo layout_info; + ClangTypeImportHelper::LayoutInfo layout_info; { if (die.HasChildren()) @@ -2283,7 +2275,7 @@ } } - m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); + m_type_import_helper.InsertRecordDecl(record_decl, layout_info); } } } @@ -2623,19 +2615,14 @@ return NULL; } - bool -DWARFASTParserClang::ParseChildMembers (const SymbolContext& sc, - const DWARFDIE &parent_die, - CompilerType &class_clang_type, - const LanguageType class_language, - std::vector& base_classes, - std::vector& member_accessibilities, - DWARFDIECollection& member_function_dies, - DelayedPropertyList& delayed_properties, - AccessType& default_accessibility, - bool &is_a_class, - LayoutInfo &layout_info) +DWARFASTParserClang::ParseChildMembers(const SymbolContext &sc, const DWARFDIE &parent_die, + CompilerType &class_clang_type, const LanguageType class_language, + std::vector &base_classes, + std::vector &member_accessibilities, + DWARFDIECollection &member_function_dies, + DelayedPropertyList &delayed_properties, AccessType &default_accessibility, + bool &is_a_class, ClangTypeImportHelper::LayoutInfo &layout_info) { if (!parent_die) return 0; @@ -4071,34 +4058,3 @@ return (failures.Size() != 0); } - -bool -DWARFASTParserClang::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) -{ - RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); - bool success = false; - base_offsets.clear(); - vbase_offsets.clear(); - if (pos != m_record_decl_to_layout_map.end()) - { - bit_size = pos->second.bit_size; - alignment = pos->second.alignment; - field_offsets.swap(pos->second.field_offsets); - base_offsets.swap (pos->second.base_offsets); - vbase_offsets.swap (pos->second.vbase_offsets); - m_record_decl_to_layout_map.erase(pos); - success = true; - } - else - { - bit_size = 0; - alignment = 0; - field_offsets.clear(); - } - return success; -} 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/CMakeLists.txt =================================================================== --- source/Symbol/CMakeLists.txt +++ source/Symbol/CMakeLists.txt @@ -5,6 +5,7 @@ ClangASTImporter.cpp ClangExternalASTSourceCallbacks.cpp ClangExternalASTSourceCommon.cpp + ClangTypeImportHelper.cpp CompilerDecl.cpp CompilerDeclContext.cpp CompilerType.cpp 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/ClangTypeImportHelper.cpp =================================================================== --- /dev/null +++ source/Symbol/ClangTypeImportHelper.cpp @@ -0,0 +1,71 @@ +//===-- ClangTypeImportHelper.cpp -------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Symbol/ClangTypeImportHelper.h" +#include "lldb/Symbol/ClangASTContext.h" +#include "lldb/Symbol/ClangASTImporter.h" + +using namespace lldb_private; + +bool +ClangTypeImportHelper::CanCompleteType(const CompilerType &compiler_type, ClangASTImporter &importer) +{ + return ClangASTContext::CanImport(compiler_type, importer); +} + +bool +ClangTypeImportHelper::CompleteType(const CompilerType &compiler_type, ClangASTImporter &importer) +{ + if (!CanCompleteType(compiler_type, importer)) + return false; + + if (ClangASTContext::Import(compiler_type, importer)) + { + ClangASTContext::CompleteTagDeclarationDefinition(compiler_type); + return true; + } + + ClangASTContext::SetHasExternalStorage(compiler_type.GetOpaqueQualType(), false); + return false; +} + +bool +ClangTypeImportHelper::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) +{ + RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find(record_decl); + bool success = false; + base_offsets.clear(); + vbase_offsets.clear(); + if (pos != m_record_decl_to_layout_map.end()) + { + bit_size = pos->second.bit_size; + alignment = pos->second.alignment; + field_offsets.swap(pos->second.field_offsets); + base_offsets.swap(pos->second.base_offsets); + vbase_offsets.swap(pos->second.vbase_offsets); + m_record_decl_to_layout_map.erase(pos); + success = true; + } + else + { + bit_size = 0; + alignment = 0; + field_offsets.clear(); + } + return success; +} + +void +ClangTypeImportHelper::InsertRecordDecl(clang::RecordDecl *decl, const LayoutInfo &layout) +{ + m_record_decl_to_layout_map.insert(std::make_pair(decl, layout)); +} \ No newline at end of file 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));