This change brings in the latest LLVM/Clang, and

completes the support in the LLDB expression parser
for incomplete types.  Clang now imports types
lazily, and we complete those types as necessary.

Changes include:

- ClangASTSource now supports three APIs which it
  passes to ClangExpressionDeclMap.  CompleteType
  completes a TagDecl or an ObjCInterfaceDecl when
  needed; FindExternalVisibleDecls finds named
  entities that are visible in the expression's
  scope; and FindExternalLexicalDecls performs a
  (potentially restricted) search for entities
  inside a lexical scope like a namespace.  These
  changes mean that entities in namespaces should
  work normally.

- The SymbolFileDWARF code for searching a context
  for a specific name is now more general, and can
  search arbitrary contexts.

- We are continuing to adapt our calls into LLVM
  from interfaces that take start and end iterators
  when accepting multiple items to interfaces that
  use ArrayRef.

- I have cleaned up some code, especially our use
  of namespaces.

This change is neutral for our testsuite and greatly
improves correctness for large programs (like Clang)
with complicated type systems.  It should also lay
the groundwork for improving the expression parser's
performance as we are lazier and lazier about
providing type information.

llvm-svn: 136555
This commit is contained in:
Sean Callanan 2011-07-30 02:42:06 +00:00
parent fc1aa292ad
commit cc427fadec
18 changed files with 469 additions and 270 deletions

View File

@ -141,7 +141,7 @@ public:
//------------------------------------------------------------------
/// Interface stub that returns true.
//------------------------------------------------------------------
virtual bool
virtual clang::ExternalLoadResult
FindExternalLexicalDecls (const clang::DeclContext *DC,
bool (*isKindWeWant)(clang::Decl::Kind),
llvm::SmallVectorImpl<clang::Decl*> &Decls);

View File

@ -21,6 +21,7 @@
// Project includes
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/DenseMap.h"
#include "clang/AST/Decl.h"
#include "lldb/lldb-public.h"
#include "lldb/Core/ClangForward.h"
#include "lldb/Core/Value.h"
@ -472,21 +473,42 @@ public:
const ConstString &name);
//------------------------------------------------------------------
/// [Used by ClangASTSource] Fill in all the members of a (potentially
/// incomplete) DeclContext.
///
/// @param[in] ast_context
/// The parser's AST context, in which the DeclContext is resident
/// [Used by ClangASTSource] Find all Decls in a context that match
/// a given criterion.
///
/// @param[in] decl_context
/// The DeclContext that needs to be filled in.
/// The DeclContext to search.
///
/// @return
/// The completed context on success; NULL otherwise.
/// @param[in] predicate
/// Returns True if a DeclKind is desired; False if not.
///
/// @param[in] decls
/// A list to add all found Decls that have a desired DeclKind
/// into.
//------------------------------------------------------------------
const clang::DeclContext *
CompleteDeclContext (clang::ASTContext *ast_context,
const clang::DeclContext *decl_context);
clang::ExternalLoadResult
FindExternalLexicalDecls (const clang::DeclContext *decl_context,
bool (*predicate)(clang::Decl::Kind),
llvm::SmallVectorImpl<clang::Decl*> &decls);
//------------------------------------------------------------------
/// [Used by ClangASTSource] Complete the definition of a TagDecl.
///
/// @param[in] tag_decl
/// The TagDecl to be completed.
//------------------------------------------------------------------
void
CompleteTagDecl (clang::TagDecl *tag_decl);
//------------------------------------------------------------------
/// [Used by ClangASTSource] Complete the definition of an
/// ObjCInterfaceDecl.
///
/// @param[in] tag_decl
/// The ObjCInterfaceDecl to be completed.
//------------------------------------------------------------------
void
CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl);
//------------------------------------------------------------------
/// [Used by ClangASTSource] Report whether a $__lldb variable has

View File

@ -554,7 +554,7 @@ private:
/// The Constant for the reference, usually a ConstantExpr.
//------------------------------------------------------------------
llvm::Constant *
BuildRelocation(const llvm::Type *type,
BuildRelocation(llvm::Type *type,
uint64_t offset);
//------------------------------------------------------------------

View File

@ -42,9 +42,12 @@ public:
clang::Decl *
CopyDecl (clang::ASTContext *src_ctx,
clang::Decl *decl);
void
CompleteTagDecl (clang::TagDecl *decl);
const clang::DeclContext *
CompleteDeclContext (const clang::DeclContext *decl_context);
void
CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl);
bool
ResolveDeclOrigin (const clang::Decl *decl, clang::Decl **original_decl, clang::ASTContext **original_ctx)
@ -111,12 +114,7 @@ private:
{
}
clang::Decl *Imported (clang::Decl *from, clang::Decl *to)
{
m_master.m_origins[to] = DeclOrigin (m_source_ctx, from);
return clang::ASTImporter::Imported(from, to);
}
clang::Decl *Imported (clang::Decl *from, clang::Decl *to);
ClangASTImporter &m_master;
clang::ASTContext *m_source_ctx;
@ -130,6 +128,8 @@ private:
{
MinionMap *minions;
minimal = true; // This override is temporary, while I sort out the attendant issues.
if (minimal)
minions = &m_minimal_minions;
else

View File

@ -118,15 +118,14 @@ public:
return;
}
virtual bool
virtual clang::ExternalLoadResult
FindExternalLexicalDecls (const clang::DeclContext *decl_ctx,
bool (*isKindWeWant)(clang::Decl::Kind),
llvm::SmallVectorImpl<clang::Decl*> &decls)
{
// This is used to support iterating through an entire lexical context,
// which isn't something the debugger should ever need to do.
// true is for error, that's good enough for me
return true;
return clang::ELR_Failure;
}
virtual clang::DeclContextLookupResult

View File

