More abstraction to get almost all clang specific DWARF parsing code into ClangASTContext.
llvm-svn: 245376
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 1404e32..3e5a885 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -48,7 +48,6 @@
#include "lldb/Interpreter/OptionValueProperties.h"
#include "lldb/Symbol/Block.h"
-#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/ObjectFile.h"
@@ -504,7 +503,6 @@
UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
m_debug_map_module_wp (),
m_debug_map_symfile (NULL),
- m_clang_tu_decl (NULL),
m_flags(),
m_data_debug_abbrev (),
m_data_debug_aranges (),
@@ -533,7 +531,6 @@
m_type_index(),
m_namespace_index(),
m_indexed (false),
- m_is_external_ast_source (false),
m_using_apple_tables (false),
m_fetched_external_modules (false),
m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
@@ -544,12 +541,6 @@
SymbolFileDWARF::~SymbolFileDWARF()
{
- if (m_is_external_ast_source)
- {
- ModuleSP module_sp (m_obj_file->GetModule());
- if (module_sp)
- module_sp->GetClangASTContext().RemoveExternalSource ();
- }
}
static const ConstString &
@@ -572,20 +563,8 @@
{
if (GetDebugMapSymfile ())
return m_debug_map_symfile->GetClangASTContext ();
-
- ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
- if (!m_is_external_ast_source)
- {
- m_is_external_ast_source = true;
- llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap (
- new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
- SymbolFileDWARF::CompleteObjCInterfaceDecl,
- SymbolFileDWARF::FindExternalVisibleDeclsByName,
- SymbolFileDWARF::LayoutRecordType,
- this));
- ast.SetExternalSource (ast_source_ap);
- }
- return ast;
+ else
+ return m_obj_file->GetModule()->GetClangASTContext();
}
TypeSystem *
@@ -595,22 +574,12 @@
if (debug_map_symfile)
return debug_map_symfile->GetTypeSystemForLanguage (language);
else
- {
- TypeSystem *type_system = m_obj_file->GetModule()->GetTypeSystemForLanguage (language);
-
- if (type_system && type_system->AsClangASTContext())
- {
- // Get the ClangAST so that we register the ClangExternalASTSource callbacks if needed...
- GetClangASTContext();
- }
- return type_system;
- }
+ return m_obj_file->GetModule()->GetTypeSystemForLanguage (language);
}
void
SymbolFileDWARF::InitializeObject()
{
- // Install our external AST source callbacks so we can complete Clang types.
ModuleSP module_sp (m_obj_file->GetModule());
if (module_sp)
{
@@ -661,6 +630,12 @@
else
m_apple_objc_ap.reset();
}
+
+ // Set the symbol file to this file if we don't have a debug map symbol
+ // file as our main symbol file. This allows the clang ASTContext to complete
+ // types using this symbol file when it needs to complete classes and structures.
+ if (GetDebugMapSymfile () == nullptr)
+ GetClangASTContext().SetSymbolFile(this);
}
bool
@@ -1588,7 +1563,7 @@
bool
-SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (CompilerType &clang_type)
+SymbolFileDWARF::CompleteType (CompilerType &clang_type)
{
// We have a struct/union/class/enum that needs to be fully resolved.
CompilerType clang_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(clang_type);
@@ -1604,19 +1579,7 @@
// are done.
m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType());
- ClangASTContext* ast = clang_type.GetTypeSystem()->AsClangASTContext();
- if (ast == NULL)
- {
- // Not a clang type
- return true;
- }
-
- // Disable external storage for this type so we don't get anymore
- // clang::ExternalASTSource queries for this type.
- ast->SetHasExternalStorage (clang_type.GetOpaqueQualType(), false);
-
DWARFDebugInfo* debug_info = DebugInfo();
-
DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Type *type = m_die_to_type.lookup (die);
@@ -1634,7 +1597,7 @@
TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType());
if (type_system)
- return type_system->ResolveClangOpaqueTypeDefinition(this, dwarf_cu, die, type, clang_type);
+ return type_system->CompleteTypeFromDWARF (this, dwarf_cu, die, type, clang_type);
return false;
}
@@ -4577,24 +4540,6 @@
}
void
-SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
-{
- SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
- CompilerType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
- if (clang_type)
- symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
-}
-
-void
-SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
-{
- SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
- CompilerType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
- if (clang_type)
- symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
-}
-
-void
SymbolFileDWARF::DumpIndexes ()
{
StreamFile s(stdout, false);
@@ -4612,111 +4557,6 @@
s.Printf("\nNamespaces:\n"); m_namespace_index.Dump (&s);
}
-void
-SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
- const char *name,
- llvm::SmallVectorImpl <clang::NamedDecl *> *results)
-{
- DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
-
- if (iter == m_decl_ctx_to_die.end())
- return;
-
- for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
- {
- const DWARFDebugInfoEntry *context_die = *pos;
-
- if (!results)
- return;
-
- DWARFDebugInfo* info = DebugInfo();
-
- DIEArray die_offsets;
-
- DWARFCompileUnit* dwarf_cu = NULL;
- const DWARFDebugInfoEntry* die = NULL;
-
- if (m_using_apple_tables)
- {
- if (m_apple_types_ap.get())
- m_apple_types_ap->FindByName (name, die_offsets);
- }
- else
- {
- if (!m_indexed)
- Index ();
-
- m_type_index.Find (ConstString(name), die_offsets);
- }
-
- const size_t num_matches = die_offsets.size();
-
- if (num_matches)
- {
- for (size_t i = 0; i < num_matches; ++i)
- {
- const dw_offset_t die_offset = die_offsets[i];
- die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
-
- if (die->GetParent() != context_die)
- continue;
-
- Type *matching_type = ResolveType (dwarf_cu, die);
-
- clang::QualType qual_type = ClangASTContext::GetQualType(matching_type->GetClangForwardType());
-
- if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
- {
- clang::TagDecl *tag_decl = tag_type->getDecl();
- results->push_back(tag_decl);
- }
- else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
- {
- clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
- results->push_back(typedef_decl);
- }
- }
- }
- }
-}
-
-void
-SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
- const clang::DeclContext *decl_context,
- clang::DeclarationName decl_name,
- llvm::SmallVectorImpl <clang::NamedDecl *> *results)
-{
-
- switch (decl_context->getDeclKind())
- {
- case clang::Decl::Namespace:
- case clang::Decl::TranslationUnit:
- {
- SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
- symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
- }
- break;
- default:
- break;
- }
-}
-
-bool
-SymbolFileDWARF::LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size,
- uint64_t &alignment,
- llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
- llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
- llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
-{
- if (baton)
- {
- SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
- TypeSystem *type_system = symbol_file_dwarf->GetTypeSystemForLanguage(eLanguageTypeC_plus_plus);
- if (type_system)
- return type_system->LayoutRecordType (symbol_file_dwarf, record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
- }
- return false;
-}
SymbolFileDWARFDebugMap *
SymbolFileDWARF::GetDebugMapSymfile ()
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
index 8534668..55c7ce6 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -115,7 +115,7 @@
size_t ParseVariablesForContext (const lldb_private::SymbolContext& sc) override;
lldb_private::Type* ResolveTypeUID(lldb::user_id_t type_uid) override;
- bool ResolveClangOpaqueTypeDefinition (lldb_private::CompilerType& clang_type) override;
+ bool CompleteType (lldb_private::CompilerType& clang_type) override;
lldb_private::Type* ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed = true);
lldb_private::Type* GetCachedTypeForDIE (const DWARFDebugInfoEntry* type_die) const;
@@ -149,26 +149,6 @@
//------------------------------------------------------------------
- // ClangASTContext callbacks for external source lookups.
- //------------------------------------------------------------------
- static void
- CompleteTagDecl (void *baton, clang::TagDecl *);
-
- static void
- CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *);
-
- static void
- FindExternalVisibleDeclsByName (void *baton,
- const clang::DeclContext *DC,
- clang::DeclarationName Name,
- llvm::SmallVectorImpl <clang::NamedDecl *> *results);
-
- static bool LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size, uint64_t &alignment,
- llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
- llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
- llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets);
-
- //------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
lldb_private::ConstString
@@ -208,24 +188,9 @@
static bool
SupportedVersion(uint16_t version);
- clang::DeclContext *
- GetCachedClangDeclContextForDIE (const DWARFDebugInfoEntry *die)
- {
- DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die);
- if (pos != m_die_to_decl_ctx.end())
- return pos->second;
- else
- return NULL;
- }
-
const DWARFDebugInfoEntry *
GetDeclContextDIEContainingDIE (const DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die);
- void
- SearchDeclContext (const clang::DeclContext *decl_context,
- const char *name,
- llvm::SmallVectorImpl <clang::NamedDecl *> *results);
-
lldb_private::Flags&
GetFlags ()
{
@@ -400,14 +365,6 @@
UniqueDWARFASTTypeMap &
GetUniqueDWARFASTTypeMap ();
-
- void LinkDeclContextToDIE (clang::DeclContext *decl_ctx,
- const DWARFDebugInfoEntry *die)
- {
- m_die_to_decl_ctx[die] = decl_ctx;
- // There can be many DIEs for a single decl context
- m_decl_ctx_to_die[decl_ctx].insert(die);
- }
bool
UserIDMatches (lldb::user_id_t uid) const
@@ -457,7 +414,6 @@
lldb::ModuleWP m_debug_map_module_wp;
SymbolFileDWARFDebugMap * m_debug_map_symfile;
- clang::TranslationUnitDecl * m_clang_tu_decl;
lldb_private::Flags m_flags;
lldb_private::DWARFDataExtractor m_dwarf_data;
lldb_private::DWARFDataExtractor m_data_debug_abbrev;
@@ -493,22 +449,16 @@
NameToDIE m_type_index; // All type DIE offsets
NameToDIE m_namespace_index; // All type DIE offsets
bool m_indexed:1,
- m_is_external_ast_source:1,
m_using_apple_tables:1,
m_fetched_external_modules:1;
lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
std::unique_ptr<DWARFDebugRanges> m_ranges;
UniqueDWARFASTTypeMap m_unique_ast_type_map;
- typedef llvm::SmallPtrSet<const DWARFDebugInfoEntry *, 4> DIEPointerSet;
- typedef llvm::DenseMap<const DWARFDebugInfoEntry *, clang::DeclContext *> DIEToDeclContextMap;
- typedef llvm::DenseMap<const clang::DeclContext *, DIEPointerSet> DeclContextToDIEMap;
typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *> DIEToTypePtr;
typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP> DIEToVariableSP;
typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::clang_type_t> DIEToClangType;
typedef llvm::DenseMap<lldb::clang_type_t, const DWARFDebugInfoEntry *> ClangTypeToDIE;
- DIEToDeclContextMap m_die_to_decl_ctx;
- DeclContextToDIEMap m_decl_ctx_to_die;
DIEToTypePtr m_die_to_type;
DIEToVariableSP m_die_to_variable_sp;
DIEToClangType m_forward_decl_die_to_clang_type;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
index 7c7706f..e2ab962 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -24,7 +24,6 @@
#endif
#include "lldb/Core/Timer.h"
-#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/ObjectFile.h"
@@ -298,15 +297,9 @@
void
SymbolFileDWARFDebugMap::InitializeObject()
{
- // Install our external AST source callbacks so we can complete Clang types.
- llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap (
- new ClangExternalASTSourceCallbacks (SymbolFileDWARFDebugMap::CompleteTagDecl,
- SymbolFileDWARFDebugMap::CompleteObjCInterfaceDecl,
- NULL,
- SymbolFileDWARFDebugMap::LayoutRecordType,
- this));
-
- GetClangASTContext().SetExternalSource (ast_source_ap);
+ // Set the symbol file to this file. This allows the clang ASTContext to complete
+ // types using this symbol file when it needs to complete classes and structures.
+ GetClangASTContext().SetSymbolFile(this);
}
void
@@ -788,10 +781,22 @@
}
bool
-SymbolFileDWARFDebugMap::ResolveClangOpaqueTypeDefinition (CompilerType& clang_type)
+SymbolFileDWARFDebugMap::CompleteType (CompilerType& clang_type)
{
- // We have a struct/union/class/enum that needs to be fully resolved.
- return false;
+ bool success = false;
+ if (clang_type)
+ {
+ ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
+ if (oso_dwarf->HasForwardDeclForClangType (clang_type))
+ {
+ oso_dwarf->CompleteType (clang_type);
+ success = true;
+ return true;
+ }
+ return false;
+ });
+ }
+ return success;
}
uint32_t
@@ -1428,60 +1433,6 @@
}
}
-
-void
-SymbolFileDWARFDebugMap::CompleteTagDecl (void *baton, clang::TagDecl *decl)
-{
- SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
- CompilerType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
- if (clang_type)
- {
- symbol_file_dwarf->ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
- if (oso_dwarf->HasForwardDeclForClangType (clang_type))
- {
- oso_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
- return true;
- }
- return false;
- });
- }
-}
-
-void
-SymbolFileDWARFDebugMap::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
-{
- SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
- CompilerType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
- if (clang_type)
- {
- symbol_file_dwarf->ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
- if (oso_dwarf->HasForwardDeclForClangType (clang_type))
- {
- oso_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
- return true;
- }
- return false;
- });
- }
-}
-
-bool
-SymbolFileDWARFDebugMap::LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size,
- uint64_t &alignment,
- llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
- llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
- llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
-{
- SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
- bool laid_out = false;
- symbol_file_dwarf->ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
- return (laid_out = SymbolFileDWARF::LayoutRecordType (oso_dwarf, record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets));
- });
- return laid_out;
-}
-
-
-
clang::DeclContext*
SymbolFileDWARFDebugMap::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
{
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
index fa7607a..2fc5d04 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
@@ -57,7 +57,6 @@
~SymbolFileDWARFDebugMap () override;
uint32_t CalculateAbilities () override;
-
void InitializeObject() override;
//------------------------------------------------------------------
@@ -78,7 +77,7 @@
lldb_private::Type* ResolveTypeUID (lldb::user_id_t type_uid) override;
clang::DeclContext* GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) override;
clang::DeclContext* GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) override;
- bool ResolveClangOpaqueTypeDefinition (lldb_private::CompilerType& clang_type) override;
+ bool CompleteType (lldb_private::CompilerType& clang_type) override;
uint32_t ResolveSymbolContext (const lldb_private::Address& so_addr, uint32_t resolve_scope, lldb_private::SymbolContext& sc) override;
uint32_t ResolveSymbolContext (const lldb_private::FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, lldb_private::SymbolContextList& sc_list) override;
uint32_t FindGlobalVariables (const lldb_private::ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, lldb_private::VariableList& variables) override;
@@ -94,21 +93,6 @@
uint32_t type_mask,
lldb_private::TypeList &type_list) override;
-
- //------------------------------------------------------------------
- // ClangASTContext callbacks for external source lookups.
- //------------------------------------------------------------------
- static void
- CompleteTagDecl (void *baton, clang::TagDecl *);
-
- static void
- CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *);
-
- static bool LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size, uint64_t &alignment,
- llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
- llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
- llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets);
-
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
diff --git a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
index 4f0764a..5308db39 100644
--- a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
+++ b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
@@ -300,7 +300,7 @@
}
bool
-SymbolFileSymtab::ResolveClangOpaqueTypeDefinition (lldb_private::CompilerType& clang_opaque_type)
+SymbolFileSymtab::CompleteType (lldb_private::CompilerType& clang_opaque_type)
{
return false;
}
diff --git a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h
index 8a12bf6..8ff2181 100644
--- a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h
+++ b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h
@@ -82,7 +82,7 @@
ResolveTypeUID(lldb::user_id_t type_uid);
virtual bool
- ResolveClangOpaqueTypeDefinition (lldb_private::CompilerType& clang_type);
+ CompleteType (lldb_private::CompilerType& clang_type);
virtual uint32_t
ResolveSymbolContext (const lldb_private::Address& so_addr, uint32_t resolve_scope, lldb_private::SymbolContext& sc);
diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp
index 5e85a59..418c266 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -71,6 +71,7 @@
#include "lldb/Core/UniqueCStringMap.h"
#include "lldb/Expression/ASTDumper.h"
#include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
#include "lldb/Symbol/VerifyDecl.h"
#include "lldb/Target/ExecutionContext.h"
@@ -293,22 +294,25 @@
ClangASTContext::ClangASTContext (const char *target_triple) :
- m_target_triple(),
- m_ast_ap(),
- m_language_options_ap(),
- m_source_manager_ap(),
- m_diagnostics_engine_ap(),
- m_target_options_rp(),
- m_target_info_ap(),
- m_identifier_table_ap(),
- m_selector_table_ap(),
- m_builtins_ap(),
+ m_target_triple (),
+ m_ast_ap (),
+ m_language_options_ap (),
+ m_source_manager_ap (),
+ m_diagnostics_engine_ap (),
+ m_target_options_rp (),
+ m_target_info_ap (),
+ m_identifier_table_ap (),
+ m_selector_table_ap (),
+ m_builtins_ap (),
m_callback_tag_decl (nullptr),
m_callback_objc_decl (nullptr),
m_callback_baton (nullptr),
m_pointer_byte_size (0),
- m_ast_owned(false)
-
+ m_ast_owned (false),
+ m_record_decl_to_layout_map (),
+ m_die_to_decl_ctx (),
+ m_decl_ctx_to_die (),
+ m_clang_tu_decl (nullptr)
{
if (target_triple && target_triple[0])
SetTargetTriple (target_triple);
@@ -445,6 +449,13 @@
}
GetASTMap().Insert(m_ast_ap.get(), this);
+
+ llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap (new ClangExternalASTSourceCallbacks (ClangASTContext::CompleteTagDecl,
+ ClangASTContext::CompleteObjCInterfaceDecl,
+ nullptr,
+ ClangASTContext::LayoutRecordType,
+ this));
+ SetExternalSource (ast_source_ap);
}
return m_ast_ap.get();
}
@@ -9076,11 +9087,11 @@
}
bool
-ClangASTContext::ResolveClangOpaqueTypeDefinition (SymbolFileDWARF *dwarf,
- DWARFCompileUnit *dwarf_cu,
- const DWARFDebugInfoEntry* die,
- lldb_private::Type *type,
- CompilerType &clang_type)
+ClangASTContext::CompleteTypeFromDWARF (SymbolFileDWARF *dwarf,
+ DWARFCompileUnit *dwarf_cu,
+ const DWARFDebugInfoEntry* die,
+ lldb_private::Type *type,
+ CompilerType &clang_type)
{
// Disable external storage for this type so we don't get anymore
// clang::ExternalASTSource queries for this type.
@@ -9298,7 +9309,7 @@
if (module_sp)
{
module_sp->LogMessage (log,
- "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])",
+ "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) caching layout info for record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])",
static_cast<void*>(clang_type.GetOpaqueQualType()),
static_cast<void*>(record_decl),
layout_info.bit_size,
@@ -9314,7 +9325,7 @@
for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
{
module_sp->LogMessage(log,
- "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
+ "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
static_cast<void *>(clang_type.GetOpaqueQualType()),
idx,
static_cast<uint32_t>(pos->second),
@@ -9328,7 +9339,7 @@
for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
{
module_sp->LogMessage(log,
- "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
+ "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
clang_type.GetOpaqueQualType(), idx, (uint32_t)base_pos->second.getQuantity(),
base_pos->first->getNameAsString().c_str());
}
@@ -9339,7 +9350,7 @@
for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
{
module_sp->LogMessage(log,
- "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
+ "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
static_cast<uint32_t>(vbase_pos->second.getQuantity()),
vbase_pos->first->getNameAsString().c_str());
@@ -9375,9 +9386,34 @@
return false;
}
+void
+ClangASTContext::CompleteTagDecl (void *baton, clang::TagDecl *decl)
+{
+ ClangASTContext *ast = (ClangASTContext *)baton;
+ SymbolFile *sym_file = ast->GetSymbolFile();
+ if (sym_file)
+ {
+ CompilerType clang_type = GetTypeForDecl (decl);
+ if (clang_type)
+ sym_file->CompleteType (clang_type);
+ }
+}
+
+void
+ClangASTContext::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
+{
+ ClangASTContext *ast = (ClangASTContext *)baton;
+ SymbolFile *sym_file = ast->GetSymbolFile();
+ if (sym_file)
+ {
+ CompilerType clang_type = GetTypeForDecl (decl);
+ if (clang_type)
+ sym_file->CompleteType (clang_type);
+ }
+}
bool
-ClangASTContext::LayoutRecordType(SymbolFileDWARF *dwarf,
+ClangASTContext::LayoutRecordType(void *baton,
const clang::RecordDecl *record_decl,
uint64_t &bit_size,
uint64_t &alignment,
@@ -9385,18 +9421,19 @@
llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
{
- RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
+ ClangASTContext *ast = (ClangASTContext *)baton;
+ RecordDeclToLayoutMap::iterator pos = ast->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())
+ if (pos != ast->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);
+ ast->m_record_decl_to_layout_map.erase(pos);
success = true;
}
else
@@ -10642,7 +10679,7 @@
DWARFCompileUnit *cu,
const DWARFDebugInfoEntry *die)
{
- clang::DeclContext *clang_decl_ctx = dwarf->GetCachedClangDeclContextForDIE (die);
+ clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
if (clang_decl_ctx)
return clang_decl_ctx;
// If this DIE has a specification, or an abstract origin, then trace to those.
@@ -10662,7 +10699,7 @@
bool assert_not_being_parsed = true;
dwarf->ResolveTypeUID (cu, die, assert_not_being_parsed);
- clang_decl_ctx = dwarf->GetCachedClangDeclContextForDIE (die);
+ clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
return clang_decl_ctx;
}
@@ -10709,7 +10746,7 @@
{
// See if we already parsed this namespace DIE and associated it with a
// uniqued namespace declaration
- clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(dwarf->m_die_to_decl_ctx[die]);
+ clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
if (namespace_decl)
return namespace_decl;
else
@@ -10742,7 +10779,7 @@
}
if (namespace_decl)
- dwarf->LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
+ LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
return namespace_decl;
}
}
@@ -10755,8 +10792,8 @@
const DWARFDebugInfoEntry *die,
const DWARFDebugInfoEntry **decl_ctx_die_copy)
{
- if (dwarf->m_clang_tu_decl == NULL)
- dwarf->m_clang_tu_decl = getASTContext()->getTranslationUnitDecl();
+ if (m_clang_tu_decl == NULL)
+ m_clang_tu_decl = getASTContext()->getTranslationUnitDecl();
const DWARFDebugInfoEntry *decl_ctx_die = dwarf->GetDeclContextDIEContainingDIE (cu, die);
@@ -10766,14 +10803,14 @@
if (decl_ctx_die)
{
- SymbolFileDWARF::DIEToDeclContextMap::iterator pos = dwarf->m_die_to_decl_ctx.find (decl_ctx_die);
- if (pos != dwarf->m_die_to_decl_ctx.end())
+ DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
+ if (pos != m_die_to_decl_ctx.end())
return pos->second;
switch (decl_ctx_die->Tag())
{
case DW_TAG_compile_unit:
- return dwarf->m_clang_tu_decl;
+ return m_clang_tu_decl;
case DW_TAG_namespace:
return ResolveNamespaceDIE (dwarf, cu, decl_ctx_die);
@@ -10788,7 +10825,7 @@
clang::DeclContext *decl_ctx = GetDeclContextForType(type->GetClangForwardType());
if (decl_ctx)
{
- dwarf->LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
+ LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
if (decl_ctx)
return decl_ctx;
}
@@ -10800,7 +10837,7 @@
break;
}
}
- return dwarf->m_clang_tu_decl;
+ return m_clang_tu_decl;
}
@@ -11377,7 +11414,7 @@
// Store a forward declaration to this class type in case any
// parameters in any class methods need it for the clang
// types for function prototypes.
- dwarf->LinkDeclContextToDIE(GetDeclContextForType(clang_type), die);
+ LinkDeclContextToDIE(GetDeclContextForType(clang_type), die);
type_sp.reset (new Type (dwarf->MakeUserID(die->GetOffset()),
dwarf,
type_name_const_str,
@@ -11470,7 +11507,7 @@
// Leave this as a forward declaration until we need
// to know the details of the type. lldb_private::Type
// will automatically call the SymbolFile virtual function
- // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
+ // "SymbolFileDWARF::CompleteType(Type *)"
// When the definition needs to be defined.
dwarf->m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType();
dwarf->m_forward_decl_clang_type_to_die[ClangASTContext::RemoveFastQualifiers(clang_type).GetOpaqueQualType()] = die;
@@ -11555,7 +11592,7 @@
enumerator_clang_type = GetEnumerationIntegerType (clang_type.GetOpaqueQualType());
}
- dwarf->LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
+ LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
type_sp.reset( new Type (dwarf->MakeUserID(die->GetOffset()),
dwarf,
@@ -11787,7 +11824,7 @@
type_handled = objc_method_decl != NULL;
if (type_handled)
{
- dwarf->LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
+ LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
SetMetadataAsUserID (objc_method_decl, dwarf->MakeUserID(die->GetOffset()));
}
else
@@ -11868,7 +11905,7 @@
clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (dwarf, sc, dwarf_cu, spec_die);
if (spec_clang_decl_ctx)
{
- dwarf->LinkDeclContextToDIE(spec_clang_decl_ctx, die);
+ LinkDeclContextToDIE(spec_clang_decl_ctx, die);
}
else
{
@@ -11891,7 +11928,7 @@
clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (dwarf, sc, dwarf_cu, abs_die);
if (abs_clang_decl_ctx)
{
- dwarf->LinkDeclContextToDIE (abs_clang_decl_ctx, die);
+ LinkDeclContextToDIE (abs_clang_decl_ctx, die);
}
else
{
@@ -11947,7 +11984,7 @@
if (type_handled)
{
- dwarf->LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
+ LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
Host::SetCrashDescription (NULL);
@@ -12028,7 +12065,7 @@
// }
// Add the decl to our DIE to decl context map
assert (function_decl);
- dwarf->LinkDeclContextToDIE(function_decl, die);
+ LinkDeclContextToDIE(function_decl, die);
if (!function_param_decls.empty())
SetFunctionParameters (function_decl,
&function_param_decls.front(),
@@ -12401,14 +12438,14 @@
src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
- clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
+ clang::DeclContext *src_decl_ctx = src_symfile->GetClangASTContext().m_die_to_decl_ctx[src_die];
if (src_decl_ctx)
{
if (log)
log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
static_cast<void*>(src_decl_ctx),
src_die->GetOffset(), dst_die->GetOffset());
- dst_symfile->LinkDeclContextToDIE (src_decl_ctx, dst_die);
+ dst_symfile->GetClangASTContext().LinkDeclContextToDIE (src_decl_ctx, dst_die);
}
else
{
@@ -12452,7 +12489,7 @@
if (src_die && (src_die->Tag() == dst_die->Tag()))
{
- clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
+ clang::DeclContext *src_decl_ctx = src_symfile->GetClangASTContext().m_die_to_decl_ctx[src_die];
if (src_decl_ctx)
{
if (log)
@@ -12460,7 +12497,7 @@
static_cast<void*>(src_decl_ctx),
src_die->GetOffset(),
dst_die->GetOffset());
- dst_symfile->LinkDeclContextToDIE (src_decl_ctx, dst_die);
+ dst_symfile->GetClangASTContext().LinkDeclContextToDIE (src_decl_ctx, dst_die);
}
else
{
@@ -12514,14 +12551,14 @@
if (dst_die)
{
// Both classes have the artificial types, link them
- clang::DeclContext *src_decl_ctx = dst_symfile->m_die_to_decl_ctx[src_die];
+ clang::DeclContext *src_decl_ctx = dst_symfile->GetClangASTContext().m_die_to_decl_ctx[src_die];
if (src_decl_ctx)
{
if (log)
log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
static_cast<void*>(src_decl_ctx),
src_die->GetOffset(), dst_die->GetOffset());
- dst_symfile->LinkDeclContextToDIE (src_decl_ctx, dst_die);
+ dst_symfile->GetClangASTContext().LinkDeclContextToDIE (src_decl_ctx, dst_die);
}
else
{
diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp
index 80f6f72..3cd04bf 100644
--- a/lldb/source/Symbol/Type.cpp
+++ b/lldb/source/Symbol/Type.cpp
@@ -611,7 +611,7 @@
if (!m_clang_type.IsDefined ())
{
// We have a forward declaration, we need to resolve it to a complete definition.
- m_symbol_file->ResolveClangOpaqueTypeDefinition (m_clang_type);
+ m_symbol_file->CompleteType (m_clang_type);
}
}
}
diff --git a/lldb/source/Symbol/TypeSystem.cpp b/lldb/source/Symbol/TypeSystem.cpp
index 1e72c54..286a760 100644
--- a/lldb/source/Symbol/TypeSystem.cpp
+++ b/lldb/source/Symbol/TypeSystem.cpp
@@ -10,7 +10,8 @@
using namespace lldb_private;
-TypeSystem::TypeSystem()
+TypeSystem::TypeSystem() :
+ m_sym_file (nullptr)
{
}