diff options
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/Expression/ExpressionSourceCode.cpp | 33 | ||||
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp | 68 | ||||
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h | 3 | ||||
-rw-r--r-- | lldb/source/Symbol/ClangASTContext.cpp | 19 | ||||
-rw-r--r-- | lldb/source/Symbol/CompilerDeclContext.cpp | 5 | ||||
-rw-r--r-- | lldb/source/Symbol/TypeSystem.cpp | 4 |
6 files changed, 122 insertions, 10 deletions
diff --git a/lldb/source/Expression/ExpressionSourceCode.cpp b/lldb/source/Expression/ExpressionSourceCode.cpp index 93bac62c43c..13fdaf8dfeb 100644 --- a/lldb/source/Expression/ExpressionSourceCode.cpp +++ b/lldb/source/Expression/ExpressionSourceCode.cpp @@ -16,7 +16,9 @@ #include "lldb/Symbol/DebugMacros.h" #include "lldb/Symbol/Block.h" #include "lldb/Symbol/TypeSystem.h" +#include "lldb/Symbol/VariableList.h" #include "lldb/Target/ExecutionContext.h" +#include "lldb/Target/Language.h" #include "lldb/Target/Platform.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" @@ -175,6 +177,21 @@ AddMacros(const DebugMacros *dm, CompileUnit *comp_unit, AddMacroState &state, S } } +static void +AddLocalVariableDecls(const lldb::VariableListSP &var_list_sp, StreamString &stream) +{ + for (size_t i = 0; i < var_list_sp->GetSize(); i++) + { + lldb::VariableSP var_sp = var_list_sp->GetVariableAtIndex(i); + + ConstString var_name = var_sp->GetName(); + if (var_name == ConstString("this")) + continue; + + stream.Printf("using $__lldb_local_vars::%s;\n", var_name.AsCString()); + } +} + bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrapping_language, bool const_object, bool static_method, ExecutionContext &exe_ctx) const { const char *target_specific_defines = "typedef signed char BOOL;\n"; @@ -239,6 +256,7 @@ bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrappi } StreamString debug_macros_stream; + StreamString lldb_local_var_decls; if (StackFrame *frame = exe_ctx.GetFramePtr()) { const SymbolContext &sc = frame->GetSymbolContext( @@ -253,8 +271,15 @@ bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrappi AddMacros(dm, sc.comp_unit, state, debug_macros_stream); } } + + ConstString object_name; + if (Language::LanguageIsCPlusPlus(frame->GetLanguage())) + { + lldb::VariableListSP var_list_sp = frame->GetInScopeVariableList(false); + AddLocalVariableDecls(var_list_sp, lldb_local_var_decls); + } } - + if (m_wrap) { switch (wrapping_language) @@ -284,19 +309,23 @@ bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrappi wrap_stream.Printf("void \n" "%s(void *$__lldb_arg) \n" "{ \n" + " %s; \n" " %s; \n" "} \n", m_name.c_str(), + lldb_local_var_decls.GetData(), m_body.c_str()); break; case lldb::eLanguageTypeC_plus_plus: wrap_stream.Printf("void \n" "$__lldb_class::%s(void *$__lldb_arg) %s\n" "{ \n" + " %s; \n" " %s; \n" "} \n", m_name.c_str(), (const_object ? "const" : ""), + lldb_local_var_decls.GetData(), m_body.c_str()); break; case lldb::eLanguageTypeObjC: @@ -339,6 +368,6 @@ bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrappi { text.append(m_body); } - + return true; } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp index f4d6b195c7f..6092efa484f 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -57,6 +57,11 @@ using namespace lldb; using namespace lldb_private; using namespace clang; +namespace +{ + const char *g_lldb_local_vars_namespace_cstr = "$__lldb_local_vars"; +} // anonymous namespace + ClangExpressionDeclMap::ClangExpressionDeclMap (bool keep_result_in_memory, Materializer::PersistentVariableDelegate *result_delegate, ExecutionContext &exe_ctx) : @@ -1004,6 +1009,24 @@ ClangExpressionDeclMap::FindGlobalVariable return VariableSP(); } +ClangASTContext * +ClangExpressionDeclMap::GetClangASTContext () +{ + StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr(); + if (frame == nullptr) + return nullptr; + + SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction|lldb::eSymbolContextBlock); + if (sym_ctx.block == nullptr) + return nullptr; + + CompilerDeclContext frame_decl_context = sym_ctx.block->GetDeclContext(); + if (!frame_decl_context) + return nullptr; + + return llvm::dyn_cast_or_null<ClangASTContext>(frame_decl_context.GetTypeSystem()); +} + // Interface for ClangASTSource void @@ -1039,6 +1062,13 @@ ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context) if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context)) { + if (namespace_context->getName().str() == std::string(g_lldb_local_vars_namespace_cstr)) + { + CompilerDeclContext compiler_decl_ctx(GetClangASTContext(), (void*)context.m_decl_context); + FindExternalVisibleDecls(context, lldb::ModuleSP(), compiler_decl_ctx, current_id); + return; + } + ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer_sp->GetNamespaceMap(namespace_context); if (log && log->GetVerbose()) @@ -1335,6 +1365,32 @@ ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context, return; } + if (name == ConstString(g_lldb_local_vars_namespace_cstr)) + { + CompilerDeclContext frame_decl_context = sym_ctx.block != nullptr ? + sym_ctx.block->GetDeclContext() : + CompilerDeclContext(); + + if (frame_decl_context) + { + ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(frame_decl_context.GetTypeSystem()); + + if (ast) + { + clang::NamespaceDecl *namespace_decl = ClangASTContext::GetUniqueNamespaceDeclaration( + m_ast_context, name_unique_cstr, nullptr); + if (namespace_decl) + { + context.AddNamedDecl(namespace_decl); + clang::DeclContext *clang_decl_ctx = clang::Decl::castToDeclContext(namespace_decl); + clang_decl_ctx->setHasExternalVisibleStorage(true); + } + } + } + + return; + } + // any other $__lldb names should be weeded out now if (!::strncmp(name_unique_cstr, "$__lldb", sizeof("$__lldb") - 1)) return; @@ -1403,19 +1459,23 @@ ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context, ValueObjectSP valobj; VariableSP var; - if (frame && !namespace_decl) + bool local_var_lookup = !namespace_decl || + (namespace_decl.GetName() == ConstString(g_lldb_local_vars_namespace_cstr)); + if (frame && local_var_lookup) { CompilerDeclContext compiler_decl_context = sym_ctx.block != nullptr ? sym_ctx.block->GetDeclContext() : CompilerDeclContext(); if (compiler_decl_context) { - // Make sure that the variables are parsed so that we have the declarations + // Make sure that the variables are parsed so that we have the declarations. VariableListSP vars = frame->GetInScopeVariableList(true); for (size_t i = 0; i < vars->GetSize(); i++) vars->GetVariableAtIndex(i)->GetDecl(); - // Search for declarations matching the name - std::vector<CompilerDecl> found_decls = compiler_decl_context.FindDeclByName(name); + // Search for declarations matching the name. Do not include imported decls + // in the search if we are looking for decls in the artificial namespace + // $__lldb_local_vars. + std::vector<CompilerDecl> found_decls = compiler_decl_context.FindDeclByName(name, namespace_decl.IsValid()); bool variable_found = false; for (CompilerDecl decl : found_decls) diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h index b3f890c7acc..35833e87558 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h @@ -707,6 +707,9 @@ private: AddThisType(NameSearchContext &context, TypeFromUser &type, unsigned int current_id); + + ClangASTContext * + GetClangASTContext(); }; } // namespace lldb_private diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp index 0fc1a94876b..f953ddb21e4 100644 --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -1885,6 +1885,17 @@ ClangASTContext::GetUniqueNamespaceDeclaration (const char *name, DeclContext *d return namespace_decl; } +NamespaceDecl * +ClangASTContext::GetUniqueNamespaceDeclaration (clang::ASTContext *ast, + const char *name, + clang::DeclContext *decl_ctx) +{ + ClangASTContext *ast_ctx = ClangASTContext::GetASTContext(ast); + if (ast_ctx == nullptr) + return nullptr; + + return ast_ctx->GetUniqueNamespaceDeclaration(name, decl_ctx); +} clang::BlockDecl * ClangASTContext::CreateBlockDeclaration (clang::DeclContext *ctx) @@ -9781,7 +9792,9 @@ ClangASTContext::DeclGetFunctionArgumentType (void *opaque_decl, size_t idx) //---------------------------------------------------------------------- std::vector<CompilerDecl> -ClangASTContext::DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name) +ClangASTContext::DeclContextFindDeclByName(void *opaque_decl_ctx, + ConstString name, + const bool ignore_using_decls) { std::vector<CompilerDecl> found_decls; if (opaque_decl_ctx) @@ -9805,12 +9818,16 @@ ClangASTContext::DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString na { if (clang::UsingDirectiveDecl *ud = llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) { + if (ignore_using_decls) + continue; clang::DeclContext *from = ud->getCommonAncestor(); if (searched.find(ud->getNominatedNamespace()) == searched.end()) search_queue.insert(std::make_pair(from, ud->getNominatedNamespace())); } else if (clang::UsingDecl *ud = llvm::dyn_cast<clang::UsingDecl>(child)) { + if (ignore_using_decls) + continue; for (clang::UsingShadowDecl *usd : ud->shadows()) { clang::Decl *target = usd->getTargetDecl(); diff --git a/lldb/source/Symbol/CompilerDeclContext.cpp b/lldb/source/Symbol/CompilerDeclContext.cpp index 8bee1b48753..10a70d97f23 100644 --- a/lldb/source/Symbol/CompilerDeclContext.cpp +++ b/lldb/source/Symbol/CompilerDeclContext.cpp @@ -15,10 +15,11 @@ using namespace lldb_private; std::vector<CompilerDecl> -CompilerDeclContext::FindDeclByName (ConstString name) +CompilerDeclContext::FindDeclByName (ConstString name, const bool ignore_using_decls) { if (IsValid()) - return m_type_system->DeclContextFindDeclByName(m_opaque_decl_ctx, name); + return m_type_system->DeclContextFindDeclByName( + m_opaque_decl_ctx, name, ignore_using_decls); else return std::vector<CompilerDecl>(); } diff --git a/lldb/source/Symbol/TypeSystem.cpp b/lldb/source/Symbol/TypeSystem.cpp index 5c2ab5cceab..5b8e935c71d 100644 --- a/lldb/source/Symbol/TypeSystem.cpp +++ b/lldb/source/Symbol/TypeSystem.cpp @@ -153,7 +153,9 @@ TypeSystem::DeclGetFunctionArgumentType (void *opaque_decl, size_t arg_idx) std::vector<CompilerDecl> -TypeSystem::DeclContextFindDeclByName (void *opaque_decl_ctx, ConstString name) +TypeSystem::DeclContextFindDeclByName (void *opaque_decl_ctx, + ConstString name, + bool ignore_imported_decls) { return std::vector<CompilerDecl>(); } |