Reputation: 3
I have a custom C++ container type and want to change the way in looks in Xcode Variable View. Need to make something similar to the way NSArray
or std::vector
look there.
By now a can only change the summary string to output container size, and don't know how to arrange container's children in a tree with indices. The default view outputs container ivars.
Is it possible to output container children in a tree with LLDB Python scripting?
Upvotes: 0
Views: 648
Reputation: 3329
Yes, it indeed is.
The feature you are looking for is called “synthetic children”, and it essentially involves binding a Python class to your data type. LLDB will then proceed to interrogate your class when in need of vending child objects (the elements in the container), instead of trusting the debug info as it is currently doing. With one slight difference [1] this is the same thing LLDB does for NSArray, std::vector and several others
[1] the synthetic children providers for well-known system types are written in C++ and are part of the LLDB core, mostly for performance reasons
In order to roll your own, you need to implement a class that obeys this specification:
class SyntheticChildrenProvider:
def __init__(self, valobj, internal_dict):
this call should initialize the Python object using valobj as the variable to provide synthetic children for
def num_children(self):
this call should return the number of children that you want your object to have
def get_child_index(self,name):
this call should return the index of the synthetic child whose name is given as argument
def get_child_at_index(self,index):
this call should return a new LLDB SBValue object representing the child at the index given as argument
def update(self):
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]
[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.
The details are at http://lldb.llvm.org/varformats.html , including links to a couple sample implementations that you can use as a starting point.
Feel free to ping back if you have any additional questions or need more guidance!
Upvotes: 0