[Lldb-commits] [lldb] r204756 - <rdar://problem/14515139>

Enrico Granata egranata at apple.com
Tue Mar 25 13:53:34 PDT 2014


Author: enrico
Date: Tue Mar 25 15:53:33 2014
New Revision: 204756

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

Add a GetFoundationVersion() to AppleObjCRuntime
This API is used to return and cache the major version of Foundation.framework, which is potentially a useful piece of data to key off of to enable or disable certain ObjC related behaviors (especially in data formatters)


Modified:
    lldb/trunk/include/lldb/lldb-defines.h
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
    lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Modified: lldb/trunk/include/lldb/lldb-defines.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-defines.h?rev=204756&r1=204755&r2=204756&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-defines.h (original)
+++ lldb/trunk/include/lldb/lldb-defines.h Tue Mar 25 15:53:33 2014
@@ -87,6 +87,7 @@
 #define LLDB_INVALID_INDEX32            UINT32_MAX
 #define LLDB_INVALID_IVAR_OFFSET        UINT32_MAX
 #define LLDB_INVALID_IMAGE_TOKEN        UINT32_MAX
+#define LLDB_INVALID_MODULE_VERSION     UINT32_MAX
 #define LLDB_INVALID_REGNUM             UINT32_MAX
 #define LLDB_INVALID_UID                UINT64_MAX
 #define LLDB_INVALID_PROCESS_ID         0

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=204756&r1=204755&r2=204756&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Tue Mar 25 15:53:33 2014
@@ -1646,7 +1646,7 @@ Module::GetVersion (uint32_t *versions,
     if (versions && num_versions)
     {
         for (uint32_t i=0; i<num_versions; ++i)
-            versions[i] = UINT32_MAX;
+            versions[i] = LLDB_INVALID_MODULE_VERSION;
     }
     return 0;
 }

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp?rev=204756&r1=204755&r2=204756&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp Tue Mar 25 15:53:33 2014
@@ -251,6 +251,32 @@ AppleObjCRuntime::AppleIsModuleObjCLibra
     return false;
 }
 
+// we use the version of Foundation to make assumptions about the ObjC runtime on a target
+uint32_t
+AppleObjCRuntime::GetFoundationVersion ()
+{
+    if (!m_Foundation_major.hasValue())
+    {
+        const ModuleList& modules = m_process->GetTarget().GetImages();
+        uint32_t major = UINT32_MAX;
+        for (uint32_t idx = 0; idx < modules.GetSize(); idx++)
+        {
+            lldb::ModuleSP module_sp = modules.GetModuleAtIndex(idx);
+            if (!module_sp)
+                continue;
+            if (strcmp(module_sp->GetFileSpec().GetFilename().AsCString(""),"Foundation") == 0)
+            {
+                module_sp->GetVersion(&major,1);
+                m_Foundation_major = major;
+                return major;
+            }
+        }
+        return LLDB_INVALID_MODULE_VERSION;
+    }
+    else
+        return m_Foundation_major.getValue();
+}
+
 bool
 AppleObjCRuntime::IsModuleObjCLibrary (const ModuleSP &module_sp)
 {

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h?rev=204756&r1=204755&r2=204756&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h Tue Mar 25 15:53:33 2014
@@ -13,6 +13,9 @@
 // C Includes
 // C++ Includes
 // Other libraries and framework includes
+
+#include "llvm/ADT/Optional.h"
+
 // Project includes
 #include "lldb/lldb-private.h"
 #include "lldb/Target/LanguageRuntime.h"
@@ -103,6 +106,9 @@ public:
     virtual lldb::SearchFilterSP
     CreateExceptionSearchFilter ();
     
+    uint32_t
+    GetFoundationVersion ();
+    
 protected:
     Address *
     GetPrintForDebuggerAddr();
@@ -112,11 +118,14 @@ protected:
     std::unique_ptr<lldb_private::AppleObjCTrampolineHandler> m_objc_trampoline_handler_ap;
     lldb::BreakpointSP m_objc_exception_bp_sp;
     lldb::ModuleWP m_objc_module_wp;
+    
+    llvm::Optional<uint32_t> m_Foundation_major;
 
     AppleObjCRuntime(Process *process) :
         lldb_private::ObjCLanguageRuntime(process),
         m_read_objc_library (false),
-        m_objc_trampoline_handler_ap ()
+        m_objc_trampoline_handler_ap (),
+        m_Foundation_major()
      {
          // Call CreateInstance instead.
      }

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=204756&r1=204755&r2=204756&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Tue Mar 25 15:53:33 2014
@@ -2472,45 +2472,22 @@ AppleObjCRuntimeV2::TaggedPointerVendorL
     return (ptr & 1);
 }
 
-// we use the version of Foundation to make assumptions about the ObjC runtime on a target
-uint32_t
-AppleObjCRuntimeV2::TaggedPointerVendorLegacy::GetFoundationVersion (Target &target)
-{
-    const ModuleList& modules = target.GetImages();
-    uint32_t major = UINT32_MAX;
-    for (uint32_t idx = 0; idx < modules.GetSize(); idx++)
-    {
-        lldb::ModuleSP module_sp = modules.GetModuleAtIndex(idx);
-        if (!module_sp)
-            continue;
-        if (strcmp(module_sp->GetFileSpec().GetFilename().AsCString(""),"Foundation") == 0)
-        {
-            module_sp->GetVersion(&major,1);
-            break;
-        }
-    }
-    return major;
-}
-
 ObjCLanguageRuntime::ClassDescriptorSP
 AppleObjCRuntimeV2::TaggedPointerVendorLegacy::GetClassDescriptor (lldb::addr_t ptr)
 {
     if (!IsPossibleTaggedPointer(ptr))
         return ObjCLanguageRuntime::ClassDescriptorSP();
 
-    Process* process(m_runtime.GetProcess());
-    
-    if (m_Foundation_version == 0)
-        m_Foundation_version = GetFoundationVersion(process->GetTarget());
+    uint32_t foundation_version = m_runtime.GetFoundationVersion();
     
-    if (m_Foundation_version == UINT32_MAX)
+    if (foundation_version == LLDB_INVALID_MODULE_VERSION)
         return ObjCLanguageRuntime::ClassDescriptorSP();
     
     uint64_t class_bits = (ptr & 0xE) >> 1;
     ConstString name;
     
     // TODO: make a table
-    if (m_Foundation_version >= 900)
+    if (foundation_version >= 900)
     {
         switch (class_bits)
         {

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=204756&r1=204755&r2=204756&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h Tue Mar 25 15:53:33 2014
@@ -226,16 +226,10 @@ private:
         GetClassDescriptor (lldb::addr_t ptr);
     protected:
         TaggedPointerVendorLegacy (AppleObjCRuntimeV2& runtime) :
-        TaggedPointerVendor (runtime),
-        m_Foundation_version(0)
+        TaggedPointerVendor (runtime)
         {
         }
         
-        static uint32_t
-        GetFoundationVersion (Target& target);
-        
-        uint32_t m_Foundation_version;
-        
         friend class AppleObjCRuntimeV2::TaggedPointerVendor;
         
         DISALLOW_COPY_AND_ASSIGN(TaggedPointerVendorLegacy);

Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=204756&r1=204755&r2=204756&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Tue Mar 25 15:53:33 2014
@@ -526,7 +526,7 @@ ObjectFileELF::GetModuleSpecifications (
                                 for (ProgramHeaderCollConstIter I = program_headers.begin();
                                      I != program_headers.end(); ++I)
                                 {
-                                     segment_data_end = std::max (I->p_offset + I->p_filesz, segment_data_end);
+                                     segment_data_end = std::max<unsigned long long> (I->p_offset + I->p_filesz, segment_data_end);
                                 }
 
                                 if (segment_data_end > data_sp->GetByteSize())





More information about the lldb-commits mailing list