Skip to content

Commit aa56848

Browse files
author
git apple-llvm automerger
committed
Merge commit '6c36bdb6eab1' from llvm.org/main into next
2 parents c887056 + 6c36bdb commit aa56848

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

lldb/docs/use/variable.rst

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -930,40 +930,55 @@ be implemented by the Python class):
930930
931931
class SyntheticChildrenProvider:
932932
def __init__(self, valobj, internal_dict):
933-
this call should initialize the Python object using valobj as the variable to provide synthetic children for
934-
def num_children(self):
935-
this call should return the number of children that you want your object to have
933+
this call should initialize the Python object using valobj as the
934+
variable to provide synthetic children for
935+
def num_children(self, max_children):
936+
this call should return the number of children that you want your
937+
object to have[1]
936938
def get_child_index(self,name):
937-
this call should return the index of the synthetic child whose name is given as argument
939+
this call should return the index of the synthetic child whose name is
940+
given as argument
938941
def get_child_at_index(self,index):
939-
this call should return a new LLDB SBValue object representing the child at the index given as argument
942+
this call should return a new LLDB SBValue object representing the
943+
child at the index given as argument
940944
def update(self):
941-
this call should be used to update the internal state of this Python object whenever the state of the variables in LLDB changes.[1]
945+
this call should be used to update the internal state of this Python
946+
object whenever the state of the variables in LLDB changes.[2]
942947
Also, this method is invoked before any other method in the interface.
943948
def has_children(self):
944-
this call should return True if this object might have children, and False if this object can be guaranteed not to have children.[2]
949+
this call should return True if this object might have children, and
950+
False if this object can be guaranteed not to have children.[3]
945951
def get_value(self):
946-
this call can return an SBValue to be presented as the value of the synthetic value under consideration.[3]
952+
this call can return an SBValue to be presented as the value of the
953+
synthetic value under consideration.[4]
947954
948955
As a warning, exceptions that are thrown by python formatters are caught
949956
silently by LLDB and should be handled appropriately by the formatter itself.
950957
Being more specific, in case of exceptions, LLDB might assume that the given
951958
object has no children or it might skip printing some children, as they are
952959
printed one by one.
953960

954-
[1] This method is optional. Also, a boolean value must be returned (since lldb
961+
[1] The `max_children` argument is optional (since lldb 3.8.0) and indicates the
962+
maximum number of children that lldb is interested in (at this moment). If the
963+
computation of the number of children is expensive (for example, requires
964+
travesing a linked list to determine its size) your implementation may return
965+
`max_children` rather than the actual number. If the computation is cheap (e.g., the
966+
number is stored as a field of the object), then you can always return the true
967+
number of children (that is, ignore the `max_children` argument).
968+
969+
[2] This method is optional. Also, a boolean value must be returned (since lldb
955970
3.1.0). If ``False`` is returned, then whenever the process reaches a new stop,
956971
this method will be invoked again to generate an updated list of the children
957972
for a given variable. Otherwise, if ``True`` is returned, then the value is
958973
cached and this method won't be called again, effectively freezing the state of
959974
the value in subsequent stops. Beware that returning ``True`` incorrectly could
960975
show misleading information to the user.
961976

962-
[2] This method is optional (since lldb 3.2.0). While implementing it in terms
977+
[3] This method is optional (since lldb 3.2.0). While implementing it in terms
963978
of num_children is acceptable, implementors are encouraged to look for
964979
optimized coding alternatives whenever reasonable.
965980

966-
[3] This method is optional (since lldb 3.5.2). The `SBValue` you return here
981+
[4] This method is optional (since lldb 3.5.2). The `SBValue` you return here
967982
will most likely be a numeric type (int, float, ...) as its value bytes will be
968983
used as-if they were the value of the root `SBValue` proper. As a shortcut for
969984
this, you can inherit from lldb.SBSyntheticValueProvider, and just define

lldb/include/lldb/API/SBValue.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,22 @@ class LLDB_API SBValue {
281281

282282
bool IsRuntimeSupportValue();
283283

284+
/// Return the number of children of this variable. Note that for some
285+
/// variables this operation can be expensive. If possible, prefer calling
286+
/// GetNumChildren(max) with the maximum number of children you are interested
287+
/// in.
284288
uint32_t GetNumChildren();
285289

290+
/// Return the numer of children of this variable, with a hint that the
291+
/// caller is interested in at most \a max children. Use this function to
292+
/// avoid expensive child computations in some cases. For example, if you know
293+
/// you will only ever display 100 elements, calling GetNumChildren(100) can
294+
/// avoid enumerating all the other children. If the returned value is smaller
295+
/// than \a max, then it represents the true number of children, otherwise it
296+
/// indicates that their number is at least \a max. Do not assume the returned
297+
/// number will always be less than or equal to \a max, as the implementation
298+
/// may choose to return a larger (but still smaller than the actual number of
299+
/// children) value.
286300
uint32_t GetNumChildren(uint32_t max);
287301

288302
LLDB_DEPRECATED("SBValue::GetOpaqueType() is deprecated.")

0 commit comments

Comments
 (0)