[Lldb-commits] [lldb] r178897 - <rdar://problem/13563628>

Enrico Granata egranata at apple.com
Fri Apr 5 11:49:07 PDT 2013


Author: enrico
Date: Fri Apr  5 13:49:06 2013
New Revision: 178897

URL: http://llvm.org/viewvc/llvm-project?rev=178897&view=rev
Log:
<rdar://problem/13563628>

Introducing a negative cache for ObjCLanguageRuntime::LookupInCompleteClassCache()
This helps speed up the (common) case of us looking for classes that are hidden deep within Cocoa internals and repeatedly failing at finding type information for them.
In order for this to work, we need to clean this cache whenever debug information is added. A new symbols loaded event is added that is triggered with add-dsym (before modules loaded would be triggered for both adding modules and adding symbols).
Interested parties can register for this event. Internally, we make sure to clean the negative cache whenever symbols are added.
Lastly, ClassDescriptor::IsTagged() has been refactored to GetTaggedPointerInfo() that also (optionally) returns info and value bits. In this way, data formatters can share tagged pointer code instead of duplicating the required arithmetic.

Modified:
    lldb/trunk/include/lldb/API/SBTarget.h
    lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/scripts/Python/interface/SBTarget.i
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/DataFormatters/Cocoa.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
    lldb/trunk/source/Target/ObjCLanguageRuntime.cpp
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=178897&r1=178896&r2=178897&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Fri Apr  5 13:49:06 2013
@@ -237,7 +237,8 @@ public:
         eBroadcastBitBreakpointChanged  = (1 << 0),
         eBroadcastBitModulesLoaded      = (1 << 1),
         eBroadcastBitModulesUnloaded    = (1 << 2),
-        eBroadcastBitWatchpointChanged  = (1 << 3)
+        eBroadcastBitWatchpointChanged  = (1 << 3),
+        eBroadcastBitSymbolsLoaded      = (1 << 4)
     };
 
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h?rev=178897&r1=178896&r2=178897&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h (original)
+++ lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h Fri Apr  5 13:49:06 2013
@@ -14,6 +14,7 @@
 // C++ Includes
 #include <functional>
 #include <map>
+#include <unordered_set>
 
 // Other libraries and framework includes
 // Project includes
@@ -197,7 +198,8 @@ public:
         IsValid () = 0;
         
         virtual bool
-        IsTagged () = 0;
+        GetTaggedPointerInfo (uint64_t* info_bits = NULL,
+                              uint64_t* value_bits = NULL) = 0;
         
         virtual uint64_t
         GetInstanceSize () = 0;
@@ -463,6 +465,12 @@ public:
         return (m_has_new_literals_and_indexing == eLazyBoolYes);
     }
     
+    virtual void
+    SymbolsDidLoad (const ModuleList& module_list)
+    {
+        m_negative_complete_class_cache.clear();
+    }
+    
 protected:
     //------------------------------------------------------------------
     // Classes that inherit from ObjCLanguageRuntime can see and modify these
@@ -567,10 +575,23 @@ private:
 
 protected:
     uint32_t m_isa_to_descriptor_stop_id;
+
     typedef std::map<ConstString, lldb::TypeWP> CompleteClassMap;
     CompleteClassMap m_complete_class_cache;
-
     
+    struct ConstStringSetHelpers {
+        size_t operator () (const ConstString& arg) const // for hashing
+        {
+            return (size_t)arg.GetCString();
+        }
+        bool operator () (const ConstString& arg1, const ConstString& arg2) const // for equality
+        {
+            return arg1.operator==(arg2);
+        }
+    };
+    typedef std::unordered_set<ConstString, ConstStringSetHelpers, ConstStringSetHelpers> CompleteClassSet;
+    CompleteClassSet m_negative_complete_class_cache;
+
     ISAToDescriptorIterator
     GetDescriptorIterator (const ConstString &name);
 

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=178897&r1=178896&r2=178897&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Fri Apr  5 13:49:06 2013
@@ -302,7 +302,8 @@ public:
         eBroadcastBitBreakpointChanged  = (1 << 0),
         eBroadcastBitModulesLoaded      = (1 << 1),
         eBroadcastBitModulesUnloaded    = (1 << 2),
-        eBroadcastBitWatchpointChanged  = (1 << 3)
+        eBroadcastBitWatchpointChanged  = (1 << 3),
+        eBroadcastBitSymbolsLoaded      = (1 << 4)
     };
     
     // These two functions fill out the Broadcaster interface:
@@ -667,6 +668,9 @@ public:
     void
     ModulesDidUnload (ModuleList &module_list);
     
+    void
+    SymbolsDidLoad (ModuleList &module_list);
+    
     //------------------------------------------------------------------
     /// Gets the module for the main executable.
     ///

Modified: lldb/trunk/scripts/Python/interface/SBTarget.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBTarget.i?rev=178897&r1=178896&r2=178897&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBTarget.i (original)
+++ lldb/trunk/scripts/Python/interface/SBTarget.i Fri Apr  5 13:49:06 2013
@@ -239,7 +239,8 @@ public:
         eBroadcastBitBreakpointChanged  = (1 << 0),
         eBroadcastBitModulesLoaded      = (1 << 1),
         eBroadcastBitModulesUnloaded    = (1 << 2),
-        eBroadcastBitWatchpointChanged  = (1 << 3)
+        eBroadcastBitWatchpointChanged  = (1 << 3),
+        eBroadcastBitSymbolsLoaded      = (1 << 4)
     };
 
     //------------------------------------------------------------------

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=178897&r1=178896&r2=178897&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Fri Apr  5 13:49:06 2013
@@ -4320,7 +4320,7 @@ protected:
                             // if it is currently loaded
                             ModuleList module_list;
                             module_list.Append (module_sp);
