From 8387e2fafebf78e4840e18be3d75ea7b9432faaa Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Wed, 8 Oct 2014 20:10:09 +0000 Subject: [PATCH] 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 llvm-svn: 219337 --- lldb/scripts/Python/python-extensions.swig | 24 ++++++++++++++++++++++ lldb/www/varformats.html | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/lldb/scripts/Python/python-extensions.swig b/lldb/scripts/Python/python-extensions.swig index 9e9feb8a3c7c..a1d98dea3b2e 100644 --- a/lldb/scripts/Python/python-extensions.swig +++ b/lldb/scripts/Python/python-extensions.swig @@ -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 diff --git a/lldb/www/varformats.html b/lldb/www/varformats.html index e8872a1b2c2b..18e2ada29fb8 100755 --- a/lldb/www/varformats.html +++ b/lldb/www/varformats.html @@ -1027,10 +1027,15 @@ def function (valobj,internal_dict):
        this call should be used to update the internal state of this Python object whenever the state of the variables in LLDB changes.[1]
    def has_children(self):
        this call should return True if this object might have children, and False if this object can be guaranteed not to have children.[2]
+     def get_value(self):
+         this call can return an SBValue to be presented as the value of the synthetic value under consideration.[3]
+ [1] 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 True, 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, None, or anything other than True is returned, LLDB will discard the cached information and ask. Regardless, whenever necessary LLDB will call update.
[2] This method is optional (starting with SVN rev166495/LLDB-175). While implementing it in terms of num_children is acceptable, implementors are encouraged to look for optimized coding alternatives whenever reasonable. +
+[3] 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.

For examples of how synthetic children are created, you are encouraged to look at examples/synthetic 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 this example to get