[Lldb-commits] [lldb] 51ad025 - [lldb][NFC] Move searching for $__lldb_objc_class into its own function

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 20 07:11:08 PST 2019


Author: Raphael Isemann
Date: 2019-11-20T16:10:24+01:00
New Revision: 51ad025ff313804674b4fb01f56f7b83e3ecc5e3

URL: https://github.com/llvm/llvm-project/commit/51ad025ff313804674b4fb01f56f7b83e3ecc5e3
DIFF: https://github.com/llvm/llvm-project/commit/51ad025ff313804674b4fb01f56f7b83e3ecc5e3.diff

LOG: [lldb][NFC] Move searching for $__lldb_objc_class into its own function

Same as in commit e7cc833ddafdca10be4ef1322ab96ffee774045b but with $__lldb_objc_class.

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 b95713b44672..7b8456257c62 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -938,178 +938,180 @@ void ClangExpressionDeclMap::LookUpLldbClass(NameSearchContext &context,
   }
 }
 
-void ClangExpressionDeclMap::FindExternalVisibleDecls(
-    NameSearchContext &context, lldb::ModuleSP module_sp,
-    CompilerDeclContext &namespace_decl, unsigned int current_id) {
-  assert(m_ast_context);
-
+void ClangExpressionDeclMap::LookUpLldbObjCClass(NameSearchContext &context,
+                                                 unsigned int current_id) {
   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-  SymbolContextList sc_list;
+  StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
 
-  const ConstString name(context.m_decl_name.getAsString().c_str());
-  if (IgnoreName(name, false))
-    return;
+  if (m_ctx_obj) {
+    Status status;
+    lldb::ValueObjectSP ctx_obj_ptr = m_ctx_obj->AddressOf(status);
+    if (!ctx_obj_ptr || status.Fail())
+      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);
+    AddOneType(context, TypeFromUser(m_ctx_obj->GetCompilerType()), current_id);
 
-  // Try the persistent decls, which take precedence over all else.
-  if (!namespace_decl)
-    SearchPersistenDecls(context, name, current_id);
+    m_struct_vars->m_object_pointer_type =
+        TypeFromUser(ctx_obj_ptr->GetCompilerType());
 
-  if (name.GetCString()[0] == '$' && !namespace_decl) {
-    static ConstString g_lldb_class_name("$__lldb_class");
+    return;
+  }
 
-    if (name == g_lldb_class_name) {
-      LookUpLldbClass(context, current_id);
-      return;
-    }
+  // Clang is looking for the type of "*self"
 
-    static ConstString g_lldb_objc_class_name("$__lldb_objc_class");
-    if (name == g_lldb_objc_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;
+  if (!frame)
+    return;
+
+  SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction |
+                                                  lldb::eSymbolContextBlock);
 
-        AddOneType(context, TypeFromUser(m_ctx_obj->GetCompilerType()),
-                   current_id);
+  // Find the block that defines the function represented by "sym_ctx"
+  Block *function_block = sym_ctx.GetFunctionBlock();
 
-        m_struct_vars->m_object_pointer_type =
-            TypeFromUser(ctx_obj_ptr->GetCompilerType());
+  if (!function_block)
+    return;
 
-        return;
-      }
+  CompilerDeclContext function_decl_ctx = function_block->GetDeclContext();
 
-      // Clang is looking for the type of "*self"
+  if (!function_decl_ctx)
+    return;
 
-      if (!frame)
-        return;
+  clang::ObjCMethodDecl *method_decl =
+      ClangASTContext::DeclContextGetAsObjCMethodDecl(function_decl_ctx);
 
-      SymbolContext sym_ctx = frame->GetSymbolContext(
-          lldb::eSymbolContextFunction | lldb::eSymbolContextBlock);
+  if (method_decl) {
+    ObjCInterfaceDecl *self_interface = method_decl->getClassInterface();
 
-      // Find the block that defines the function represented by "sym_ctx"
-      Block *function_block = sym_ctx.GetFunctionBlock();
+    if (!self_interface)
+      return;
 
-      if (!function_block)
-        return;
+    const clang::Type *interface_type = self_interface->getTypeForDecl();
 
-      CompilerDeclContext function_decl_ctx = function_block->GetDeclContext();
+    if (!interface_type)
+      return; // This is unlikely, but we have seen crashes where this
+              // occurred
 
-      if (!function_decl_ctx)
-        return;
+    TypeFromUser class_user_type(
+        QualType(interface_type, 0).getAsOpaquePtr(),
+        ClangASTContext::GetASTContext(&method_decl->getASTContext()));
+
+    if (log) {
+      ASTDumper ast_dumper(interface_type);
+      LLDB_LOGF(log, "  FEVD[%u] Adding type for $__lldb_objc_class: %s",
+                current_id, ast_dumper.GetCString());
+    }
 
-      clang::ObjCMethodDecl *method_decl =
-          ClangASTContext::DeclContextGetAsObjCMethodDecl(function_decl_ctx);
+    AddOneType(context, class_user_type, current_id);
 
-      if (method_decl) {
-        ObjCInterfaceDecl *self_interface = method_decl->getClassInterface();
+    if (method_decl->isInstanceMethod()) {
+      // self is a pointer to the object
 
-        if (!self_interface)
-          return;
+      QualType class_pointer_type =
+          method_decl->getASTContext().getObjCObjectPointerType(
+              QualType(interface_type, 0));
 
-        const clang::Type *interface_type = self_interface->getTypeForDecl();
+      TypeFromUser self_user_type(
+          class_pointer_type.getAsOpaquePtr(),
+          ClangASTContext::GetASTContext(&method_decl->getASTContext()));
 
-        if (!interface_type)
-          return; // This is unlikely, but we have seen crashes where this
-                  // occurred
+      m_struct_vars->m_object_pointer_type = self_user_type;
+    } else {
+      // self is a Class pointer
+      QualType class_type = method_decl->getASTContext().getObjCClassType();
 
-        TypeFromUser class_user_type(
-            QualType(interface_type, 0).getAsOpaquePtr(),
-            ClangASTContext::GetASTContext(&method_decl->getASTContext()));
+      TypeFromUser self_user_type(
+          class_type.getAsOpaquePtr(),
+          ClangASTContext::GetASTContext(&method_decl->getASTContext()));
 
-        if (log) {
-          ASTDumper ast_dumper(interface_type);
-          LLDB_LOGF(log, "  FEVD[%u] Adding type for $__lldb_objc_class: %s",
-                    current_id, ast_dumper.GetCString());
-        }
+      m_struct_vars->m_object_pointer_type = self_user_type;
+    }
 
-        AddOneType(context, class_user_type, current_id);
+    return;
+  }
+  // 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 "self" variable in the current scope
+  // and use its type.
 
-        if (method_decl->isInstanceMethod()) {
-          // self is a pointer to the object
+  VariableList *vars = frame->GetVariableList(false);
 
-          QualType class_pointer_type =
-              method_decl->getASTContext().getObjCObjectPointerType(
-                  QualType(interface_type, 0));
+  lldb::VariableSP self_var = vars->FindVariable(ConstString("self"));
 
-          TypeFromUser self_user_type(
-              class_pointer_type.getAsOpaquePtr(),
-              ClangASTContext::GetASTContext(&method_decl->getASTContext()));
+  if (self_var && self_var->IsInScope(frame) &&
+      self_var->LocationIsValidForFrame(frame)) {
+    Type *self_type = self_var->GetType();
 
-          m_struct_vars->m_object_pointer_type = self_user_type;
-        } else {
-          // self is a Class pointer
-          QualType class_type = method_decl->getASTContext().getObjCClassType();
+    if (!self_type)
+      return;
 
-          TypeFromUser self_user_type(
-              class_type.getAsOpaquePtr(),
-              ClangASTContext::GetASTContext(&method_decl->getASTContext()));
+    CompilerType self_clang_type = self_type->GetFullCompilerType();
 
-          m_struct_vars->m_object_pointer_type = self_user_type;
-        }
+    if (ClangASTContext::IsObjCClassType(self_clang_type)) {
+      return;
+    } else if (ClangASTContext::IsObjCObjectPointerType(self_clang_type)) {
+      self_clang_type = self_clang_type.GetPointeeType();
 
+      if (!self_clang_type)
         return;
-      } 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 "self" variable in the current scope
-        // and use its type.
 
-        VariableList *vars = frame->GetVariableList(false);
+      if (log) {
+        ASTDumper ast_dumper(self_type->GetFullCompilerType());
+        LLDB_LOGF(log, "  FEVD[%u] Adding type for $__lldb_objc_class: %s",
+                  current_id, ast_dumper.GetCString());
+      }
 
-        lldb::VariableSP self_var = vars->FindVariable(ConstString("self"));
+      TypeFromUser class_user_type(self_clang_type);
 
-        if (self_var && self_var->IsInScope(frame) &&
-            self_var->LocationIsValidForFrame(frame)) {
-          Type *self_type = self_var->GetType();
+      AddOneType(context, class_user_type, current_id);
 
-          if (!self_type)
-            return;
+      TypeFromUser self_user_type(self_type->GetFullCompilerType());
 
-          CompilerType self_clang_type = self_type->GetFullCompilerType();
+      m_struct_vars->m_object_pointer_type = self_user_type;
+    }
+  }
+}
 
-          if (ClangASTContext::IsObjCClassType(self_clang_type)) {
-            return;
-          } else if (ClangASTContext::IsObjCObjectPointerType(
-                         self_clang_type)) {
-            self_clang_type = self_clang_type.GetPointeeType();
+void ClangExpressionDeclMap::FindExternalVisibleDecls(
+    NameSearchContext &context, lldb::ModuleSP module_sp,
+    CompilerDeclContext &namespace_decl, unsigned int current_id) {
+  assert(m_ast_context);
 
-            if (!self_clang_type)
-              return;
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
-            if (log) {
-              ASTDumper ast_dumper(self_type->GetFullCompilerType());
-              LLDB_LOGF(log,
-                        "  FEVD[%u] Adding type for $__lldb_objc_class: %s",
-                        current_id, ast_dumper.GetCString());
-            }
+  SymbolContextList sc_list;
 
-            TypeFromUser class_user_type(self_clang_type);
+  const ConstString name(context.m_decl_name.getAsString().c_str());
+  if (IgnoreName(name, false))
+    return;
 
-            AddOneType(context, class_user_type, current_id);
+  // 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);
 
-            TypeFromUser self_user_type(self_type->GetFullCompilerType());
+  // Try the persistent decls, which take precedence over all else.
+  if (!namespace_decl)
+    SearchPersistenDecls(context, name, current_id);
 
-            m_struct_vars->m_object_pointer_type = self_user_type;
-            return;
-          }
-        }
-      }
+  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;
     }
 
+    static ConstString g_lldb_objc_class_name("$__lldb_objc_class");
+    if (name == g_lldb_objc_class_name) {
+      LookUpLldbObjCClass(context, current_id);
+      return;
+    }
     if (name == ConstString(g_lldb_local_vars_namespace_cstr)) {
       CompilerDeclContext frame_decl_context =
           sym_ctx.block != nullptr ? sym_ctx.block->GetDeclContext()

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
index 2d7b3712ad53..93342dace77e 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
@@ -400,6 +400,16 @@ class ClangExpressionDeclMap : public ClangASTSource {
   ///     for logging purposes.
   void LookUpLldbClass(NameSearchContext &context, unsigned int current_id);
 
+  /// Handles looking up $__lldb_objc_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 LookUpLldbObjCClass(NameSearchContext &context, unsigned int current_id);
+
   /// Given a target, find a variable that matches the given name and type.
   ///
   /// \param[in] target


        


More information about the lldb-commits mailing list