[Lldb-commits] [lldb] r145799 - in /lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime: AppleObjCRuntimeV2.cpp AppleObjCRuntimeV2.h

Greg Clayton gclayton at apple.com
Sun Dec 4 22:07:35 PST 2011


Author: gclayton
Date: Mon Dec  5 00:07:35 2011
New Revision: 145799

URL: http://llvm.org/viewvc/llvm-project?rev=145799&view=rev
Log:
Fixed the remaining test suite failures after the recent objective C cleanup
and fixes we did. Now that objective C classes are represented by symbols with
their own type, there were a few more places in the objective C code that needed
to be fixed when searching for dynamic types.

Cleaned up the objective C runtime plug-in a bit to not keep having to create
constant strings and make one less memory access when we find an "isa" in the
objective C cache.


Modified:
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp?rev=145799&r1=145798&r2=145799&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Mon Dec  5 00:07:35 2011
@@ -88,9 +88,6 @@
 }                                                                                                 \n\
 ";
 
-const char *AppleObjCRuntimeV2::g_objc_class_symbol_prefix = "OBJC_CLASS_$_";
-const char *AppleObjCRuntimeV2::g_objc_class_data_section_name = "__objc_data";
-
 AppleObjCRuntimeV2::AppleObjCRuntimeV2 (Process *process, 
                                         const ModuleSP &objc_module_sp) : 
     AppleObjCRuntime (process),
@@ -99,11 +96,12 @@
     m_isa_to_name_cache(),
     m_isa_to_parent_cache()
 {
-    m_has_object_getClass = (objc_module_sp->FindFirstSymbolWithNameAndType(ConstString("gdb_object_getClass"), eSymbolTypeCode) != NULL);
+    static const ConstString g_gdb_object_getClass("gdb_object_getClass");
+    m_has_object_getClass = (objc_module_sp->FindFirstSymbolWithNameAndType(g_gdb_object_getClass, eSymbolTypeCode) != NULL);
 }
 
 bool
-AppleObjCRuntimeV2::RunFunctionToFindClassName(lldb::addr_t object_addr, Thread *thread, char *name_dst, size_t max_name_len)
+AppleObjCRuntimeV2::RunFunctionToFindClassName(addr_t object_addr, Thread *thread, char *name_dst, size_t max_name_len)
 {
     // Since we are going to run code we have to make sure only one thread at a time gets to try this.
     Mutex::Locker (m_get_class_name_args_mutex);
@@ -123,7 +121,7 @@
     Value void_ptr_value;
     ClangASTContext *clang_ast_context = m_process->GetTarget().GetScratchClangASTContext();
     
-    lldb::clang_type_t clang_void_ptr_type = clang_ast_context->GetVoidPtrType(false);
+    clang_type_t clang_void_ptr_type = clang_ast_context->GetVoidPtrType(false);
     void_ptr_value.SetValueType (Value::eValueTypeScalar);
     void_ptr_value.SetContext (Value::eContextTypeClangType, clang_void_ptr_type);
     void_ptr_value.GetScalar() = object_addr;
@@ -131,7 +129,7 @@
     dispatch_values.PushValue (void_ptr_value);
     
     Value int_value;
-    lldb::clang_type_t clang_int_type = clang_ast_context->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingSint, 32);
+    clang_type_t clang_int_type = clang_ast_context->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 32);
     int_value.SetValueType (Value::eValueTypeScalar);
     int_value.SetContext (Value::eContextTypeClangType, clang_int_type);
     int_value.GetScalar() = debug;
@@ -221,7 +219,7 @@
         return false;
     }
     
-    lldb::addr_t result_ptr = void_ptr_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
+    addr_t result_ptr = void_ptr_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
     size_t chars_read = m_process->ReadCStringFromMemory (result_ptr, name_dst, max_name_len);
     
     // If we exhausted our buffer before finding a NULL we're probably off in the weeds somewhere...