@ -26,7 +26,7 @@ our @llvm_clang_slices; # paths to the single architecture static libraries (arc
our $llvm_configuration = $ENV{LLVM_CONFIGURATION};
our $llvm_revision = "131657";
our $llvm_revision = "136537";
our $llvm_source_dir = "$ENV{SRCROOT}";
our @archs = split (/\s+/, $ENV{ARCHS});
@ -51,6 +51,7 @@ our @archive_files = (
"$llvm_configuration/lib/libLLVMARMAsmParser.a",
"$llvm_configuration/lib/libLLVMARMAsmPrinter.a",
"$llvm_configuration/lib/libLLVMARMCodeGen.a",
"$llvm_configuration/lib/libLLVMARMDesc.a",
"$llvm_configuration/lib/libLLVMARMDisassembler.a",
"$llvm_configuration/lib/libLLVMARMInfo.a",
"$llvm_configuration/lib/libLLVMAsmParser.a",
@ -81,6 +82,7 @@ our @archive_files = (
"$llvm_configuration/lib/libLLVMX86AsmParser.a",
"$llvm_configuration/lib/libLLVMX86AsmPrinter.a",
"$llvm_configuration/lib/libLLVMX86CodeGen.a",
"$llvm_configuration/lib/libLLVMX86Desc.a",
"$llvm_configuration/lib/libLLVMX86Disassembler.a",
"$llvm_configuration/lib/libLLVMX86Info.a",
"$llvm_configuration/lib/libLLVMX86Utils.a",

View File

@ -406,7 +406,6 @@ void ASTDumper::VisitType (const clang::Type *type)
m_stream.Indent(); m_stream.Printf("isCanonicalUnqualified() : %s\n", SfB(type->isCanonicalUnqualified()));
m_stream.Indent(); m_stream.Printf("isIncompleteType() : %s\n", SfB(type->isIncompleteType()));
m_stream.Indent(); m_stream.Printf("isObjectType() : %s\n", SfB(type->isObjectType()));
m_stream.Indent(); m_stream.Printf("isPODType() : %s\n", SfB(type->isPODType()));
m_stream.Indent(); m_stream.Printf("isLiteralType() : %s\n", SfB(type->isLiteralType()));
m_stream.Indent(); m_stream.Printf("isBuiltinType() : %s\n", SfB(type->isBuiltinType()));
m_stream.Indent(); m_stream.Printf("isPlaceholderType() : %s\n", SfB(type->isPlaceholderType()));

View File

@ -114,13 +114,13 @@ ClangASTSource::FindExternalVisibleDeclsByName
void
ClangASTSource::CompleteType (TagDecl *tag_decl)
{
puts(__PRETTY_FUNCTION__);
m_decl_map.CompleteTagDecl (tag_decl);
}
void
ClangASTSource::CompleteType (ObjCInterfaceDecl *objc_decl)
{
puts(__PRETTY_FUNCTION__);
m_decl_map.CompleteObjCInterfaceDecl (objc_decl);
}
void
@ -131,7 +131,7 @@ ClangASTSource::MaterializeVisibleDecls(const DeclContext *DC)
// This is used to support iterating through an entire lexical context,
// which isn't something the debugger should ever need to do.
bool
clang::ExternalLoadResult
ClangASTSource::FindExternalLexicalDecls
(
const DeclContext *DC,
@ -139,8 +139,7 @@ ClangASTSource::FindExternalLexicalDecls
llvm::SmallVectorImpl<Decl*> &Decls
)
{
// true is for error, that's good enough for me
return true;
return m_decl_map.FindExternalLexicalDecls (DC, isKindWeWant, Decls);
}
clang::ASTContext *

View File

@ -134,7 +134,7 @@ ClangExpressionDeclMap::BuildIntegerVariable (const ConstString &name,
{
assert (m_parser_vars.get());
ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
clang::ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
TypeFromUser user_type(ClangASTContext::CopyType(context,
type.GetASTContext(),
@ -203,7 +203,7 @@ ClangExpressionDeclMap::BuildIntegerVariable (const ConstString &name,
lldb::ClangExpressionVariableSP
ClangExpressionDeclMap::BuildCastVariable (const ConstString &name,
clang::VarDecl *decl,
VarDecl *decl,
lldb_private::TypeFromParser type)
{
assert (m_parser_vars.get());
@ -211,7 +211,7 @@ ClangExpressionDeclMap::BuildCastVariable (const ConstString &name,
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
clang::ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
ClangExpressionVariableSP var_sp (m_found_entities.GetVariable(decl));
@ -273,7 +273,7 @@ ClangExpressionDeclMap::BuildCastVariable (const ConstString &name,
bool
ClangExpressionDeclMap::AddPersistentVariable
(
const clang::NamedDecl *decl,
const NamedDecl *decl,
const ConstString &name,
TypeFromParser parser_type,
bool is_result,
@ -285,7 +285,7 @@ ClangExpressionDeclMap::AddPersistentVariable
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
clang::ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
TypeFromUser user_type(ClangASTContext::CopyType(context,
parser_type.GetASTContext(),
@ -333,7 +333,7 @@ ClangExpressionDeclMap::AddPersistentVariable
bool
ClangExpressionDeclMap::AddValueToStruct
(
const clang::NamedDecl *decl,
const NamedDecl *decl,
const ConstString &name,
llvm::Value *value,
size_t size,
@ -439,7 +439,7 @@ bool ClangExpressionDeclMap::GetStructInfo
bool
ClangExpressionDeclMap::GetStructElement
(
const clang::NamedDecl *&decl,
const NamedDecl *&decl,
llvm::Value *&value,
off_t &offset,
ConstString &name,
@ -472,7 +472,7 @@ ClangExpressionDeclMap::GetStructElement
bool
ClangExpressionDeclMap::GetFunctionInfo
(
const clang::NamedDecl *decl,
const NamedDecl *decl,
llvm::Value**& value,
uint64_t &ptr
)
@ -915,7 +915,7 @@ ClangExpressionDeclMap::DoMaterialize
if (log)
log->PutCString("Not bothering to allocate a struct because no arguments are needed");
m_material_vars->m_allocated_area = 0;
m_material_vars->m_allocated_area = NULL;
return true;
}
@ -1674,61 +1674,57 @@ ClangExpressionDeclMap::GetDecls (NameSearchContext &context, const ConstString
if (isa<TranslationUnitDecl>(context.m_decl_context))
break;
if (log)
log->Printf("'%s' is in something other than a translation unit", name.GetCString());
const Decl *context_decl = dyn_cast<Decl>(context.m_decl_context);
if (!context_decl)
if (!isa<NamespaceDecl>(context.m_decl_context))
return;
if (const NamespaceDecl *namespace_decl = dyn_cast<NamespaceDecl>(context_decl))
const Decl *context_decl = dyn_cast<Decl>(context.m_decl_context);
if (log)
log->Printf("Searching for '%s' in a '%s'", name.GetCString(), context_decl->getDeclKindName());
Decl *original_decl = NULL;
ASTContext *original_ctx = NULL;
if (!m_parser_vars->GetASTImporter(context.GetASTContext())->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx))
break;
if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl))
{
Decl *original_decl = NULL;
ASTContext *original_ctx = NULL;
ExternalASTSource *external_source = original_ctx->getExternalSource();
if (log)
log->Printf("Resolving the containing context's origin...");
if (!m_parser_vars->GetASTImporter(context.GetASTContext())->ResolveDeclOrigin(namespace_decl, &original_decl, &original_ctx))
if (!external_source)
break;
if (log)
log->Printf("Casting it to a DeclContext...");
DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
if (!original_decl_context)
break;
if (log)
{
std::string s;
llvm::raw_string_ostream os(s);
original_decl->print(os);
os.flush();
log->Printf("Containing context:");
log->Printf("%s", s.c_str());
}
if (!original_ctx->getExternalSource())
break;
DeclContextLookupConstResult original_lookup_result = original_ctx->getExternalSource()->FindExternalVisibleDeclsByName(original_decl_context, context.m_decl_name);
NamedDecl *const *iter = NULL;
if (!original_tag_decl)
break;
for (iter = original_lookup_result.first;
iter != original_lookup_result.second;
++iter)
{
clang::NamedDecl *copied_result = dyn_cast<NamedDecl>(m_parser_vars->GetASTImporter(context.GetASTContext())->CopyDecl(original_ctx, *iter));
external_source->CompleteType (original_tag_decl);
}
DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
if (!original_decl_context)
break;
if (copied_result)
context.AddNamedDecl(copied_result);
for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
iter != original_decl_context->decls_end();
++iter)
{
NamedDecl *named_decl = dyn_cast<NamedDecl>(*iter);
if (named_decl && named_decl->getName().equals(name.GetCString()))
{
Decl *copied_decl = m_parser_vars->GetASTImporter(context.GetASTContext())->CopyDecl(original_ctx, named_decl);
NamedDecl *copied_named_decl = dyn_cast<NamedDecl>(copied_decl);
if (!copied_named_decl)
continue;
context.AddNamedDecl (copied_named_decl);
}
}
return;
}
while (0);
@ -1824,7 +1820,7 @@ ClangExpressionDeclMap::GetDecls (NameSearchContext &context, const ConstString
log->Printf("%s", s.c_str());
}
clang::NamespaceDecl *clang_namespace_decl = AddNamespace(context, namespace_decl);
NamespaceDecl *clang_namespace_decl = AddNamespace(context, namespace_decl);
if (clang_namespace_decl)
clang_namespace_decl->setHasExternalLexicalStorage();
}
@ -1976,44 +1972,103 @@ ClangExpressionDeclMap::GetDecls (NameSearchContext &context, const ConstString
}
}
const clang::DeclContext *
ClangExpressionDeclMap::CompleteDeclContext (clang::ASTContext *ast_context,
const clang::DeclContext *decl_context)
clang::ExternalLoadResult
ClangExpressionDeclMap::FindExternalLexicalDecls (const DeclContext *decl_context,
bool (*predicate)(Decl::Kind),
llvm::SmallVectorImpl<Decl*> &decls)
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
if (log)
{
const NamedDecl *named_decl = dyn_cast<NamedDecl>(decl_context);
if (named_decl)
log->Printf("Completing a '%s' DeclContext named '%s'", decl_context->getDeclKindName(), named_decl->getDeclName().getAsString().c_str());
else
log->Printf("Completing a '%s' DeclContext", decl_context->getDeclKindName());
}
assert (m_parser_vars.get());
if (!m_parser_vars->GetASTImporter (ast_context)->CompleteDeclContext(decl_context))
return NULL;
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
const Decl *context_decl = dyn_cast<Decl>(decl_context);
if (!context_decl)
return ELR_Failure;
ASTContext *ast_context = &context_decl->getASTContext();
if (log)
log->Printf("Finding lexical decls in a '%s' with %s predicate", context_decl->getDeclKindName(), (predicate ? "non-null" : "null"));
Decl *original_decl = NULL;
ASTContext *original_ctx = NULL;
ClangASTImporter *ast_importer = m_parser_vars->GetASTImporter(ast_context);
if (!ast_importer)
return ELR_Failure;
if (!ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx))
return ELR_Failure;
if (log)
{
const Decl *decl = dyn_cast<Decl>(decl_context);
std::string decl_print_string;
llvm::raw_string_ostream decl_print_stream(decl_print_string);
original_decl->print(decl_print_stream);
decl_print_stream.flush();
log->Printf("Original decl:\n%s", decl_print_string.c_str());
}
if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl))
{
ExternalASTSource *external_source = original_ctx->getExternalSource();
if (decl)
if (!external_source)
return ELR_Failure;
if (!original_tag_decl)
return ELR_Failure;
external_source->CompleteType (original_tag_decl);
}
DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
if (!original_decl_context)
return ELR_Failure;
for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
iter != original_decl_context->decls_end();
++iter)
{
Decl *decl = *iter;
if (!predicate || predicate(decl->getKind()))
{
std::string s;
llvm::raw_string_ostream os(s);
decl->print(os);
os.flush();
if (log)
{
std::string decl_print_string;
llvm::raw_string_ostream decl_print_stream(decl_print_string);
decl->print(decl_print_stream);
decl_print_stream.flush();
log->Printf(" Adding lexical decl %s", decl_print_string.c_str());
}
Decl *copied_decl = ast_importer->CopyDecl(original_ctx, decl);
log->Printf("After:");
log->Printf("%s", s.c_str());
decls.push_back(copied_decl);
}
}
return decl_context;
return ELR_AlreadyLoaded;
}
void
ClangExpressionDeclMap::CompleteTagDecl (TagDecl *tag_decl)
{
assert (m_parser_vars.get());
m_parser_vars->GetASTImporter(&tag_decl->getASTContext())->CompleteTagDecl (tag_decl);
}
void
ClangExpressionDeclMap::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl)
{
assert (m_parser_vars.get());
m_parser_vars->GetASTImporter(&interface_decl->getASTContext())->CompleteObjCInterfaceDecl (interface_decl);
}
Value *
@ -2021,7 +2076,7 @@ ClangExpressionDeclMap::GetVariableValue
(
ExecutionContext &exe_ctx,
VariableSP var,
clang::ASTContext *parser_ast_context,
ASTContext *parser_ast_context,
TypeFromUser *user_type,
TypeFromParser *parser_type
)
@ -2046,7 +2101,7 @@ ClangExpressionDeclMap::GetVariableValue
return NULL;
}
clang::ASTContext *ast = var_type->GetClangASTContext().getASTContext();
ASTContext *ast = var_type->GetClangASTContext().getASTContext();
if (!ast)
{
@ -2170,12 +2225,12 @@ ClangExpressionDeclMap::AddOneVariable (NameSearchContext &context, VariableSP v
log->Printf("Found variable %s, returned %s", decl_name.c_str(), var_decl_print_string.c_str());
if (log->GetVerbose())
{
StreamString var_decl_dump_string;
ASTDumper::DumpDecl(var_decl_dump_string, var_decl);
log->Printf("%s\n", var_decl_dump_string.GetData());
}
//if (log->GetVerbose())
//{
// StreamString var_decl_dump_string;
// ASTDumper::DumpDecl(var_decl_dump_string, var_decl);
// log->Printf("%s\n", var_decl_dump_string.GetData());
//}
}
}
@ -2219,7 +2274,7 @@ ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
clang::ASTContext *scratch_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext()->getASTContext();
ASTContext *scratch_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext()->getASTContext();
TypeFromUser user_type (ClangASTContext::CreateLValueReferenceType(scratch_ast_context, ClangASTContext::GetVoidPtrType(scratch_ast_context, true)),
scratch_ast_context);
@ -2265,12 +2320,12 @@ ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
log->Printf("Found variable %s, returned %s", decl_name.c_str(), var_decl_print_string.c_str());
if (log->GetVerbose())
{
StreamString var_decl_dump_string;
ASTDumper::DumpDecl(var_decl_dump_string, var_decl);
log->Printf("%s\n", var_decl_dump_string.GetData());
}
//if (log->GetVerbose())
//{
// StreamString var_decl_dump_string;
// ASTDumper::DumpDecl(var_decl_dump_string, var_decl);
// log->Printf("%s\n", var_decl_dump_string.GetData());
//}
}
}
@ -2279,7 +2334,7 @@ ClangExpressionDeclMap::ResolveUnknownTypes()
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
clang::ASTContext *scratch_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext()->getASTContext();
ASTContext *scratch_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext()->getASTContext();
for (size_t index = 0, num_entities = m_found_entities.GetSize();
index < num_entities;
@ -2374,17 +2429,17 @@ ClangExpressionDeclMap::AddOneRegister (NameSearchContext &context,
}
}
clang::NamespaceDecl *
NamespaceDecl *
ClangExpressionDeclMap::AddNamespace (NameSearchContext &context, const ClangNamespaceDecl &namespace_decl)
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
assert (m_parser_vars.get());
clang::Decl *copied_decl = m_parser_vars->GetASTImporter(context.GetASTContext())->CopyDecl(namespace_decl.GetASTContext(),
Decl *copied_decl = m_parser_vars->GetASTImporter(context.GetASTContext())->CopyDecl(namespace_decl.GetASTContext(),
namespace_decl.GetNamespaceDecl());
return dyn_cast<clang::NamespaceDecl>(copied_decl);
return dyn_cast<NamespaceDecl>(copied_decl);
}
void
@ -2402,7 +2457,7 @@ ClangExpressionDeclMap::AddOneFunction (NameSearchContext &context,
// only valid for Functions, not for Symbols
void *fun_opaque_type = NULL;
clang::ASTContext *fun_ast_context = NULL;
ASTContext *fun_ast_context = NULL;
if (fun)
{
@ -2478,8 +2533,8 @@ ClangExpressionDeclMap::AddOneType(NameSearchContext &context,
TypeFromUser &ut,
bool add_method)
{
clang::ASTContext *parser_ast_context = context.GetASTContext();
clang::ASTContext *user_ast_context = ut.GetASTContext();
ASTContext *parser_ast_context = context.GetASTContext();
ASTContext *user_ast_context = ut.GetASTContext();
void *copied_type = GuardedCopyType(parser_ast_context, user_ast_context, ut.GetOpaqueQualType());

View File

@ -123,7 +123,6 @@ static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) {
case ASTPrint: return new ASTPrintAction();
case ASTDumpXML: return new ASTDumpXMLAction();
case ASTView: return new ASTViewAction();
case BoostCon: return new BoostConAction();
case DumpRawTokens: return new DumpRawTokensAction();
case DumpTokens: return new DumpTokensAction();
case EmitAssembly: return new EmitAssemblyAction();
@ -199,6 +198,7 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
InitializeLLVM() {
llvm::InitializeAllTargets();
llvm::InitializeAllAsmPrinters();
llvm::InitializeAllTargetMCs();
}
} InitializeLLVM;
@ -557,9 +557,7 @@ ClangExpressionParser::MakeJIT (lldb::addr_t &func_allocation_addr,
RecordingMemoryManager *jit_memory_manager = new RecordingMemoryManager();
std::string error_string;
llvm::TargetMachine::setRelocationModel(llvm::Reloc::PIC_);
#if defined (USE_STANDARD_JIT)
m_execution_engine.reset(llvm::ExecutionEngine::createJIT (module,
&error_string,
@ -571,11 +569,12 @@ ClangExpressionParser::MakeJIT (lldb::addr_t &func_allocation_addr,
EngineBuilder builder(module);
builder.setEngineKind(EngineKind::JIT)
.setErrorStr(&error_string)
.setRelocationModel(llvm::Reloc::PIC_)
.setJITMemoryManager(jit_memory_manager)
.setOptLevel(CodeGenOpt::Less)
.setAllocateGVsWithCode(true)
.setCodeModel(CodeModel::Small)
.setUseMCJIT(true);
.setUseMCJIT(true);
m_execution_engine.reset(builder.create());
#endif

View File

@ -258,12 +258,14 @@ protected:
//------------------------------------------------------------------
llvm::Value *BuildPointerValidatorFunc(lldb::addr_t start_address)
{
std::vector<const llvm::Type*> params;
const IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(),
IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(),
(m_module.getPointerSize() == llvm::Module::Pointer64) ? 64 : 32);
params.push_back(GetI8PtrTy());
llvm::Type *param_array[1];
param_array[0] = const_cast<llvm::PointerType*>(GetI8PtrTy());
ArrayRef<llvm::Type*> params(param_array, 1);
FunctionType *fun_ty = FunctionType::get(llvm::Type::getVoidTy(m_module.getContext()), params, true);
PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty);
@ -271,7 +273,7 @@ protected:
return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty);
}
const PointerType *GetI8PtrTy()
PointerType *GetI8PtrTy()
{
if (!m_i8ptr_ty)
m_i8ptr_ty = llvm::Type::getInt8PtrTy(m_module.getContext());
@ -286,7 +288,7 @@ protected:
llvm::Module &m_module; ///< The module which is being instrumented
DynamicCheckerFunctions &m_checker_functions; ///< The dynamic checker functions for the process
private:
const PointerType *m_i8ptr_ty;
PointerType *m_i8ptr_ty;
};
class ValidPointerChecker : public Instrumenter
@ -332,12 +334,14 @@ private:
// Insert an instruction to call the helper with the result
SmallVector <llvm::Value*, 1> args;
args.push_back(bit_cast);
llvm::Value *arg_array[1];
arg_array[0] = bit_cast;
llvm::ArrayRef<llvm::Value *> args(arg_array, 1);
CallInst::Create(m_valid_pointer_check_func,
args.begin(),
args.end(),
args,
"",
inst);
@ -397,12 +401,14 @@ private:
// Insert an instruction to call the helper with the result
SmallVector <llvm::Value*, 1> args;
args.push_back(bit_cast);
llvm::Value *arg_array[1];
arg_array[0] = bit_cast;
ArrayRef<llvm::Value*> args(arg_array, 1);
CallInst::Create(m_objc_object_check_func,
args.begin(),
args.end(),
args,
"",
inst);

View File

@ -310,24 +310,28 @@ IRForTarget::CreateResultVariable (llvm::Function &llvm_function)
ValueSymbolTable& value_symbol_table = m_module->getValueSymbolTable();
std::string result_name_str;
const char *result_name = NULL;
for (ValueSymbolTable::iterator vi = value_symbol_table.begin(), ve = value_symbol_table.end();
vi != ve;
++vi)
{
if (strstr(vi->first(), "$__lldb_expr_result_ptr") &&
!strstr(vi->first(), "GV"))
result_name_str = vi->first().str();
const char *value_name = result_name_str.c_str();
if (strstr(value_name, "$__lldb_expr_result_ptr") &&
!strstr(value_name, "GV"))
{
result_name = vi->first();
result_name = value_name;
m_result_is_pointer = true;
break;
}
if (strstr(vi->first(), "$__lldb_expr_result") &&
!strstr(vi->first(), "GV"))
if (strstr(value_name, "$__lldb_expr_result") &&
!strstr(value_name, "GV"))
{
result_name = vi->first();
result_name = value_name;
m_result_is_pointer = false;
break;
}
@ -580,13 +584,13 @@ IRForTarget::RewriteObjCConstString (llvm::GlobalVariable *ns_str,
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
const Type *ns_str_ty = ns_str->getType();
Type *ns_str_ty = ns_str->getType();
const Type *i8_ptr_ty = Type::getInt8PtrTy(m_module->getContext());
const IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
Type *i8_ptr_ty = Type::getInt8PtrTy(m_module->getContext());
IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
(m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
const Type *i32_ty = Type::getInt32Ty(m_module->getContext());
const Type *i8_ty = Type::getInt8Ty(m_module->getContext());
Type *i32_ty = Type::getInt32Ty(m_module->getContext());
Type *i8_ty = Type::getInt8Ty(m_module->getContext());
if (!m_CFStringCreateWithBytes)
{
@ -627,12 +631,16 @@ IRForTarget::RewriteObjCConstString (llvm::GlobalVariable *ns_str,
// CFStringEncoding -> i32
// Boolean -> i8
std::vector <const Type *> CFSCWB_arg_types;
CFSCWB_arg_types.push_back(i8_ptr_ty);
CFSCWB_arg_types.push_back(i8_ptr_ty);
CFSCWB_arg_types.push_back(intptr_ty);
CFSCWB_arg_types.push_back(i32_ty);
CFSCWB_arg_types.push_back(i8_ty);
Type *arg_type_array[5];
arg_type_array[0] = i8_ptr_ty;
arg_type_array[1] = i8_ptr_ty;
arg_type_array[2] = intptr_ty;
arg_type_array[3] = i32_ty;
arg_type_array[4] = i8_ty;
ArrayRef<Type *> CFSCWB_arg_types(arg_type_array, 5);
llvm::Type *CFSCWB_ty = FunctionType::get(ns_str_ty, CFSCWB_arg_types, false);
// Build the constant containing the pointer to the function
@ -645,24 +653,25 @@ IRForTarget::RewriteObjCConstString (llvm::GlobalVariable *ns_str,
if (cstr)
string_array = dyn_cast<ConstantArray>(cstr->getInitializer());
SmallVector <Value*, 5> CFSCWB_arguments;
Constant *alloc_arg = Constant::getNullValue(i8_ptr_ty);
Constant *bytes_arg = cstr ? ConstantExpr::getBitCast(cstr, i8_ptr_ty) : Constant::getNullValue(i8_ptr_ty);
Constant *numBytes_arg = ConstantInt::get(intptr_ty, cstr ? string_array->getType()->getNumElements() - 1 : 0, false);
Constant *encoding_arg = ConstantInt::get(i32_ty, 0x0600, false); /* 0x0600 is kCFStringEncodingASCII */
Constant *isExternal_arg = ConstantInt::get(i8_ty, 0x0, false); /* 0x0 is false */
CFSCWB_arguments.push_back(alloc_arg);
CFSCWB_arguments.push_back(bytes_arg);
CFSCWB_arguments.push_back(numBytes_arg);
CFSCWB_arguments.push_back(encoding_arg);
CFSCWB_arguments.push_back(isExternal_arg);
Value *argument_array[5];
argument_array[0] = alloc_arg;
argument_array[1] = bytes_arg;
argument_array[2] = numBytes_arg;
argument_array[3] = encoding_arg;
argument_array[4] = isExternal_arg;
ArrayRef <Value *> CFSCWB_arguments(argument_array, 5);
CallInst *CFSCWB_call = CallInst::Create(m_CFStringCreateWithBytes,
CFSCWB_arguments.begin(),
CFSCWB_arguments.end(),
CFSCWB_arguments,
"CFStringCreateWithBytes",
FirstEntryInstruction);
@ -707,7 +716,10 @@ IRForTarget::RewriteObjCConstStrings(Function &llvm_function)
vi != ve;
++vi)
{
if (strstr(vi->first(), "_unnamed_cfstring_"))
std::string value_name = vi->first().str();
const char *value_name_cstr = value_name.c_str();
if (strstr(value_name_cstr, "_unnamed_cfstring_"))
{
Value *nsstring_value = vi->second;
@ -860,9 +872,9 @@ IRForTarget::RewriteObjCConstStrings(Function &llvm_function)
if (log)
{
if (cstr_array)
log->Printf("Found NSString constant %s, which contains \"%s\"", vi->first(), cstr_array->getAsString().c_str());
log->Printf("Found NSString constant %s, which contains \"%s\"", value_name_cstr, cstr_array->getAsString().c_str());
else
log->Printf("Found NSString constant %s, which contains \"\"", vi->first());
log->Printf("Found NSString constant %s, which contains \"\"", value_name_cstr);
}
if (!cstr_array)
@ -884,7 +896,10 @@ IRForTarget::RewriteObjCConstStrings(Function &llvm_function)
vi != ve;
++vi)
{
if (!strcmp(vi->first(), "__CFConstantStringClassReference"))
std::string value_name = vi->first().str();
const char *value_name_cstr = value_name.c_str();
if (!strcmp(value_name_cstr, "__CFConstantStringClassReference"))
{
GlobalVariable *gv = dyn_cast<GlobalVariable>(vi->second);
@ -995,29 +1010,34 @@ IRForTarget::RewriteObjCSelector (Instruction* selector_load)
// The below code would be "more correct," but in actuality what's required is uint8_t*
//Type *sel_type = StructType::get(m_module->getContext());
//Type *sel_ptr_type = PointerType::getUnqual(sel_type);
const Type *sel_ptr_type = Type::getInt8PtrTy(m_module->getContext());
Type *sel_ptr_type = Type::getInt8PtrTy(m_module->getContext());
Type *type_array[1];
type_array[0] = llvm::Type::getInt8PtrTy(m_module->getContext());
ArrayRef<Type *> srN_arg_types(type_array, 1);
std::vector <const Type *> srN_arg_types;
srN_arg_types.push_back(Type::getInt8PtrTy(m_module->getContext()));
llvm::Type *srN_type = FunctionType::get(sel_ptr_type, srN_arg_types, false);
// Build the constant containing the pointer to the function
const IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
(m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
(m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
PointerType *srN_ptr_ty = PointerType::getUnqual(srN_type);
Constant *srN_addr_int = ConstantInt::get(intptr_ty, sel_registerName_addr, false);
m_sel_registerName = ConstantExpr::getIntToPtr(srN_addr_int, srN_ptr_ty);
}
SmallVector <Value*, 1> srN_arguments;
Value *argument_array[1];
Constant *omvn_pointer = ConstantExpr::getBitCast(_objc_meth_var_name_, Type::getInt8PtrTy(m_module->getContext()));
srN_arguments.push_back(omvn_pointer);
argument_array[0] = omvn_pointer;
ArrayRef<Value *> srN_arguments(argument_array, 1);
CallInst *srN_call = CallInst::Create(m_sel_registerName,
srN_arguments.begin(),
srN_arguments.end(),
srN_arguments,
"sel_registerName",
selector_load);
@ -1338,10 +1358,10 @@ IRForTarget::HandleSymbol (Value *symbol)
if (log)
log->Printf("Found \"%s\" at 0x%llx", name.GetCString(), symbol_addr);
const Type *symbol_type = symbol->getType();
Type *symbol_type = symbol->getType();
const IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
(m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
(m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
Constant *symbol_addr_int = ConstantInt::get(intptr_ty, symbol_addr, false);
@ -1398,7 +1418,7 @@ IRForTarget::MaybeHandleCall (CallInst *llvm_call_inst)
if (!fun)
{
if (m_error_stream)
m_error_stream->Printf("Internal error [IRForTarget]: Called entity is a cast of something not a function\n");
m_error_stream->Printf("Internal error [IRForTaget]: Called entity is a cast of something not a function\n");
return false;
}
@ -1495,9 +1515,9 @@ IRForTarget::MaybeHandleCall (CallInst *llvm_call_inst)
if (!fun_value_ptr || !*fun_value_ptr)
{
const IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
(m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
const FunctionType *fun_ty = fun->getFunctionType();
IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
(m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
FunctionType *fun_ty = fun->getFunctionType();
PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty);
Constant *fun_addr_int = ConstantInt::get(intptr_ty, fun_addr, false);
fun_addr_ptr = ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty);
@ -1636,7 +1656,7 @@ IRForTarget::ReplaceStrings ()
m_data_allocator->GetStream().Write(str.c_str(), str.length() + 1);
}
const Type *char_ptr_ty = Type::getInt8PtrTy(m_module->getContext());
Type *char_ptr_ty = Type::getInt8PtrTy(m_module->getContext());
for (OffsetsTy::iterator oi = offsets.begin(), oe = offsets.end();
oi != oe;
@ -1789,7 +1809,7 @@ IRForTarget::ReplaceStaticLiterals (llvm::BasicBlock &basic_block)
m_data_allocator->GetStream().Write(data.GetBytes(), operand_data_size);
const llvm::Type *fp_ptr_ty = operand_constant_fp->getType()->getPointerTo();
llvm::Type *fp_ptr_ty = operand_constant_fp->getType()->getPointerTo();
Constant *new_pointer = BuildRelocation(fp_ptr_ty, offset);
@ -1961,8 +1981,8 @@ IRForTarget::UnfoldConstant(Constant *old_constant, Value *new_constant, Instruc
if (ptr == old_constant)
ptr = new_constant;
SmallVector<Value*, 16> indices;
std::vector<Value*> index_vector;
unsigned operand_index;
unsigned num_operands = constant_expr->getNumOperands();
@ -1976,10 +1996,12 @@ IRForTarget::UnfoldConstant(Constant *old_constant, Value *new_constant, Instruc
if (operand == old_constant)
operand = new_constant;
indices.push_back(operand);
index_vector.push_back(operand);
}
GetElementPtrInst *get_element_ptr(GetElementPtrInst::Create(ptr, indices.begin(), indices.end(), "", first_entry_inst));
ArrayRef <Value*> indices(index_vector);
GetElementPtrInst *get_element_ptr(GetElementPtrInst::Create(ptr, indices, "", first_entry_inst));
UnfoldConstant(constant_expr, get_element_ptr, first_entry_inst);
}
@ -2107,7 +2129,7 @@ IRForTarget::ReplaceVariables (Function &llvm_function)
}
LLVMContext &context(m_module->getContext());
const IntegerType *offset_type(Type::getInt32Ty(context));
IntegerType *offset_type(Type::getInt32Ty(context));
if (!offset_type)
{
@ -2139,7 +2161,7 @@ IRForTarget::ReplaceVariables (Function &llvm_function)
PrintValue(value, true).c_str(),
offset);
ConstantInt *offset_int(ConstantInt::getSigned(offset_type, offset));
ConstantInt *offset_int(ConstantInt::get(offset_type, offset, true));
GetElementPtrInst *get_element_ptr = GetElementPtrInst::Create(argument, offset_int, "", FirstEntryInstruction);
Value *replacement = NULL;
@ -2178,16 +2200,23 @@ IRForTarget::ReplaceVariables (Function &llvm_function)
}
llvm::Constant *
IRForTarget::BuildRelocation(const llvm::Type *type,
IRForTarget::BuildRelocation(llvm::Type *type,
uint64_t offset)
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
const IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
(m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
(m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
llvm::Constant *offset_int = ConstantInt::get(intptr_ty, offset);
llvm::Constant *reloc_getelementptr = ConstantExpr::getGetElementPtr(m_reloc_placeholder, &offset_int, 1);
llvm::Constant *offset_array[1];
offset_array[0] = offset_int;
llvm::ArrayRef<llvm::Constant *> offsets(offset_array, 1);
llvm::Constant *reloc_getelementptr = ConstantExpr::getGetElementPtr(m_reloc_placeholder, offsets);
llvm::Constant *reloc_getbitcast = ConstantExpr::getBitCast(reloc_getelementptr, type);
return reloc_getbitcast;
@ -2214,8 +2243,8 @@ IRForTarget::CompleteDataAllocation ()
if (!allocation)
return false;
const IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
(m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
(m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
Constant *relocated_addr = ConstantInt::get(intptr_ty, (uint64_t)allocation);
Constant *relocated_bitcast = ConstantExpr::getIntToPtr(relocated_addr, llvm::Type::getInt8PtrTy(m_module->getContext()));
@ -2255,7 +2284,7 @@ IRForTarget::runOnModule (Module &llvm_module)
return false;
}
const llvm::Type *intptr_ty = Type::getInt8Ty(m_module->getContext());
llvm::Type *intptr_ty = Type::getInt8Ty(m_module->getContext());
m_reloc_placeholder = new llvm::GlobalVariable((*m_module),
intptr_ty,

View File

@ -22,6 +22,8 @@
#include "clang/Basic/Specifiers.h"
#include "clang/Sema/DeclSpec.h"
#include "llvm/Support/Casting.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/RegularExpression.h"
@ -4437,16 +4439,35 @@ SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDec
}
void
SymbolFileDWARF::SearchNamespace (const clang::NamespaceDecl *namespace_decl,
const char *name,
llvm::SmallVectorImpl <clang::NamedDecl *> *results)
SymbolFileDWARF::DumpIndexes ()
{
StreamFile s(stdout, false);
s.Printf ("DWARF index for (%s) '%s/%s':",
GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
GetObjectFile()->GetFileSpec().GetFilename().AsCString());
s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
s.Printf("\nNamepaces:\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((const clang::DeclContext*)namespace_decl);
DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
if (iter == m_decl_ctx_to_die.end())
return;
const DWARFDebugInfoEntry *namespace_die = iter->second;
const DWARFDebugInfoEntry *context_die = iter->second;
if (!results)
return;
@ -4467,7 +4488,7 @@ SymbolFileDWARF::SearchNamespace (const clang::NamespaceDecl *namespace_decl,
compile_unit->ExtractDIEsIfNeeded (false);
const DWARFDebugInfoEntry *die = compile_unit->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
if (die->GetParent() != namespace_die)
if (die->GetParent() != context_die)
continue;
Type *matching_type = ResolveType (compile_unit, die);
@ -4475,13 +4496,12 @@ SymbolFileDWARF::SearchNamespace (const clang::NamespaceDecl *namespace_decl,
lldb::clang_type_t type = matching_type->GetClangFullType();
clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
if (const clang::TagType *tag_type = dyn_cast<clang::TagType>(qual_type.getTypePtr()))
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 = dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
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);
@ -4498,7 +4518,5 @@ SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
{
SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
const clang::NamespaceDecl *DC_namespace = llvm::dyn_cast<clang::NamespaceDecl>(DC);
symbol_file_dwarf->SearchNamespace (DC_namespace, Name.getAsString().c_str(), results);
symbol_file_dwarf->SearchDeclContext (DC, Name.getAsString().c_str(), results);
}

View File

@ -189,10 +189,10 @@ public:
GetClangDeclContextForDIEOffset (dw_offset_t die_offset);
void
SearchNamespace (const clang::NamespaceDecl *namespace_decl,
const char *name,
llvm::SmallVectorImpl <clang::NamedDecl *> *results);
SearchDeclContext (const clang::DeclContext *decl_context,
const char *name,
llvm::SmallVectorImpl <clang::NamedDecl *> *results);
lldb_private::Flags&
GetFlags ()
{
@ -317,6 +317,8 @@ protected:
uint32_t FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, lldb_private::TypeList& types);
void Index();
void DumpIndexes();
void SetDebugMapSymfile (SymbolFileDWARFDebugMap *debug_map_symfile)
{

View File

@ -1607,9 +1607,10 @@ ClangASTContext::AddFieldToRecordType
SourceLocation(),
name ? &identifier_table->get(name) : NULL, // Identifier
QualType::getFromOpaquePtr(field_type), // Field type
NULL, // DeclaratorInfo *
NULL, // TInfo *
bit_width, // BitWidth
false); // Mutable
false, // Mutable
false); // HasInit
field->setAccess (ConvertAccessTypeToAccessSpecifier (access));
@ -3170,7 +3171,7 @@ ClangASTContext::GetIndexOfChildMemberWithName
//const Decl *root_cdecl = cxx_record_decl->getCanonicalDecl();
// Didn't find things easily, lets let clang do its thang...
IdentifierInfo & ident_ref = ast->Idents.get(name, name + strlen (name));
IdentifierInfo & ident_ref = ast->Idents.get(name_sref);
DeclarationName decl_name(&ident_ref);
CXXBasePaths paths;
@ -3647,6 +3648,7 @@ ClangASTContext::GetDeclContextForType (clang_type_t clang_type)
const clang::Type::TypeClass type_class = qual_type->getTypeClass();
switch (type_class)
{
case clang::Type::UnaryTransform: break;
case clang::Type::FunctionNoProto: break;
case clang::Type::FunctionProto: break;
case clang::Type::IncompleteArray: break;

View File

@ -8,6 +8,8 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
#include "lldb/Core/Log.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/ClangASTImporter.h"
@ -19,8 +21,10 @@ ClangASTImporter::CopyType (clang::ASTContext *src_ast,
clang::QualType type)
{
MinionSP minion_sp (GetMinion(src_ast, false));
if (minion_sp)
return minion_sp->Import(type);
return QualType();
}
@ -37,28 +41,84 @@ ClangASTImporter::CopyDecl (clang::ASTContext *src_ast,
if (minion_sp)
return minion_sp->Import(decl);
return NULL;
}
const clang::DeclContext *
ClangASTImporter::CompleteDeclContext (const clang::DeclContext *decl_context)
void
ClangASTImporter::CompleteTagDecl (clang::TagDecl *decl)
{
const Decl *context_decl = dyn_cast<Decl>(decl_context);
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
if (log)
log->Printf("Completing a TagDecl named %s", decl->getName().str().c_str());
if (!context_decl)
return NULL;
DeclOrigin decl_origin = GetDeclOrigin(decl);
DeclOrigin context_decl_origin = GetDeclOrigin(context_decl);
if (!decl_origin.Valid())
return;
if (!context_decl_origin.Valid())
return NULL;
if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
return;
if (!ClangASTContext::GetCompleteDecl(context_decl_origin.ctx, context_decl_origin.decl))
return NULL;
MinionSP minion_sp (GetMinion(decl_origin.ctx, false));
MinionSP minion_sp (GetMinion(context_decl_origin.ctx, false));
if (minion_sp)
minion_sp->ImportDefinition(context_decl_origin.decl);
minion_sp->ImportDefinition(decl_origin.decl);
return decl_context;
return;
}
void
ClangASTImporter::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl)
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
if (log)
log->Printf("Completing an ObjCInterfaceDecl named %s", interface_decl->getName().str().c_str());
DeclOrigin decl_origin = GetDeclOrigin(interface_decl);
if (!decl_origin.Valid())
return;
if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
return;
MinionSP minion_sp (GetMinion(decl_origin.ctx, false));
if (minion_sp)
minion_sp->ImportDefinition(decl_origin.decl);
return;
}
clang::Decl
*ClangASTImporter::Minion::Imported (clang::Decl *from, clang::Decl *to)
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
m_master.m_origins[to] = DeclOrigin (m_source_ctx, from);
if (TagDecl *from_tag_decl = dyn_cast<TagDecl>(from))
{
TagDecl *to_tag_decl = dyn_cast<TagDecl>(to);
to_tag_decl->setHasExternalLexicalStorage();
if (log)
log->Printf("Imported a TagDecl named %s%s%s",
from_tag_decl->getName().str().c_str(),
(to_tag_decl->hasExternalLexicalStorage() ? " Lexical" : ""),
(to_tag_decl->hasExternalVisibleStorage() ? " Visible" : ""));
}
if (isa<ObjCInterfaceDecl>(from))
{
ObjCInterfaceDecl *to_interface_decl = dyn_cast<ObjCInterfaceDecl>(to);
to_interface_decl->setExternallyCompleted();
}
return clang::ASTImporter::Imported(from, to);
}

View File

@ -194,7 +194,7 @@ ClangASTType::GetMinimumLanguage (lldb::clang_type_t clang_type)
default:
break;
case clang::Type::Builtin:
switch (cast<clang::BuiltinType>(qual_type)->getKind())
switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
{
default:
case clang::BuiltinType::Void:
@ -238,7 +238,7 @@ ClangASTType::GetMinimumLanguage (lldb::clang_type_t clang_type)
}
break;
case clang::Type::Typedef:
return GetMinimumLanguage(cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
return GetMinimumLanguage(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
}
}
return lldb::eLanguageTypeC;
@ -252,6 +252,9 @@ ClangASTType::GetEncoding (clang_type_t clang_type, uint32_t &count)
switch (qual_type->getTypeClass())
{
case clang::Type::UnaryTransform:
break;
case clang::Type::FunctionNoProto:
case clang::Type::FunctionProto:
break;
@ -269,7 +272,7 @@ ClangASTType::GetEncoding (clang_type_t clang_type, uint32_t &count)
break;
case clang::Type::Builtin:
switch (cast<clang::BuiltinType>(qual_type)->getKind())
switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
{
default: assert(0 && "Unknown builtin type!");
case clang::BuiltinType::Void:
@ -337,7 +340,7 @@ ClangASTType::GetEncoding (clang_type_t clang_type, uint32_t &count)
case clang::Type::Record: break;
case clang::Type::Enum: return lldb::eEncodingSint;
case clang::Type::Typedef:
return GetEncoding(cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), count);
return GetEncoding(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), count);
break;
case clang::Type::DependentSizedArray:
@ -379,6 +382,9 @@ ClangASTType::GetFormat (clang_type_t clang_type)
switch (qual_type->getTypeClass())
{
case clang::Type::UnaryTransform:
break;
case clang::Type::FunctionNoProto:
case clang::Type::FunctionProto:
break;
@ -395,7 +401,7 @@ ClangASTType::GetFormat (clang_type_t clang_type)
break;
case clang::Type::Builtin:
switch (cast<clang::BuiltinType>(qual_type)->getKind())
switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
{
//default: assert(0 && "Unknown builtin type!");
case clang::BuiltinType::UnknownAny:
@ -450,7 +456,7 @@ ClangASTType::GetFormat (clang_type_t clang_type)
case clang::Type::Record: break;
case clang::Type::Enum: return lldb::eFormatEnum;
case clang::Type::Typedef:
return ClangASTType::GetFormat(cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
return ClangASTType::GetFormat(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
case clang::Type::DependentSizedArray:
case clang::Type::DependentSizedExtVector:
@ -538,7 +544,7 @@ ClangASTType::DumpValue
case clang::Type::Record:
if (ClangASTContext::GetCompleteType (ast_context, clang_type))
{
const clang::RecordType *record_type = cast<clang::RecordType>(qual_type.getTypePtr());
const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
const clang::RecordDecl *record_decl = record_type->getDecl();
assert(record_decl);
uint32_t field_bit_offset = 0;
@ -547,7 +553,7 @@ ClangASTType::DumpValue
uint32_t child_idx = 0;
const clang::CXXRecordDecl *cxx_record_decl = dyn_cast<clang::CXXRecordDecl>(record_decl);
const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
if (cxx_record_decl)
{
// We might have base classes to print out first
@ -556,7 +562,7 @@ ClangASTType::DumpValue
base_class != base_class_end;
++base_class)
{
const clang::CXXRecordDecl *base_class_decl = cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
// Skip empty base classes
if (verbose == false && ClangASTContext::RecordHasFields(base_class_decl) == false)
@ -667,7 +673,7 @@ ClangASTType::DumpValue
case clang::Type::Enum:
if (ClangASTContext::GetCompleteType (ast_context, clang_type))
{
const clang::EnumType *enum_type = cast<clang::EnumType>(qual_type.getTypePtr());
const clang::EnumType *enum_type = llvm::cast<clang::EnumType>(qual_type.getTypePtr());
const clang::EnumDecl *enum_decl = enum_type->getDecl();
assert(enum_decl);
clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
@ -689,7 +695,7 @@ ClangASTType::DumpValue
case clang::Type::ConstantArray:
{
const clang::ConstantArrayType *array = cast<clang::ConstantArrayType>(qual_type.getTypePtr());
const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr());
bool is_array_of_characters = false;
clang::QualType element_qual_type = array->getElementType();
@ -759,7 +765,7 @@ ClangASTType::DumpValue
case clang::Type::Typedef:
{
clang::QualType typedef_qual_type = cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType();
clang::QualType typedef_qual_type = llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType();
lldb::Format typedef_format = ClangASTType::GetFormat(typedef_qual_type.getAsOpaquePtr());
std::pair<uint64_t, unsigned> typedef_type_info = ast_context->getTypeInfo(typedef_qual_type);
uint64_t typedef_byte_size = typedef_type_info.first / 8;
@ -844,7 +850,7 @@ ClangASTType::DumpTypeValue
{
case clang::Type::Typedef:
{
clang::QualType typedef_qual_type = cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType();
clang::QualType typedef_qual_type = llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType();
if (format == eFormatDefault)
format = ClangASTType::GetFormat(typedef_qual_type.getAsOpaquePtr());
std::pair<uint64_t, unsigned> typedef_type_info = ast_context->getTypeInfo(typedef_qual_type);
@ -867,7 +873,7 @@ ClangASTType::DumpTypeValue
// its enumeration string value, else just display it as requested.
if ((format == eFormatEnum || format == eFormatDefault) && ClangASTContext::GetCompleteType (ast_context, clang_type))
{
const clang::EnumType *enum_type = cast<clang::EnumType>(qual_type.getTypePtr());
const clang::EnumType *enum_type = llvm::cast<clang::EnumType>(qual_type.getTypePtr());
const clang::EnumDecl *enum_decl = enum_type->getDecl();
assert(enum_decl);
clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
@ -1073,7 +1079,7 @@ bool
ClangASTType::IsDefined (clang_type_t clang_type)
{
clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
const clang::TagType *tag_type = dyn_cast<clang::TagType>(qual_type.getTypePtr());
const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
if (tag_type)
{
clang::TagDecl *tag_decl = tag_type->getDecl();
@ -1083,7 +1089,7 @@ ClangASTType::IsDefined (clang_type_t clang_type)
}
else
{
const clang::ObjCObjectType *objc_class_type = dyn_cast<clang::ObjCObjectType>(qual_type);
const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
if (objc_class_type)
{
clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
@ -1126,7 +1132,7 @@ ClangASTType::DumpTypeDescription (clang::ASTContext *ast_context, clang_type_t
llvm::SmallVector<char, 1024> buf;
llvm::raw_svector_ostream llvm_ostrm (buf);
const clang::TagType *tag_type = dyn_cast<clang::TagType>(qual_type.getTypePtr());
const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
if (tag_type)
{
clang::TagDecl *tag_decl = tag_type->getDecl();
@ -1141,7 +1147,7 @@ ClangASTType::DumpTypeDescription (clang::ASTContext *ast_context, clang_type_t
case clang::Type::ObjCObject:
case clang::Type::ObjCInterface:
{
const clang::ObjCObjectType *objc_class_type = dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
assert (objc_class_type);
if (objc_class_type)
{

View File

@ -17,6 +17,7 @@
#include "lldb/Symbol/SymbolVendor.h"
#include "clang/AST/Type.h"
#include "clang/AST/CanonicalType.h"
#include "llvm/Support/Casting.h"
using namespace lldb;
using namespace lldb_private;
@ -414,7 +415,7 @@ clang_type_t
Function::GetReturnClangType ()
{
clang::QualType clang_type (clang::QualType::getFromOpaquePtr(GetType()->GetClangFullType()));
const clang::FunctionType *function_type = dyn_cast<clang::FunctionType> (clang_type);
const clang::FunctionType *function_type = llvm::dyn_cast<clang::FunctionType> (clang_type);
if (function_type)
return function_type->getResultType().getAsOpaquePtr();
return NULL;
@ -428,7 +429,7 @@ Function::GetArgumentCount ()
if (!clang_type->isFunctionProtoType())
return -1;
const clang::FunctionProtoType *function_proto_type = dyn_cast<clang::FunctionProtoType>(clang_type);
const clang::FunctionProtoType *function_proto_type = llvm::dyn_cast<clang::FunctionProtoType>(clang_type);
if (function_proto_type != NULL)
return function_proto_type->getNumArgs();
@ -439,7 +440,7 @@ clang_type_t
Function::GetArgumentTypeAtIndex (size_t idx)
{
clang::QualType clang_type (clang::QualType::getFromOpaquePtr(GetType()->GetClangFullType()));
const clang::FunctionProtoType *function_proto_type = dyn_cast<clang::FunctionProtoType>(clang_type);
const clang::FunctionProtoType *function_proto_type = llvm::dyn_cast<clang::FunctionProtoType>(clang_type);
if (function_proto_type)
{
unsigned num_args = function_proto_type->getNumArgs();
@ -459,7 +460,7 @@ Function::IsVariadic ()
if (!clang_type->isFunctionProtoType())
return false;
const clang::FunctionProtoType *function_proto_type = dyn_cast<clang::FunctionProtoType>(clang_type);
const clang::FunctionProtoType *function_proto_type = llvm::dyn_cast<clang::FunctionProtoType>(clang_type);
if (function_proto_type)
return function_proto_type->isVariadic();