[Lldb-commits] [lldb] r154067 - in /lldb/trunk: include/lldb/Symbol/ClangASTContext.h source/Expression/ClangASTSource.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h source/Symbol/ClangASTContext.cpp

Sean Callanan scallanan at apple.com
Wed Apr 4 17:12:53 PDT 2012


Author: spyffe
Date: Wed Apr  4 19:12:52 2012
New Revision: 154067

URL: http://llvm.org/viewvc/llvm-project?rev=154067&view=rev
Log:
Fixed a problem where we did not read properties
correctly if the setter/getter were not present
in the debug information.  The fixes are as follows:

- We not only look for the method by its full name,
  but also look for automatically-generated methods
  when searching for a selector in an Objective-C
  interface.  This is necessary to find accessors.

- Extract the getter and setter name from the
  DW_TAG_APPLE_Property declaration in the DWARF
  if they are present; generate them if not.

Modified:
    lldb/trunk/include/lldb/Symbol/ClangASTContext.h
    lldb/trunk/source/Expression/ClangASTSource.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
    lldb/trunk/source/Symbol/ClangASTContext.cpp

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=154067&r1=154066&r2=154067&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Wed Apr  4 19:12:52 2012
@@ -195,6 +195,12 @@
 
     lldb::clang_type_t
     GetCStringType(bool is_const);
+    
+    lldb::clang_type_t
+    GetVoidType();
+    
+    lldb::clang_type_t
+    GetVoidType(clang::ASTContext *ast);
 
     lldb::clang_type_t
     GetVoidPtrType(bool is_const);

Modified: lldb/trunk/source/Expression/ClangASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangASTSource.cpp?rev=154067&r1=154066&r2=154067&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangASTSource.cpp (original)
+++ lldb/trunk/source/Expression/ClangASTSource.cpp Wed Apr  4 19:12:52 2012
@@ -648,6 +648,86 @@
     if (!interface_decl)
         return;
     
+    do
+    {
+        Decl *original_decl = NULL;
+        ASTContext *original_ctx = NULL;
+        
+        m_ast_importer->ResolveDeclOrigin(interface_decl, &original_decl, &original_ctx);
+        
+        if (!original_decl)
+            break;
+            
+        ObjCInterfaceDecl *original_interface_decl = dyn_cast<ObjCInterfaceDecl>(original_decl);
+        
+        Selector original_selector;
+                
+        if (decl_name.isObjCZeroArgSelector())
+        {
+            IdentifierInfo *ident = &original_ctx->Idents.get(decl_name.getAsString());
+            original_selector = original_ctx->Selectors.getSelector(0, &ident);
+        }
+        else if (decl_name.isObjCOneArgSelector())
+        {
+            const std::string &decl_name_string = decl_name.getAsString();
+            std::string decl_name_string_without_colon(decl_name_string.c_str(), decl_name_string.length() - 1);
+            IdentifierInfo *ident = &original_ctx->Idents.get(decl_name_string_without_colon.c_str());
+            original_selector = original_ctx->Selectors.getSelector(1, &ident);
+        }
+        else
+        {
+            SmallVector<IdentifierInfo *, 4> idents;
+            
+            clang::Selector sel = decl_name.getObjCSelector();
+            
+            int num_args = sel.getNumArgs();
+            
+            for (unsigned i = 0;
+                 i != num_args;
+                 ++i)
+            {
+                idents.push_back(&original_ctx->Idents.get(sel.getNameForSlot(i)));
+            }
+            
+            original_selector = original_ctx->Selectors.getSelector(num_args, idents.data());
+        }
+        
+        DeclarationName original_decl_name(original_selector);
+                
+        ObjCInterfaceDecl::lookup_result result = original_interface_decl->lookup(original_decl_name);
+        
+        if (result.first == result.second)
+            break;
+        
+        if (!*result.first)
+            break;
+        
+        ObjCMethodDecl *result_method = dyn_cast<ObjCMethodDecl>(*result.first);
+        
+        if (!result_method)
+            break;
+        
+        Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &result_method->getASTContext(), result_method);
+        
+        if (!copied_decl)
+            continue;
+        
+        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 debug info) %s", current_id, dumper.GetCString());
+        }
+        
+        context.AddNamedDecl(copied_method_decl);
+        
+        return;
+    } while (0);
+    
     StreamString ss;
         
     if (decl_name.isObjCZeroArgSelector())

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=154067&r1=154066&r2=154067&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Wed Apr  4 19:12:52 2012
@@ -1565,28 +1565,53 @@
                             }
                         }
                     }
