[Lldb-commits] [lldb] r136578 - /lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdVectorSynthProvider.py

Greg Clayton gclayton at apple.com
Sat Jul 30 15:25:25 PDT 2011


Author: gclayton
Date: Sat Jul 30 17:25:25 2011
New Revision: 136578

URL: http://llvm.org/viewvc/llvm-project?rev=136578&view=rev
Log:
Protect a bit better against uninitialized vectors.


Modified:
    lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdVectorSynthProvider.py

Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdVectorSynthProvider.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdVectorSynthProvider.py?rev=136578&r1=136577&r2=136578&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdVectorSynthProvider.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdVectorSynthProvider.py Sat Jul 30 17:25:25 2011
@@ -1,25 +1,55 @@
 class StdVectorSynthProvider:
+
     def __init__(self, valobj, dict):
         self.valobj = valobj;
         self.update()
+
     def num_children(self):
-        start_val = int(self.Mstart.GetValue(),0)
-        finish_val = int(self.Mfinish.GetValue(),0)
-        return (finish_val-start_val)/self.data_size
+        start_val = int(self.start.GetValue(),0)
+        finish_val = int(self.finish.GetValue(),0)
+        end_val  = int(self.end.GetValue(),0)
+        # Before a vector has been constructed, it will contain bad values
+        # so we really need to be careful about the length we return since
+        # unitialized data can cause us to return a huge number. We need
+        # to also check for any of the start, finish or end of storage values
+        # being zero (NULL). If any are, then this vector has not been 
+        # initialized yet and we should return zero
+        
+        # Make sure nothing is NULL
+        if start_val == 0 or finish_val == 0 or end_val == 0:
+            return 0
+        # Make sure start is less than finish
+        if start_val >= finish_val:
+            return 0
+        # Make sure finish is less than or equal to end of storage
+        if finish_val > end_val:
+            return 0
+
+        # We might still get things wrong, so cap things at 256 items for now
+        # TODO: read a target "settings set" variable for this to allow it to
+        # be customized
+        num_children = (finish_val-start_val)/self.data_size
+        if num_children > 256:
+            return 256
+        return num_children
+
     def get_child_index(self,name):
         if name == "len":
             return self.num_children();
         else:
             return int(name.lstrip('[').rstrip(']'))
+
     def get_child_at_index(self,index):
         if index == self.num_children():
             return self.valobj.CreateValueFromExpression("len",str(self.num_children()))
         else:
             offset = index * self.data_size
-            return self.Mstart.CreateChildAtOffset('['+str(index)+']',offset,self.data_type)
+            return self.start.CreateChildAtOffset('['+str(index)+']',offset,self.data_type)
+
     def update(self):
-        self.Mimpl = self.valobj.GetChildMemberWithName('_M_impl')
-        self.Mstart = self.Mimpl.GetChildMemberWithName('_M_start')
-        self.Mfinish = self.Mimpl.GetChildMemberWithName('_M_finish')
-        self.data_type = self.Mstart.GetType().GetPointeeType()
+        impl = self.valobj.GetChildMemberWithName('_M_impl')
+        self.start = impl.GetChildMemberWithName('_M_start')
+        self.finish = impl.GetChildMemberWithName('_M_finish')
+        self.end = impl.GetChildMemberWithName('_M_end_of_storage')
+        self.data_type = self.start.GetType().GetPointeeType()
         self.data_size = self.data_type.GetByteSize()





More information about the lldb-commits mailing list