@@ -234,7 +232,7 @@
 
 bool
 AppleObjCRuntimeV2::GetDynamicTypeAndAddress (ValueObject &in_value, 
-                                              lldb::DynamicValueType use_dynamic, 
+                                              DynamicValueType use_dynamic, 
                                               TypeAndOrName &class_type_or_name, 
                                               Address &address)
 {
@@ -245,53 +243,18 @@
     if (CouldHaveDynamicValue (in_value))
     {
         // First job, pull out the address at 0 offset from the object  That will be the ISA pointer.
-        AddressType address_type;
-        lldb::addr_t original_ptr = in_value.GetPointerValue(&address_type);
-        
-        // ObjC only has single inheritance, so the objects all start at the same pointer value.
-        address.SetSection (NULL);
-        address.SetOffset (original_ptr);
+        Error error;
+        const addr_t object_ptr = in_value.GetPointerValue();
+        const addr_t isa_addr = m_process->ReadPointerFromMemory (object_ptr, error);
 
-        if (original_ptr == LLDB_INVALID_ADDRESS)
+        if (error.Fail())
             return false;
-            
-        Target *target = m_process->CalculateTarget();
 
-        char memory_buffer[16];
-        DataExtractor data (memory_buffer, 
-                            sizeof(memory_buffer), 
-                            m_process->GetByteOrder(), 
-                            m_process->GetAddressByteSize());
+        address.SetSection (NULL);
+        address.SetOffset(object_ptr);
 
-        size_t address_byte_size = m_process->GetAddressByteSize();
-        Error error;
-        size_t bytes_read = m_process->ReadMemory (original_ptr, 
-                                                   memory_buffer, 
-                                                   address_byte_size, 
-                                                   error);
-        if (!error.Success() || (bytes_read != address_byte_size))
-        {
-            return false;
-        }
-        
-        uint32_t offset = 0;
-        lldb::addr_t isa_addr = data.GetAddress (&offset);
-            
-        if (offset == 0)
-            return false;
-            
-        // Make sure the class address is readable, otherwise this is not a good object:
-        bytes_read = m_process->ReadMemory (isa_addr, 
-                                            memory_buffer, 
-                                            address_byte_size, 
-                                            error);
-        if (bytes_read != address_byte_size)
-            return false;
-        
         // First check the cache...
-        
         SymbolContext sc;
-            
         class_type_or_name = LookupInClassNameCache (isa_addr);
         
         if (!class_type_or_name.IsEmpty())
@@ -302,9 +265,17 @@
                 return false;
         }
 
+        // We don't have the object cached, so make sure the class
+        // address is readable, otherwise this is not a good object:
+        m_process->ReadPointerFromMemory (isa_addr, error);
+        
+        if (error.Fail())
+            return false;
+
         const char *class_name = NULL;
         Address isa_address;
-        target->GetSectionLoadList().ResolveLoadAddress (isa_addr, isa_address);
+        Target &target = m_process->GetTarget();
+        target.GetSectionLoadList().ResolveLoadAddress (isa_addr, isa_address);
         
         if (isa_address.IsValid())
         {
@@ -319,14 +290,14 @@
                 // some static class or nothing.  See if it is in the right section 
                 // and if its name is the right form.
                 ConstString section_name = section->GetName();
-                if (section_name == ConstString(g_objc_class_data_section_name))
+                static ConstString g_objc_class_section_name ("__objc_data");
+                if (section_name == g_objc_class_section_name)
                 {
                     isa_address.CalculateSymbolContext(&sc);
                     if (sc.symbol)
                     {
-                        class_name = sc.symbol->GetName().AsCString();
-                        if (strstr (class_name, g_objc_class_symbol_prefix) == class_name)
-                            class_name += strlen (g_objc_class_symbol_prefix);
+                        if (sc.symbol->GetType() == eSymbolTypeObjCClass)
+                            class_name = sc.symbol->GetName().GetCString();
                         else
                             return false;
                     }
@@ -335,7 +306,7 @@
         }
         
         char class_buffer[1024];
-        if (class_name == NULL && use_dynamic != lldb::eDynamicDontRunTarget)
+        if (class_name == NULL && use_dynamic != eDynamicDontRunTarget)
         {
             // If the class address didn't point into the binary, or
             // it points into the right section but there wasn't a symbol
@@ -351,23 +322,23 @@
             if (thread_to_use == NULL)
                 return false;
                 
-            if (!RunFunctionToFindClassName (original_ptr, thread_to_use, class_buffer, 1024))
+            if (!RunFunctionToFindClassName (object_ptr, thread_to_use, class_buffer, 1024))
                 return false;
                 
              class_name = class_buffer;   
             
         }
         
-        if (class_name != NULL && *class_name != '\0')
+        if (class_name && class_name[0])
         {
             class_type_or_name.SetName (class_name);
             
             TypeList class_types;
-            uint32_t num_matches = target->GetImages().FindTypes (sc, 
-                                                                  class_type_or_name.GetName(),
-                                                                  true,
-                                                                  UINT32_MAX,
-                                                                  class_types);
+            uint32_t num_matches = target.GetImages().FindTypes (sc, 
+                                                                 class_type_or_name.GetName(),
+                                                                 true,
+                                                                 UINT32_MAX,
+                                                                 class_types);
             if (num_matches == 1)
             {
                 class_type_or_name.SetTypeSP (class_types.GetTypeAtIndex(0));
@@ -377,7 +348,7 @@
             {
                 for (size_t i  = 0; i < num_matches; i++)
                 {
-                    lldb::TypeSP this_type(class_types.GetTypeAtIndex(i));
+                    TypeSP this_type(class_types.GetTypeAtIndex(i));
                     if (this_type)
                     {
                         if (ClangASTContext::IsObjCClassType(this_type->GetClangFullType()))
@@ -419,7 +390,7 @@
 // Static Functions
 //------------------------------------------------------------------
 LanguageRuntime *
-AppleObjCRuntimeV2::CreateInstance (Process *process, lldb::LanguageType language)
+AppleObjCRuntimeV2::CreateInstance (Process *process, LanguageType language)
 {
     // FIXME: This should be a MacOS or iOS process, and we need to look for the OBJC section to make
     // sure we aren't using the V1 runtime.
@@ -565,9 +536,9 @@
     ConstString ivar_const_str (buffer.c_str());
     
     SymbolContextList sc_list;
-    Target *target = &(m_process->GetTarget());
+    Target &target = m_process->GetTarget();
     
-    target->GetImages().FindSymbolsWithNameAndType(ivar_const_str, eSymbolTypeRuntime, sc_list);
+    target.GetImages().FindSymbolsWithNameAndType(ivar_const_str, eSymbolTypeRuntime, sc_list);
 
     SymbolContext ivar_offset_symbol;
     if (sc_list.GetSize() != 1 
@@ -575,7 +546,7 @@
         || ivar_offset_symbol.symbol == NULL)
         return LLDB_INVALID_IVAR_OFFSET;
     
-    lldb::addr_t ivar_offset_address = ivar_offset_symbol.symbol->GetValue().GetLoadAddress(target);
+    addr_t ivar_offset_address = ivar_offset_symbol.symbol->GetValue().GetLoadAddress (&target);
     
     Error error;
     
@@ -592,7 +563,7 @@
 // is not accurate (it might become better by incorporating further
 // knowledge about the internals of tagged pointers)
 bool
-AppleObjCRuntimeV2::IsTaggedPointer(lldb::addr_t ptr)
+AppleObjCRuntimeV2::IsTaggedPointer(addr_t ptr)
 {
     return (ptr & 0x01);
 }
@@ -604,7 +575,7 @@
 ObjCLanguageRuntime::ObjCISA
 AppleObjCRuntimeV2::GetISA(ValueObject& valobj)
 {
-    if (ClangASTType::GetMinimumLanguage(valobj.GetClangAST(),valobj.GetClangType()) != lldb::eLanguageTypeObjC)
+    if (ClangASTType::GetMinimumLanguage(valobj.GetClangAST(),valobj.GetClangType()) != eLanguageTypeObjC)
         return 0;
     
     // if we get an invalid VO (which might still happen when playing around
@@ -613,7 +584,7 @@
     if (valobj.GetValue().GetContextType() == Value::eContextTypeInvalid)
         return 0;
     
-    lldb::addr_t isa_pointer = valobj.GetPointerValue();
+    addr_t isa_pointer = valobj.GetPointerValue();
     
     // tagged pointer
     if (IsTaggedPointer(isa_pointer))
@@ -635,11 +606,16 @@
 ConstString
 AppleObjCRuntimeV2::GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa)
 {
+    static const ConstString g_unknown ("unknown");
+
     if (!IsValidISA(isa))
-        return ConstString(NULL);
+        return ConstString();
      
     if (isa == g_objc_Tagged_ISA)
-        return ConstString("_lldb_Tagged_ObjC_ISA");
+    {
+        static const ConstString g_objc_tagged_isa_name ("_lldb_Tagged_ObjC_ISA");
+        return g_objc_tagged_isa_name;
+    }
     
     ISAToNameIterator found = m_isa_to_name_cache.find(isa);
     ISAToNameIterator end = m_isa_to_name_cache.end();
@@ -658,14 +634,17 @@
 -->     class_rw_t data;
      */
     
-    lldb::addr_t rw_pointer = isa + (4 * pointer_size);
+    addr_t rw_pointer = isa + (4 * pointer_size);
     //printf("rw_pointer: %llx\n", rw_pointer);
     uint64_t data_pointer =  m_process->ReadUnsignedIntegerFromMemory(rw_pointer,
                                                                       pointer_size,
                                                                       0,
                                                                       error);
     if (error.Fail())
-        return ConstString("unknown");
+    {
+        return g_unknown;
+
+    }
     
     /*
      uint32_t flags;
@@ -680,7 +659,7 @@
                                                                    0,
                                                                    error);
     if (error.Fail())
-        return ConstString("unknown");
+        return g_unknown;
     
     /*
      uint32_t flags;
@@ -704,7 +683,7 @@
                                                                      0,
                                                                      error);
     if (error.Fail())
-        return ConstString("unknown");
+        return g_unknown;
     
     //printf("name_pointer: %llx\n", name_pointer);
     char* cstr = new char[512];
@@ -730,7 +709,7 @@
         }
     }
     else
-        return ConstString("unknown");
+        return g_unknown;
 }
 
 ObjCLanguageRuntime::ObjCISA
@@ -754,7 +733,7 @@
      struct class_t *isa;
 -->     struct class_t *superclass;
      */
-    lldb::addr_t parent_pointer = isa + pointer_size;
+    addr_t parent_pointer = isa + pointer_size;
     //printf("rw_pointer: %llx\n", rw_pointer);
     
     uint64_t parent_isa =  m_process->ReadUnsignedIntegerFromMemory(parent_pointer,

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h?rev=145799&r1=145798&r2=145799&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h Mon Dec  5 00:07:35 2011
@@ -130,8 +130,6 @@
     
     static const char *g_find_class_name_function_name;
     static const char *g_find_class_name_function_body;
-    static const char *g_objc_class_symbol_prefix;
-    static const char *g_objc_class_data_section_name;
 };
     
 } // namespace lldb_private





More information about the lldb-commits mailing list