-                    
-                    ConstString fixed_getter;
-                    ConstString fixed_setter;
-                    
-                    if (prop_getter_name && prop_getter_name[0] == '-')
-                    {
-                        ObjCLanguageRuntime::ParseMethodName (prop_getter_name,
-                                                              NULL,
-                                                              &fixed_getter,
-                                                              NULL,
-                                                              NULL);
-                        prop_getter_name = fixed_getter.GetCString();
-                    }
-                    
-                    if (prop_setter_name && prop_setter_name[0] == '-')
+                                        
+                    if (prop_name)
                     {
-                        ObjCLanguageRuntime::ParseMethodName (prop_setter_name,
-                                                              NULL,
-                                                              &fixed_setter,
-                                                              NULL,
-                                                              NULL);
-                        prop_setter_name = fixed_setter.GetCString();
+                        ConstString fixed_getter;
+                        ConstString fixed_setter;
+
+                        // Check if the property getter/setter were provided as full
+                        // names.  We want basenames, so we extract them.
+                        
+                        if (prop_getter_name && prop_getter_name[0] == '-')
+                        {
+                            ObjCLanguageRuntime::ParseMethodName (prop_getter_name,
+                                                                  NULL,
+                                                                  &fixed_getter,
+                                                                  NULL,
+                                                                  NULL);
+                            prop_getter_name = fixed_getter.GetCString();
+                        }
+                        
+                        if (prop_setter_name && prop_setter_name[0] == '-')
+                        {
+                            ObjCLanguageRuntime::ParseMethodName (prop_setter_name,
+                                                                  NULL,
+                                                                  &fixed_setter,
+                                                                  NULL,
+                                                                  NULL);
+                            prop_setter_name = fixed_setter.GetCString();
+                        }
+                        
+                        // If the names haven't been provided, they need to be
+                        // filled in.
+                        
+                        if (!prop_getter_name)
+                        {
+                            prop_getter_name = prop_name;
+                        }
+                        if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
+                        {
+                            StreamString ss;
+                            
+                            ss.Printf("set%c%s:",
+                                      toupper(prop_name[0]),
+                                      &prop_name[1]);
+                            
+                            fixed_setter.SetCString(ss.GetData());
+                            prop_setter_name = fixed_setter.GetCString();
+                        }
                     }
                     
                     // Clang has a DWARF generation bug where sometimes it

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=154067&r1=154066&r2=154067&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Wed Apr  4 19:12:52 2012
@@ -512,6 +512,11 @@
     bool
     DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
                           DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2);
+    
+    bool
+    ClassContainsSelector (DWARFCompileUnit *dwarf_cu,
+                           const DWARFDebugInfoEntry *class_die,
+                           const lldb_private::ConstString &selector);
 
     SymbolFileDWARFDebugMap *       m_debug_map_symfile;
     clang::TranslationUnitDecl *    m_clang_tu_decl;

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=154067&r1=154066&r2=154067&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Wed Apr  4 19:12:52 2012
@@ -973,6 +973,18 @@
 }
 
 clang_type_t
+ClangASTContext::GetVoidType()
+{
+    return GetVoidType(getASTContext());
+}
+
+clang_type_t
+ClangASTContext::GetVoidType(ASTContext *ast)
+{
+    return ast->VoidTy.getAsOpaquePtr();
+}
+
+clang_type_t
 ClangASTContext::GetVoidPtrType (bool is_const)
 {
     return GetVoidPtrType(getASTContext(), is_const);
@@ -2424,8 +2436,6 @@
                         std::string property_setter_no_colon(property_setter_name, strlen(property_setter_name) - 1);
                         clang::IdentifierInfo *setter_ident = &identifier_table->get(property_setter_no_colon.c_str());
                         setter_sel = ast->Selectors.getSelector(1, &setter_ident);
-                        property_decl->setSetterName(setter_sel);
-                        property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_setter);
                     }
                     else if (!(property_attributes & DW_APPLE_PROPERTY_readonly))
                     {
@@ -2435,19 +2445,21 @@
                         clang::IdentifierInfo *setter_ident = &identifier_table->get(setter_sel_string.c_str());
                         setter_sel = ast->Selectors.getSelector(1, &setter_ident);
                     }
+                    property_decl->setSetterName(setter_sel);
+                    property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_setter);
                     
                     if (property_getter_name != NULL)
                     {
                         clang::IdentifierInfo *getter_ident = &identifier_table->get(property_getter_name);
                         getter_sel = ast->Selectors.getSelector(0, &getter_ident);
-                        property_decl->setGetterName(getter_sel);
-                        property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_getter);
                     }
                     else
                     {
                         clang::IdentifierInfo *getter_ident = &identifier_table->get(property_name);
                         getter_sel = ast->Selectors.getSelector(0, &getter_ident);
                     }
+                    property_decl->setGetterName(getter_sel);
+                    property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_getter);
                         
                     if (ivar_decl)
                         property_decl->setPropertyIvarDecl (ivar_decl);





More information about the lldb-commits mailing list