[Lldb-commits] [lldb] r219337 - Add a (Python only) lldb.SBSyntheticValueProvider class to our API surface

Enrico Granata egranata at apple.com
Wed Oct 8 13:10:09 PDT 2014

Author: enrico
Date: Wed Oct  8 15:10:09 2014
New Revision: 219337

URL: http://llvm.org/viewvc/llvm-project?rev=219337&view=rev
Add a (Python only) lldb.SBSyntheticValueProvider class to our API surface
On a suggestion from Jim Ingham, this class allows you to very easily define synthetic child providers that return a synthetic value (in the sense of r219330), but no children

Also, document this new feature in our www docs


Modified: lldb/trunk/scripts/Python/python-extensions.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-extensions.swig?rev=219337&r1=219336&r2=219337&view=diff
--- lldb/trunk/scripts/Python/python-extensions.swig (original)
+++ lldb/trunk/scripts/Python/python-extensions.swig Wed Oct  8 15:10:09 2014
@@ -1047,3 +1047,27 @@ class value(object):
     def __neq__(self, other):
         return not self.__eq__(other)
+%pythoncode %{
+class SBSyntheticValueProvider(object):
+    def __init__(self,valobj):
+        pass
+    def num_children(self):
+        return 0
+    def get_child_index(self,name):
+        return None
+    def get_child_at_index(self,idx):
+        return None
+    def update(self):
+        pass
+    def has_children(self):
+        return False
\ No newline at end of file

Modified: lldb/trunk/www/varformats.html
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/www/varformats.html?rev=219337&r1=219336&r2=219337&view=diff
--- lldb/trunk/www/varformats.html (original)
+++ lldb/trunk/www/varformats.html Wed Oct  8 15:10:09 2014
@@ -1027,10 +1027,15 @@ def function (valobj,internal_dict):<br/
 			        <i>this call should be used to update the internal state of this Python object whenever the state of the variables in LLDB changes.</i><sup>[1]</sup><br/>
 			    <font color=blue>def</font> has_children(self): <br/>
 			        <i>this call should return True if this object might have children, and False if this object can be guaranteed not to have children.</i><sup>[2]</sup><br/>
+			    <font color=blue>def</font> get_value(self): <br/>
+			        <i>this call can return an SBValue to be presented as the value of the synthetic value under consideration.</i><sup>[3]</sup><br/>
 <sup>[1]</sup> This method is optional. Also, it may optionally choose to return a value (starting with SVN rev153061/LLDB-134). If it returns a value, and that value is <font color=blue><code>True</code></font>, LLDB will be allowed to cache the children and the children count it previously obtained, and will not return to the provider class to ask. If nothing, <font color=blue><code>None</code></font>, or anything other than <font color=blue><code>True</code></font> is returned, LLDB will discard the cached information and ask. Regardless, whenever necessary LLDB will call <code>update</code>.
 <sup>[2]</sup> This method is optional (starting with SVN rev166495/LLDB-175). While implementing it in terms of <code>num_children</code> is acceptable, implementors are encouraged to look for optimized coding alternatives whenever reasonable.
+<sup>[3]</sup> This method is optional (starting with SVN revision 219330). The SBValue you return here will most likely be a numeric type (int, float, ...) as its value bytes will be used as-if they were the value of the root SBValue proper. As a shortcut for this, you can inherit from lldb.SBSyntheticValueProvider, and just define get_value as other methods are defaulted in the superclass as returning default no-children responses.
 		<p>For examples of how synthetic children are created, you are encouraged to look at <a href="http://llvm.org/svn/llvm-project/lldb/trunk/examples/synthetic/">examples/synthetic</a> in the LLDB trunk. Please, be aware that the code in those files (except bitfield/)
 			is legacy code and is not maintained.
 			You may especially want to begin looking at <a href="http://llvm.org/svn/llvm-project/lldb/trunk/examples/synthetic/bitfield">this example</a> to get

More information about the lldb-commits mailing list