As part of the work to make Objective-C type information
from symbols more accessible, I have added a second
map to the ClangASTImporter: the ObjCInterfaceMetaMap.
This map keeps track of all type definitions found for
a particular Objective-C interface, allowing the
ClangASTSource to refer to all possible sources when
looking for method definitions.
There is a bug in lookup that I still need to figure out,
but after that we should be able to report full method
information for Objective-C classes shown in symbols.
Also fixed some errors I ran into when enabling the maps
for the persistent type store. The persistent type store
previously did not use the ClangASTImporter to import
types, instead using ASTImporters that got allocated each
time a type needed copying. To support the requirements
of the persistent type store -- namely, that types must be
copied, completed, and then completely severed from their
origin in the parser's AST context (which will go away) --
I added a new function called DeportType which severs all
these connections.
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@145914 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/ASTResultSynthesizer.cpp b/source/Expression/ASTResultSynthesizer.cpp
index f28f8f1..ff3b2f4 100644
--- a/source/Expression/ASTResultSynthesizer.cpp
+++ b/source/Expression/ASTResultSynthesizer.cpp
@@ -22,6 +22,8 @@
#include "lldb/Expression/ClangPersistentVariables.h"
#include "lldb/Expression/ASTResultSynthesizer.h"
#include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/ClangASTImporter.h"
+#include "lldb/Target/Target.h"
using namespace llvm;
using namespace clang;
@@ -29,13 +31,11 @@
ASTResultSynthesizer::ASTResultSynthesizer(ASTConsumer *passthrough,
TypeFromUser desired_type,
- ASTContext &scratch_ast_context,
- ClangPersistentVariables &persistent_vars) :
+ Target &target) :
m_ast_context (NULL),
m_passthrough (passthrough),
m_passthrough_sema (NULL),
- m_scratch_ast_context (scratch_ast_context),
- m_persistent_vars (persistent_vars),
+ m_target (target),
m_sema (NULL),
m_desired_type (desired_type)
{
@@ -442,14 +442,12 @@
if (log)
log->Printf ("Recording persistent type %s\n", name_cs.GetCString());
- Decl *D_scratch = ClangASTContext::CopyDecl(&m_scratch_ast_context,
- m_ast_context,
- D);
+ Decl *D_scratch = m_target.GetClangASTImporter()->DeportDecl(m_target.GetScratchClangASTContext()->getASTContext(),
+ m_ast_context,
+ D);
- TypeDecl *TD_scratch = dyn_cast<TypeDecl>(D_scratch);
-
- if (TD_scratch)
- m_persistent_vars.RegisterPersistentType(name_cs, TD_scratch);
+ if (TypeDecl *TypeDecl_scratch = dyn_cast<TypeDecl>(D_scratch))
+ m_target.GetPersistentVariables().RegisterPersistentType(name_cs, TypeDecl_scratch);
}
void
diff --git a/source/Expression/ClangASTSource.cpp b/source/Expression/ClangASTSource.cpp
index 0eca0a4..19baef0 100644
--- a/source/Expression/ClangASTSource.cpp
+++ b/source/Expression/ClangASTSource.cpp
@@ -463,29 +463,11 @@
SymbolContext null_sc;
if (module_sp && namespace_decl)
- {
module_sp->FindTypes(null_sc, name, &namespace_decl, true, 1, types);
- }
else if(name != id_name && name != Class_name)
- {
- m_target->GetImages().FindTypes (null_sc, name, true, 1, types);
-
- if (!types.GetSize())
- {
- lldb::ProcessSP process = m_target->GetProcessSP();
-
- if (process && process->GetObjCLanguageRuntime())
- {
- SymbolVendor *objc_symbol_vendor = process->GetObjCLanguageRuntime()->GetSymbolVendor();
-
- objc_symbol_vendor->FindTypes(null_sc, name, NULL, true, 1, types);
- }
- }
- }
+ m_target->GetImages().FindTypes(null_sc, name, true, 1, types);
else
- {
break;
- }
if (types.GetSize())
{
@@ -501,13 +483,15 @@
(name_string ? name_string : "<anonymous>"));
}
+
void *copied_type = GuardedCopyType(m_ast_context, type_sp->GetClangAST(), type_sp->GetClangFullType());
-
+
if (!copied_type)
{
if (log)
- log->Printf("ClangExpressionDeclMap::BuildIntegerVariable - Couldn't export the type for a constant integer result");
-
+ log->Printf(" CAS::FEVD[%u] - Couldn't export the type for a constant integer result",
+ current_id);
+
break;
}
@@ -534,6 +518,7 @@
return;
StreamString ss;
+
if (decl_name.isObjCZeroArgSelector())
{
ss.Printf("%s", decl_name.getAsString().c_str());
@@ -565,6 +550,90 @@
interface_decl->getNameAsString().c_str(),
selector_name.AsCString());
+ ClangASTImporter::ObjCInterfaceMapSP interface_map = m_ast_importer->GetObjCInterfaceMap(interface_decl);
+
+ if (interface_map)
+ {
+ for (ClangASTImporter::ObjCInterfaceMap::iterator i = interface_map->begin(), e = interface_map->end();
+ i != e;
+ ++i)
+ {
+ lldb::clang_type_t backing_type = i->GetOpaqueQualType();
+
+ if (!backing_type)
+ continue;
+
+ QualType backing_qual_type = QualType::getFromOpaquePtr(backing_type);
+
+ const ObjCInterfaceType *backing_interface_type = dyn_cast<ObjCInterfaceType>(backing_qual_type.getTypePtr());
+
+ if (!backing_interface_type)
+ continue;
+
+ const ObjCInterfaceDecl *backing_interface_decl = backing_interface_type->getDecl();
+
+ if (!backing_interface_decl)
+ continue;
+
+ if (backing_interface_decl->decls_begin() == backing_interface_decl->decls_end())
+ continue; // don't waste time creating a DeclarationName here
+
+ clang::ASTContext &backing_ast_context = backing_interface_decl->getASTContext();
+
+ llvm::SmallVector<clang::IdentifierInfo *, 3> selector_components;
+
+ if (decl_name.isObjCZeroArgSelector())
+ {
+ selector_components.push_back (&backing_ast_context.Idents.get(decl_name.getAsString().c_str()));
+ }
+ else if (decl_name.isObjCOneArgSelector())
+ {
+ selector_components.push_back (&backing_ast_context.Idents.get(decl_name.getAsString().c_str()));
+ }
+ else
+ {
+ clang::Selector sel = decl_name.getObjCSelector();
+
+ for (unsigned i = 0, e = sel.getNumArgs();
+ i != e;
+ ++i)
+ {
+ llvm::StringRef r = sel.getNameForSlot(i);
+
+ selector_components.push_back (&backing_ast_context.Idents.get(r.str().c_str()));
+ }
+ }
+
+ Selector backing_selector = backing_interface_decl->getASTContext().Selectors.getSelector(selector_components.size(), selector_components.data());
+ DeclarationName backing_decl_name = DeclarationName(backing_selector);
+
+ DeclContext::lookup_const_result lookup_result = backing_interface_decl->lookup(backing_decl_name);
+
+ if (lookup_result.first == lookup_result.second)
+ continue;
+
+ ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(*lookup_result.first);
+
+ if (!method_decl)
+ continue;
+
+ Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &backing_ast_context, *lookup_result.first);
+
+ ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl> (copied_decl);
+
+ if (!copied_method_decl)
+ continue;
+
+ if (log)
+ {
+ ASTDumper dumper((Decl*)copied_method_decl);
+ log->Printf(" CAS::FOMD[%d] found (in symbols) %s", current_id, dumper.GetCString());
+ }
+
+ context.AddNamedDecl(copied_method_decl);
+ }
+ }
+
SymbolContextList sc_list;
const bool include_symbols = false;
@@ -614,7 +683,7 @@
if (log)
{
ASTDumper dumper((Decl*)copied_method_decl);
- log->Printf(" CAS::FOMD[%d] found %s", current_id, dumper.GetCString());
+ log->Printf(" CAS::FOMD[%d] found (in debug info) %s", current_id, dumper.GetCString());
}
context.AddNamedDecl(copied_method_decl);
@@ -777,6 +846,29 @@
}
}
+void
+ClangASTSource::CompleteObjCInterfaceMap (ClangASTImporter::ObjCInterfaceMapSP &objc_interface_map,
+ const ConstString &name) const
+{
+ SymbolContext null_sc;
+
+ TypeList types;
+
+ m_target->GetImages().FindTypes(null_sc, name, true, UINT32_MAX, types);
+
+ for (uint32_t i = 0, e = types.GetSize();
+ i != e;
+ ++i)
+ {
+ lldb::TypeSP mapped_type_sp = types.GetTypeAtIndex(i);
+
+ if (!mapped_type_sp || !mapped_type_sp->GetClangFullType())
+ continue;
+
+ objc_interface_map->push_back (ClangASTType(mapped_type_sp->GetClangAST(), mapped_type_sp->GetClangFullType()));
+ }
+}
+
NamespaceDecl *
ClangASTSource::AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls)
{
diff --git a/source/Expression/ClangExpressionDeclMap.cpp b/source/Expression/ClangExpressionDeclMap.cpp
index 6fbec8f..d879f19 100644
--- a/source/Expression/ClangExpressionDeclMap.cpp
+++ b/source/Expression/ClangExpressionDeclMap.cpp
@@ -895,8 +895,12 @@
return err.Success();
}
case Value::eValueTypeHostAddress:
- memcpy ((void *)value.GetScalar().ULongLong(), data, length);
- return true;
+ {
+ if (value.GetScalar().ULongLong() == 0 || data == NULL)
+ return false;
+ memcpy ((void *)value.GetScalar().ULongLong(), data, length);
+ return true;
+ }
case Value::eValueTypeScalar:
return false;
}
@@ -2474,7 +2478,7 @@
if (!ptype_type_decl)
break;
- Decl *parser_ptype_decl = ClangASTContext::CopyDecl(m_ast_context, scratch_ast_context, ptype_type_decl);
+ Decl *parser_ptype_decl = m_ast_importer->CopyDecl(m_ast_context, scratch_ast_context, ptype_type_decl);
if (!parser_ptype_decl)
break;
diff --git a/source/Expression/ClangUserExpression.cpp b/source/Expression/ClangUserExpression.cpp
index 4ae34a3..04d5c32 100644
--- a/source/Expression/ClangUserExpression.cpp
+++ b/source/Expression/ClangUserExpression.cpp
@@ -92,8 +92,7 @@
if (!m_result_synthesizer.get())
m_result_synthesizer.reset(new ASTResultSynthesizer(passthrough,
m_desired_type,
- *m_target->GetScratchClangASTContext()->getASTContext(),
- m_target->GetPersistentVariables()));
+ *m_target));
return m_result_synthesizer.get();
}