diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h b/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h @@ -10,6 +10,7 @@ #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DIEREF_H #include "lldb/Core/dwarf.h" +#include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/Optional.h" #include "llvm/Support/FormatProviders.h" #include @@ -66,6 +67,10 @@ } private: + friend struct llvm::DenseMapInfo; + DIERef(unsigned unique) : m_u(llvm::None, DebugInfo), m_die_offset(0) { + m_u.s.dwo_num = unique; + } uint32_t get_hash_value() const { return llvm::detail::combineHashValue(m_u.hash_bits, m_die_offset); } @@ -93,6 +98,16 @@ template<> struct format_provider { static void format(const DIERef &ref, raw_ostream &OS, StringRef Style); }; + +/// DenseMapInfo implementation. +/// \{ +template <> struct DenseMapInfo { + static inline DIERef getEmptyKey() { return DIERef(1); } + static inline DIERef getTombstoneKey() { return DIERef(2); } + static unsigned getHashValue(DIERef val) { return val.get_hash_value(); } + static bool isEqual(DIERef LHS, DIERef RHS) { return LHS == RHS; } +}; +/// \} } // namespace llvm #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DIEREF_H diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h @@ -73,8 +73,7 @@ class DelayedAddObjCClassProperty; typedef std::vector DelayedPropertyList; - typedef llvm::DenseMap - DIEToDeclContextMap; + typedef llvm::DenseMap DIERefToDeclContextMap; typedef std::multimap> DeclContextToFileDIERefMap; @@ -86,7 +85,7 @@ lldb_private::TypeSystemClang &m_ast; DIEToDeclMap m_die_to_decl; - DIEToDeclContextMap m_die_to_decl_ctx; + DIERefToDeclContextMap m_dieref_to_decl_ctx; DeclContextToFileDIERefMap m_decl_ctx_to_filedieref; DIEToModuleMap m_die_to_module; std::unique_ptr m_clang_ast_importer_up; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -58,7 +58,7 @@ using namespace lldb; using namespace lldb_private; DWARFASTParserClang::DWARFASTParserClang(TypeSystemClang &ast) - : m_ast(ast), m_die_to_decl_ctx(), m_decl_ctx_to_filedieref() {} + : m_ast(ast), m_dieref_to_decl_ctx(), m_decl_ctx_to_filedieref() {} DWARFASTParserClang::~DWARFASTParserClang() = default; @@ -1040,7 +1040,7 @@ if (attrs.specification.IsValid()) { // We have a specification which we are going to base our // function prototype off of, so we need this type to be - // completed so that the m_die_to_decl_ctx for the method in + // completed so that the m_dieref_to_decl_ctx for the method in // the specification has a valid clang decl context. class_type->GetForwardCompilerType(); // If we have a specification, then the function type should @@ -1061,7 +1061,7 @@ } else if (attrs.abstract_origin.IsValid()) { // We have a specification which we are going to base our // function prototype off of, so we need this type to be - // completed so that the m_die_to_decl_ctx for the method in + // completed so that the m_dieref_to_decl_ctx for the method in // the abstract origin has a valid clang decl context. class_type->GetForwardCompilerType(); @@ -3351,8 +3351,8 @@ clang::BlockDecl *DWARFASTParserClang::ResolveBlockDIE(const DWARFDIE &die) { if (die && die.Tag() == DW_TAG_lexical_block) { - clang::BlockDecl *decl = - llvm::cast_or_null(m_die_to_decl_ctx[die.GetDIE()]); + clang::BlockDecl *decl = llvm::cast_or_null( + m_dieref_to_decl_ctx[*die.GetDIERef()]); if (!decl) { DWARFDIE decl_context_die; @@ -3375,8 +3375,8 @@ if (die && die.Tag() == DW_TAG_namespace) { // See if we already parsed this namespace DIE and associated it with a // uniqued namespace declaration - clang::NamespaceDecl *namespace_decl = - static_cast(m_die_to_decl_ctx[die.GetDIE()]); + clang::NamespaceDecl *namespace_decl = static_cast( + m_dieref_to_decl_ctx[*die.GetDIERef()]); if (namespace_decl) return namespace_decl; else { @@ -3443,8 +3443,9 @@ clang::DeclContext * DWARFASTParserClang::GetCachedClangDeclContextForDIE(const DWARFDIE &die) { if (die) { - DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die.GetDIE()); - if (pos != m_die_to_decl_ctx.end()) + DIERefToDeclContextMap::iterator pos = + m_dieref_to_decl_ctx.find(*die.GetDIERef()); + if (pos != m_dieref_to_decl_ctx.end()) return pos->second; } return nullptr; @@ -3452,9 +3453,9 @@ void DWARFASTParserClang::LinkDeclContextToDIE(clang::DeclContext *decl_ctx, const DWARFDIE &die) { - m_die_to_decl_ctx[die.GetDIE()] = decl_ctx; - SymbolFileDWARF *sym_file = &die.GetCU()->GetSymbolFileDWARF(); DIERef ref = *die.GetDIERef(); + m_dieref_to_decl_ctx[ref] = decl_ctx; + SymbolFileDWARF *sym_file = &die.GetCU()->GetSymbolFileDWARF(); // There can be many DIEs for a single decl context // m_decl_ctx_to_filedieref[decl_ctx].insert(...); m_decl_ctx_to_filedieref.insert( @@ -3588,7 +3589,7 @@ dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); clang::DeclContext *src_decl_ctx = - src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; + src_dwarf_ast_parser->m_dieref_to_decl_ctx[*src_die.GetDIERef()]; if (src_decl_ctx) { LLDB_LOGF(log, "uniquing decl context %p from 0x%8.8x for 0x%8.8x", static_cast(src_decl_ctx), src_die.GetOffset(), @@ -3632,7 +3633,7 @@ if (src_die && (src_die.Tag() == dst_die.Tag())) { clang::DeclContext *src_decl_ctx = - src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; + src_dwarf_ast_parser->m_dieref_to_decl_ctx[*src_die.GetDIERef()]; if (src_decl_ctx) { LLDB_LOGF(log, "uniquing decl context %p from 0x%8.8x for 0x%8.8x", static_cast(src_decl_ctx), src_die.GetOffset(), @@ -3687,7 +3688,7 @@ if (dst_die) { // Both classes have the artificial types, link them clang::DeclContext *src_decl_ctx = - src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; + src_dwarf_ast_parser->m_dieref_to_decl_ctx[*src_die.GetDIERef()]; if (src_decl_ctx) { LLDB_LOGF(log, "uniquing decl context %p from 0x%8.8x for 0x%8.8x", static_cast(src_decl_ctx), src_die.GetOffset(),