-                            target->ModulesDidLoad (module_list);
+                            target->SymbolsDidLoad (module_list);
                             
                             // Make sure we load any scripting resources that may be embedded
                             // in the debug info files in case the platform supports that.

Modified: lldb/trunk/source/DataFormatters/Cocoa.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/Cocoa.cpp?rev=178897&r1=178896&r2=178897&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/Cocoa.cpp (original)
+++ lldb/trunk/source/DataFormatters/Cocoa.cpp Fri Apr  5 13:49:06 2013
@@ -321,12 +321,10 @@ lldb_private::formatters::NSNumberSummar
     
     if (!strcmp(class_name,"NSNumber") || !strcmp(class_name,"__NSCFNumber"))
     {
-        if (descriptor->IsTagged())
+        uint64_t value = 0;
+        uint64_t i_bits = 0;
+        if (descriptor->GetTaggedPointerInfo(&i_bits,&value))
         {
-            // we have a call to get info and value bits in the tagged descriptor. but we prefer not to cast and replicate them
-            int64_t value = (valobj_addr & ~0x0000000000000000FFL) >> 8;
-            uint64_t i_bits = (valobj_addr & 0xF0) >> 4;
-            
             switch (i_bits)
             {
                 case 0:
@@ -515,10 +513,9 @@ lldb_private::formatters::NSDateSummaryP
         strcmp(class_name,"__NSDate") == 0 ||
         strcmp(class_name,"__NSTaggedDate") == 0)
     {
-        if (descriptor->IsTagged())
+        uint64_t info_bits=0,value_bits = 0;
+        if (descriptor->GetTaggedPointerInfo(&info_bits,&value_bits))
         {
-            uint64_t info_bits = (valobj_addr & 0xF0ULL) >> 4;
-            uint64_t value_bits = (valobj_addr & ~0x0000000000000000FFULL) >> 8;
             date_value_bits = ((value_bits << 8) | (info_bits << 4));
             date_value = *((double*)&date_value_bits);
         }

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h?rev=178897&r1=178896&r2=178897&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h Fri Apr  5 13:49:06 2013
@@ -46,10 +46,12 @@ public:
             return m_valid;
         }
         
+        // v1 does not support tagged pointers
         virtual bool
-        IsTagged ()
+        GetTaggedPointerInfo (uint64_t* info_bits = NULL,
+                              uint64_t* value_bits = NULL)
         {
-            return false;   // v1 runtime does not support tagged pointers
+            return false;
         }
         
         virtual uint64_t

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=178897&r1=178896&r2=178897&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Fri Apr  5 13:49:06 2013
@@ -854,10 +854,12 @@ public:
         return true;    // any Objective-C v2 runtime class descriptor we vend is valid
     }
     
+    // a custom descriptor is used for tagged pointers
     virtual bool
-    IsTagged ()
+    GetTaggedPointerInfo (uint64_t* info_bits = NULL,
+                          uint64_t* value_bits = NULL)
     {
-        return false;   // we use a special class for tagged descriptors
+        return false;
     }
     
     virtual uint64_t
@@ -1530,9 +1532,14 @@ public:
     }
     
     virtual bool
-    IsTagged ()
+    GetTaggedPointerInfo (uint64_t* info_bits = NULL,
+                          uint64_t* value_bits = NULL)
     {
-        return true;   // we use this class to describe tagged pointers
+        if (info_bits)
+            *info_bits = GetInfoBits();
+        if (value_bits)
+            *value_bits = GetValueBits();
+        return true;
     }
     
     virtual uint64_t

Modified: lldb/trunk/source/Target/ObjCLanguageRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ObjCLanguageRuntime.cpp?rev=178897&r1=178896&r2=178897&view=diff
==============================================================================
--- lldb/trunk/source/Target/ObjCLanguageRuntime.cpp (original)
+++ lldb/trunk/source/Target/ObjCLanguageRuntime.cpp Fri Apr  5 13:49:06 2013
@@ -92,6 +92,9 @@ ObjCLanguageRuntime::LookupInCompleteCla
             m_complete_class_cache.erase(name);
     }
     
+    if (m_negative_complete_class_cache.count(name) > 0)
+        return TypeSP();
+    
     const ModuleList &modules = m_process->GetTarget().GetImages();
 
     SymbolContextList sc_list;
@@ -139,6 +142,7 @@ ObjCLanguageRuntime::LookupInCompleteCla
             }
         }
     }
+    m_negative_complete_class_cache.insert(name);
     return TypeSP();
 }
 

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=178897&r1=178896&r2=178897&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Fri Apr  5 13:49:06 2013
@@ -90,6 +90,7 @@ Target::Target(Debugger &debugger, const
     SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
     SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
     SetEventName (eBroadcastBitWatchpointChanged, "watchpoint-changed");
+    SetEventName (eBroadcastBitSymbolsLoaded, "symbols-loaded");
     
     CheckInWithManager();
 
@@ -1126,6 +1127,23 @@ Target::ModulesDidLoad (ModuleList &modu
 }
 
 void
+Target::SymbolsDidLoad (ModuleList &module_list)
+{
+    if (module_list.GetSize() == 0)
+        return;
+    if (m_process_sp)
+    {
+        LanguageRuntime* runtime = m_process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
+        if (runtime)
+        {
+            ObjCLanguageRuntime *objc_runtime = (ObjCLanguageRuntime*)runtime;
+            objc_runtime->SymbolsDidLoad(module_list);
+        }
+    }
+    BroadcastEvent(eBroadcastBitSymbolsLoaded, NULL);
+}
+
+void
 Target::ModulesDidUnload (ModuleList &module_list)
 {
     if (module_list.GetSize())





More information about the lldb-commits mailing list