Author: Raphael Isemann Date: 2019-11-20T15:12:31+01:00 New Revision: e7cc833ddafdca10be4ef1322ab96ffee774045b
URL: https://github.com/llvm/llvm-project/commit/e7cc833ddafdca10be4ef1322ab96ffee774045b DIFF: https://github.com/llvm/llvm-project/commit/e7cc833ddafdca10be4ef1322ab96ffee774045b.diff LOG: [lldb][NFC] Move searching for $__lldb_class into its own function in ClangExpressionDeclMap Added: Modified: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h Removed: ################################################################################ diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp index da106f4f8f44..b95713b44672 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -824,138 +824,151 @@ void ClangExpressionDeclMap::SearchPersistenDecls(NameSearchContext &context, context.AddNamedDecl(parser_named_decl); } -void ClangExpressionDeclMap::FindExternalVisibleDecls( - NameSearchContext &context, lldb::ModuleSP module_sp, - CompilerDeclContext &namespace_decl, unsigned int current_id) { - assert(m_ast_context); +void ClangExpressionDeclMap::LookUpLldbClass(NameSearchContext &context, + unsigned int current_id) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); - SymbolContextList sc_list; - - const ConstString name(context.m_decl_name.getAsString().c_str()); - if (IgnoreName(name, false)) - return; - - // Only look for functions by name out in our symbols if the function doesn't - // start with our phony prefix of '$' - Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr(); StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr(); SymbolContext sym_ctx; if (frame != nullptr) sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction | lldb::eSymbolContextBlock); - // Try the persistent decls, which take precedence over all else. - if (!namespace_decl) - SearchPersistenDecls(context, name, current_id); + if (m_ctx_obj) { + Status status; + lldb::ValueObjectSP ctx_obj_ptr = m_ctx_obj->AddressOf(status); + if (!ctx_obj_ptr || status.Fail()) + return; - if (name.GetCString()[0] == '$' && !namespace_decl) { - static ConstString g_lldb_class_name("$__lldb_class"); + AddThisType(context, TypeFromUser(m_ctx_obj->GetCompilerType()), + current_id); - if (name == g_lldb_class_name) { - if (m_ctx_obj) { - Status status; - lldb::ValueObjectSP ctx_obj_ptr = m_ctx_obj->AddressOf(status); - if (!ctx_obj_ptr || status.Fail()) - return; + m_struct_vars->m_object_pointer_type = + TypeFromUser(ctx_obj_ptr->GetCompilerType()); - AddThisType(context, TypeFromUser(m_ctx_obj->GetCompilerType()), - current_id); + return; + } - m_struct_vars->m_object_pointer_type = - TypeFromUser(ctx_obj_ptr->GetCompilerType()); + // Clang is looking for the type of "this" - return; - } + if (frame == nullptr) + return; - // Clang is looking for the type of "this" + // Find the block that defines the function represented by "sym_ctx" + Block *function_block = sym_ctx.GetFunctionBlock(); - if (frame == nullptr) - return; + if (!function_block) + return; - // Find the block that defines the function represented by "sym_ctx" - Block *function_block = sym_ctx.GetFunctionBlock(); + CompilerDeclContext function_decl_ctx = function_block->GetDeclContext(); - if (!function_block) - return; + if (!function_decl_ctx) + return; - CompilerDeclContext function_decl_ctx = function_block->GetDeclContext(); + clang::CXXMethodDecl *method_decl = + ClangASTContext::DeclContextGetAsCXXMethodDecl(function_decl_ctx); - if (!function_decl_ctx) - return; + if (method_decl) { + clang::CXXRecordDecl *class_decl = method_decl->getParent(); - clang::CXXMethodDecl *method_decl = - ClangASTContext::DeclContextGetAsCXXMethodDecl(function_decl_ctx); + QualType class_qual_type(class_decl->getTypeForDecl(), 0); - if (method_decl) { - clang::CXXRecordDecl *class_decl = method_decl->getParent(); + TypeFromUser class_user_type( + class_qual_type.getAsOpaquePtr(), + ClangASTContext::GetASTContext(&class_decl->getASTContext())); - QualType class_qual_type(class_decl->getTypeForDecl(), 0); + if (log) { + ASTDumper ast_dumper(class_qual_type); + LLDB_LOGF(log, " CEDM::FEVD[%u] Adding type for $__lldb_class: %s", + current_id, ast_dumper.GetCString()); + } - TypeFromUser class_user_type( - class_qual_type.getAsOpaquePtr(), - ClangASTContext::GetASTContext(&class_decl->getASTContext())); + AddThisType(context, class_user_type, current_id); - if (log) { - ASTDumper ast_dumper(class_qual_type); - LLDB_LOGF(log, " CEDM::FEVD[%u] Adding type for $__lldb_class: %s", - current_id, ast_dumper.GetCString()); - } + if (method_decl->isInstance()) { + // self is a pointer to the object - AddThisType(context, class_user_type, current_id); + QualType class_pointer_type = + method_decl->getASTContext().getPointerType(class_qual_type); - if (method_decl->isInstance()) { - // self is a pointer to the object + TypeFromUser self_user_type( + class_pointer_type.getAsOpaquePtr(), + ClangASTContext::GetASTContext(&method_decl->getASTContext())); - QualType class_pointer_type = - method_decl->getASTContext().getPointerType(class_qual_type); + m_struct_vars->m_object_pointer_type = self_user_type; + } + return; + } - TypeFromUser self_user_type( - class_pointer_type.getAsOpaquePtr(), - ClangASTContext::GetASTContext(&method_decl->getASTContext())); + // This branch will get hit if we are executing code in the context of + // a function that claims to have an object pointer (through + // DW_AT_object_pointer?) but is not formally a method of the class. + // In that case, just look up the "this" variable in the current scope + // and use its type. + // FIXME: This code is formally correct, but clang doesn't currently + // emit DW_AT_object_pointer + // for C++ so it hasn't actually been tested. - m_struct_vars->m_object_pointer_type = self_user_type; - } - } else { - // This branch will get hit if we are executing code in the context of - // a function that claims to have an object pointer (through - // DW_AT_object_pointer?) but is not formally a method of the class. - // In that case, just look up the "this" variable in the current scope - // and use its type. - // FIXME: This code is formally correct, but clang doesn't currently - // emit DW_AT_object_pointer - // for C++ so it hasn't actually been tested. + VariableList *vars = frame->GetVariableList(false); - VariableList *vars = frame->GetVariableList(false); + lldb::VariableSP this_var = vars->FindVariable(ConstString("this")); - lldb::VariableSP this_var = vars->FindVariable(ConstString("this")); + if (this_var && this_var->IsInScope(frame) && + this_var->LocationIsValidForFrame(frame)) { + Type *this_type = this_var->GetType(); - if (this_var && this_var->IsInScope(frame) && - this_var->LocationIsValidForFrame(frame)) { - Type *this_type = this_var->GetType(); + if (!this_type) + return; - if (!this_type) - return; + TypeFromUser pointee_type = + this_type->GetForwardCompilerType().GetPointeeType(); - TypeFromUser pointee_type = - this_type->GetForwardCompilerType().GetPointeeType(); + if (pointee_type.IsValid()) { + if (log) { + ASTDumper ast_dumper(pointee_type); + LLDB_LOGF(log, " FEVD[%u] Adding type for $__lldb_class: %s", + current_id, ast_dumper.GetCString()); + } - if (pointee_type.IsValid()) { - if (log) { - ASTDumper ast_dumper(pointee_type); - LLDB_LOGF(log, " FEVD[%u] Adding type for $__lldb_class: %s", - current_id, ast_dumper.GetCString()); - } + AddThisType(context, pointee_type, current_id); + TypeFromUser this_user_type(this_type->GetFullCompilerType()); + m_struct_vars->m_object_pointer_type = this_user_type; + } + } +} - AddThisType(context, pointee_type, current_id); - TypeFromUser this_user_type(this_type->GetFullCompilerType()); - m_struct_vars->m_object_pointer_type = this_user_type; - return; - } - } - } +void ClangExpressionDeclMap::FindExternalVisibleDecls( + NameSearchContext &context, lldb::ModuleSP module_sp, + CompilerDeclContext &namespace_decl, unsigned int current_id) { + assert(m_ast_context); + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + + SymbolContextList sc_list; + + const ConstString name(context.m_decl_name.getAsString().c_str()); + if (IgnoreName(name, false)) + return; + // Only look for functions by name out in our symbols if the function doesn't + // start with our phony prefix of '$' + Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr(); + StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr(); + SymbolContext sym_ctx; + if (frame != nullptr) + sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction | + lldb::eSymbolContextBlock); + + // Try the persistent decls, which take precedence over all else. + if (!namespace_decl) + SearchPersistenDecls(context, name, current_id); + + if (name.GetCString()[0] == '$' && !namespace_decl) { + static ConstString g_lldb_class_name("$__lldb_class"); + + if (name == g_lldb_class_name) { + LookUpLldbClass(context, current_id); return; } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h index 4b80248ceac5..2d7b3712ad53 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h @@ -390,6 +390,16 @@ class ClangExpressionDeclMap : public ClangASTSource { void SearchPersistenDecls(NameSearchContext &context, const ConstString name, unsigned int current_id); + /// Handles looking up $__lldb_class which requires special treatment. + /// + /// \param[in] context + /// The NameSearchContext that can construct Decls for this name. + /// + /// \param[in] current_id + /// The ID for the current FindExternalVisibleDecls invocation, + /// for logging purposes. + void LookUpLldbClass(NameSearchContext &context, unsigned int current_id); + /// Given a target, find a variable that matches the given name and type. /// /// \param[in] target _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits