[Lldb-commits] [lldb] r239851 - Fixing a potential issue where the NSIndexPath formatter could try to access stale data

Enrico Granata egranata at apple.com
Tue Jun 16 13:48:49 PDT 2015


Author: enrico
Date: Tue Jun 16 15:48:49 2015
New Revision: 239851

URL: http://llvm.org/viewvc/llvm-project?rev=239851&view=rev
Log:
Fixing a potential issue where the NSIndexPath formatter could try to access stale data

No test because I did not see this happen - it has been found by code inspection as a response to seeing crash logs about this


Modified:
    lldb/trunk/source/DataFormatters/NSIndexPath.cpp

Modified: lldb/trunk/source/DataFormatters/NSIndexPath.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/NSIndexPath.cpp?rev=239851&r1=239850&r2=239851&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/NSIndexPath.cpp (original)
+++ lldb/trunk/source/DataFormatters/NSIndexPath.cpp Tue Jun 16 15:48:49 2015
@@ -47,7 +47,7 @@ public:
     virtual bool
     Update()
     {
-        m_impl.m_mode = Mode::Invalid;
+        m_impl.Clear();
         
         m_ast_ctx = ClangASTContext::GetASTContext(m_backend.GetClangType().GetASTContext());
         if (!m_ast_ctx)
@@ -76,8 +76,8 @@ public:
         
         if (descriptor->GetTaggedPointerInfo(&info_bits, &value_bits, &payload))
         {
-            m_impl.m_mode = Mode::Inlined;
             m_impl.m_inlined.SetIndexes(payload, *process_sp);
+            m_impl.m_mode = Mode::Inlined;
         }
         else
         {
@@ -191,104 +191,133 @@ protected:
         }
 
         struct InlinedIndexes {
-	public:
-	  void SetIndexes(uint64_t value, Process& p)
-	  {
-	      m_indexes = value;
-	      _lengthForInlinePayload(p.GetAddressByteSize());
-	      m_process = &p;
-	  }
-          
-	  size_t
-	  GetNumIndexes ()
-	  {
-	      return m_count;
-	  }
-          
-	  lldb::ValueObjectSP
-	  GetIndexAtIndex (size_t idx, const ClangASTType& desired_type)
-	  {
-	      std::pair<uint64_t, bool> value(_indexAtPositionForInlinePayload(idx));
-	      if (!value.second)
-		  return nullptr;
-	      Value v;
-	      if (m_ptr_size == 8)
-	      {
-		  Scalar scalar( (unsigned long long)value.first );
-		  v = Value(scalar);
-	      }
-	      else
-	      {
-		  Scalar scalar( (unsigned int)value.first );
-		  v = Value(scalar);
-	      }
-	      v.SetClangType(desired_type);
-	      StreamString idx_name;
-	      idx_name.Printf("[%" PRIu64 "]", (uint64_t)idx);
-	      return ValueObjectConstResult::Create(m_process, v, ConstString(idx_name.GetData()));
-	  }
-                
-	  private:
-	  uint64_t m_indexes;
-	  size_t m_count;
-	  uint32_t m_ptr_size;
-	  Process *m_process;
-                
-	  // cfr. Foundation for the details of this code
-	  size_t _lengthForInlinePayload(uint32_t ptr_size) {
-	      m_ptr_size = ptr_size;
-	      if (m_ptr_size == 8)
-		  m_count = ((m_indexes >> 3) & 0x7);
-	      else
-		  m_count = ((m_indexes >> 3) & 0x3);
-	      return m_count;
-	  }
-                
-	  std::pair<uint64_t, bool>
-	  _indexAtPositionForInlinePayload(size_t pos) {
-	      if (m_ptr_size == 8)
-	      {
-		switch (pos) {
-		case 5: return {((m_indexes >> 51) & 0x1ff),true};
-		case 4: return {((m_indexes >> 42) & 0x1ff),true};
-		case 3: return {((m_indexes >> 33) & 0x1ff),true};
-		case 2: return {((m_indexes >> 24) & 0x1ff),true};
-		case 1: return {((m_indexes >> 15) & 0x1ff),true};
-		case 0: return {((m_indexes >>  6) & 0x1ff),true};
-	        }
-	      }
-	      else
-	      {
-		  switch (pos) {
-		  case 2: return {((m_indexes >> 23) & 0x1ff),true};
-		  case 1: return {((m_indexes >> 14) & 0x1ff),true};
-		  case 0: return {((m_indexes >>  5) & 0x1ff),true};
-		  }
-	      }
-	      return {0,false};
-	  }
+        public:
+          void SetIndexes(uint64_t value, Process& p)
+          {
+              m_indexes = value;
+              _lengthForInlinePayload(p.GetAddressByteSize());
+              m_process = &p;
+          }
+              
+          size_t
+          GetNumIndexes ()
+          {
+              return m_count;
+          }
+
+          lldb::ValueObjectSP
+          GetIndexAtIndex (size_t idx, const ClangASTType& desired_type)
+          {
+              std::pair<uint64_t, bool> value(_indexAtPositionForInlinePayload(idx));
+              if (!value.second)
+                  return nullptr;
+              
+              Value v;
+              if (m_ptr_size == 8)
+              {
+                  Scalar scalar( (unsigned long long)value.first );
+                  v = Value(scalar);
+              }
+              else
+              {
+                  Scalar scalar( (unsigned int)value.first );
+                  v = Value(scalar);
+              }
+
+              v.SetClangType(desired_type);
 
-	};
+              StreamString idx_name;
+              idx_name.Printf("[%" PRIu64 "]", (uint64_t)idx);
+
+              return ValueObjectConstResult::Create(m_process, v, ConstString(idx_name.GetData()));
+          }
+            
+            void
+            Clear ()
+            {
+                m_indexes = 0;
+                m_count = 0;
+                m_ptr_size = 0;
+                m_process = nullptr;
+            }
+                    
+          private:
+          uint64_t m_indexes;
+          size_t m_count;
+          uint32_t m_ptr_size;
+          Process *m_process;
+                    
+          // cfr. Foundation for the details of this code
+          size_t _lengthForInlinePayload(uint32_t ptr_size) {
+              m_ptr_size = ptr_size;
+              if (m_ptr_size == 8)
+              m_count = ((m_indexes >> 3) & 0x7);
+              else
+              m_count = ((m_indexes >> 3) & 0x3);
+              return m_count;
+          }
+                    
+          std::pair<uint64_t, bool>
+          _indexAtPositionForInlinePayload(size_t pos)
+          {
+              if (m_ptr_size == 8)
+              {
+                switch (pos) {
+                    case 5: return {((m_indexes >> 51) & 0x1ff),true};
+                    case 4: return {((m_indexes >> 42) & 0x1ff),true};
+                    case 3: return {((m_indexes >> 33) & 0x1ff),true};
+                    case 2: return {((m_indexes >> 24) & 0x1ff),true};
+                    case 1: return {((m_indexes >> 15) & 0x1ff),true};
+                    case 0: return {((m_indexes >>  6) & 0x1ff),true};
+                }
+              }
+              else
+                  {
+                  switch (pos) {
+                      case 2: return {((m_indexes >> 23) & 0x1ff),true};
+                      case 1: return {((m_indexes >> 14) & 0x1ff),true};
+                      case 0: return {((m_indexes >>  5) & 0x1ff),true};
+                  }
+              }
+              return {0,false};
+          }
+
+        };
         struct OutsourcedIndexes {
-	    ValueObject *m_indexes;
-	    size_t m_count;
-                
-	    lldb::ValueObjectSP
-	    GetIndexAtIndex (size_t idx)
-	    {
-	        if (m_indexes)
-		{
-		    ValueObjectSP index_sp(m_indexes->GetSyntheticArrayMember(idx, true));
-		    return index_sp;
-		}
-		return nullptr;
-	    }
-	};
+            ValueObject *m_indexes;
+            size_t m_count;
+                    
+            lldb::ValueObjectSP
+            GetIndexAtIndex (size_t idx)
+            {
+                if (m_indexes)
+                {
+                    ValueObjectSP index_sp(m_indexes->GetSyntheticArrayMember(idx, true));
+                    return index_sp;
+                }
+                return nullptr;
+            }
+            
+            void
+            Clear ()
+            {
+                m_indexes = nullptr;
+                m_count = 0;
+            }
+        };
 
         union {
-	    struct InlinedIndexes m_inlined;
-	    struct OutsourcedIndexes m_outsourced;
+            struct InlinedIndexes m_inlined;
+            struct OutsourcedIndexes m_outsourced;
         };
+        
+        void
+        Clear ()
+        {
+            m_mode = Mode::Invalid;
+            m_inlined.Clear();
+            m_outsourced.Clear();
+        }
     } m_impl;
     
     uint32_t m_ptr_size;





More information about the lldb-commits mailing list