Author: sivachandra Date: Wed Oct 21 14:28:08 2015 New Revision: 250930 URL: http://llvm.org/viewvc/llvm-project?rev=250930&view=rev Log: [SBValue] Add a method GetNumChildren(uint32_t max)
Summary: Along with this, support for an optional argument to the "num_children" method of a Python synthetic child provider has also been added. These have been added with the following use case in mind: Synthetic child providers currently have a method "has_children" and "num_children". While the former is good enough to know if there are children, it does not give any insight into how many children there are. Though the latter serves this purpose, calculating the number for children of a data structure could be an O(N) operation if the data structure has N children. The new method added in this change provide a middle ground. One can call GetNumChildren(K) to know if a child exists at an index K which can be as large as the callers tolerance can be. If the caller wants to know about children beyond K, it can make an other call with 2K. If the synthetic child provider maintains state about it counting till K previosly, then the next call is only an O(K) operation. Infact, all calls made progressively with steps of K will be O(K) operations. Reviewers: vharron, clayborg, granata.enrico Subscribers: labath, lldb-commits Differential Revision: http://reviews.llvm.org/D13778 Modified: lldb/trunk/include/lldb/API/SBValue.h lldb/trunk/include/lldb/Core/ValueObject.h lldb/trunk/include/lldb/Core/ValueObjectCast.h lldb/trunk/include/lldb/Core/ValueObjectChild.h lldb/trunk/include/lldb/Core/ValueObjectConstResult.h lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h lldb/trunk/include/lldb/Core/ValueObjectMemory.h lldb/trunk/include/lldb/Core/ValueObjectRegister.h lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h lldb/trunk/include/lldb/Core/ValueObjectVariable.h lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h lldb/trunk/scripts/Python/python-wrapper.swig lldb/trunk/scripts/interface/SBValue.i lldb/trunk/source/API/SBValue.cpp lldb/trunk/source/API/SystemInitializerFull.cpp lldb/trunk/source/Core/ValueObject.cpp lldb/trunk/source/Core/ValueObjectCast.cpp lldb/trunk/source/Core/ValueObjectChild.cpp lldb/trunk/source/Core/ValueObjectConstResult.cpp lldb/trunk/source/Core/ValueObjectDynamicValue.cpp lldb/trunk/source/Core/ValueObjectMemory.cpp lldb/trunk/source/Core/ValueObjectRegister.cpp lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp lldb/trunk/source/Core/ValueObjectVariable.cpp lldb/trunk/source/DataFormatters/TypeSynthetic.cpp lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/main.cpp lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/myIntSynthProvider.py Modified: lldb/trunk/include/lldb/API/SBValue.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBValue.h?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBValue.h (original) +++ lldb/trunk/include/lldb/API/SBValue.h Wed Oct 21 14:28:08 2015 @@ -330,6 +330,9 @@ public: uint32_t GetNumChildren (); + uint32_t + GetNumChildren (uint32_t max); + void * GetOpaqueType(); Modified: lldb/trunk/include/lldb/Core/ValueObject.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObject.h (original) +++ lldb/trunk/include/lldb/Core/ValueObject.h Wed Oct 21 14:28:08 2015 @@ -595,7 +595,7 @@ public: GetIndexOfChildWithName (const ConstString &name); size_t - GetNumChildren (); + GetNumChildren (uint32_t max=UINT32_MAX); const Value & GetValue() const; @@ -1204,7 +1204,7 @@ protected: // Should only be called by ValueObject::GetNumChildren() virtual size_t - CalculateNumChildren() = 0; + CalculateNumChildren(uint32_t max=UINT32_MAX) = 0; void SetNumChildren (size_t num_children); Modified: lldb/trunk/include/lldb/Core/ValueObjectCast.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectCast.h?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObjectCast.h (original) +++ lldb/trunk/include/lldb/Core/ValueObjectCast.h Wed Oct 21 14:28:08 2015 @@ -35,7 +35,7 @@ public: GetByteSize() override; size_t - CalculateNumChildren() override; + CalculateNumChildren(uint32_t max) override; lldb::ValueType GetValueType() const override; Modified: lldb/trunk/include/lldb/Core/ValueObjectChild.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectChild.h?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObjectChild.h (original) +++ lldb/trunk/include/lldb/Core/ValueObjectChild.h Wed Oct 21 14:28:08 2015 @@ -56,7 +56,7 @@ public: GetValueType() const override; size_t - CalculateNumChildren() override; + CalculateNumChildren(uint32_t max) override; ConstString GetTypeName() override; Modified: lldb/trunk/include/lldb/Core/ValueObjectConstResult.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectConstResult.h?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObjectConstResult.h (original) +++ lldb/trunk/include/lldb/Core/ValueObjectConstResult.h Wed Oct 21 14:28:08 2015 @@ -76,7 +76,7 @@ public: GetValueType() const override; size_t - CalculateNumChildren() override; + CalculateNumChildren(uint32_t max) override; ConstString GetTypeName() override; Modified: lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h (original) +++ lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h Wed Oct 21 14:28:08 2015 @@ -41,7 +41,7 @@ public: GetDisplayTypeName() override; size_t - CalculateNumChildren() override; + CalculateNumChildren(uint32_t max) override; lldb::ValueType GetValueType() const override; Modified: lldb/trunk/include/lldb/Core/ValueObjectMemory.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectMemory.h?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObjectMemory.h (original) +++ lldb/trunk/include/lldb/Core/ValueObjectMemory.h Wed Oct 21 14:28:08 2015 @@ -50,7 +50,7 @@ public: GetDisplayTypeName() override; size_t - CalculateNumChildren() override; + CalculateNumChildren(uint32_t max) override; lldb::ValueType GetValueType() const override; Modified: lldb/trunk/include/lldb/Core/ValueObjectRegister.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectRegister.h?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObjectRegister.h (original) +++ lldb/trunk/include/lldb/Core/ValueObjectRegister.h Wed Oct 21 14:28:08 2015 @@ -48,7 +48,7 @@ public: GetDisplayTypeName() override; size_t - CalculateNumChildren() override; + CalculateNumChildren(uint32_t max) override; ValueObject * CreateChildAtIndex(size_t idx, bool synthetic_array_member, int32_t synthetic_index) override; @@ -94,7 +94,7 @@ public: GetQualifiedTypeName() override; size_t - CalculateNumChildren() override; + CalculateNumChildren(uint32_t max) override; ValueObject * CreateChildAtIndex(size_t idx, bool synthetic_array_member, int32_t synthetic_index) override; @@ -148,7 +148,7 @@ public: GetTypeName() override; size_t - CalculateNumChildren() override; + CalculateNumChildren(uint32_t max) override; bool SetValueFromCString(const char *value_str, Error& error) override; Modified: lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h (original) +++ lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h Wed Oct 21 14:28:08 2015 @@ -49,7 +49,7 @@ public: MightHaveChildren() override; size_t - CalculateNumChildren() override; + CalculateNumChildren(uint32_t max) override; lldb::ValueType GetValueType() const override; Modified: lldb/trunk/include/lldb/Core/ValueObjectVariable.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectVariable.h?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObjectVariable.h (original) +++ lldb/trunk/include/lldb/Core/ValueObjectVariable.h Wed Oct 21 14:28:08 2015 @@ -43,7 +43,7 @@ public: GetDisplayTypeName() override; size_t - CalculateNumChildren() override; + CalculateNumChildren(uint32_t max) override; lldb::ValueType GetValueType() const override; Modified: lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h (original) +++ lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h Wed Oct 21 14:28:08 2015 @@ -56,13 +56,20 @@ namespace lldb_private { ~SyntheticChildrenFrontEnd () { } - + virtual size_t CalculateNumChildren () = 0; + + virtual size_t + CalculateNumChildren (uint32_t max) + { + auto count = CalculateNumChildren (); + return count <= max ? count : max; + } virtual lldb::ValueObjectSP GetChildAtIndex (size_t idx) = 0; - + virtual size_t GetIndexOfChildWithName (const ConstString &name) = 0; @@ -454,7 +461,7 @@ namespace lldb_private { return lldb::ValueObjectSP(); return m_backend.GetSyntheticExpressionPathChild(filter->GetExpressionPathAtIndex(idx), true); } - + bool Update() override { return false; } @@ -589,13 +596,16 @@ namespace lldb_private { IsValid (); ~FrontEnd() override; - + size_t CalculateNumChildren() override; + + size_t + CalculateNumChildren(uint32_t max) override; lldb::ValueObjectSP GetChildAtIndex(size_t idx) override; - + bool Update() override; Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original) +++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Wed Oct 21 14:28:08 2015 @@ -349,7 +349,7 @@ public: } virtual size_t - CalculateNumChildren(const StructuredData::ObjectSP &implementor) + CalculateNumChildren(const StructuredData::ObjectSP &implementor, uint32_t max) { return 0; } Modified: lldb/trunk/scripts/Python/python-wrapper.swig URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-wrapper.swig?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/scripts/Python/python-wrapper.swig (original) +++ lldb/trunk/scripts/Python/python-wrapper.swig Wed Oct 21 14:28:08 2015 @@ -113,9 +113,18 @@ public: argc GetNumArguments () { - if (m_callable && PyFunction_Check(m_callable)) + PyObject *py_func_obj = NULL; + if (m_callable) { - PyCodeObject* code = (PyCodeObject*)PyFunction_GET_CODE(m_callable); + if (PyMethod_Check(m_callable)) + py_func_obj = PyMethod_GET_FUNCTION(m_callable); + else + py_func_obj = m_callable; + } + + if (py_func_obj) + { + PyCodeObject* code = (PyCodeObject*)PyFunction_GET_CODE(py_func_obj); if (code) { size_t args = code->co_argcount; @@ -632,15 +641,24 @@ LLDBSwigPython_CallOptionalMember SWIGEXPORT size_t LLDBSwigPython_CalculateNumChildren ( - PyObject *implementor + PyObject *implementor, + uint32_t max ) { - size_t ret_val = UINT32_MAX; + size_t ret_val = 0; bool int_match = false; - static char callee_name[] = "num_children"; + PyCallable pfunc = PyCallable::FindWithMemberFunction(implementor, "num_children"); - PyObject* py_return = LLDBSwigPython_CallOptionalMember(implementor,callee_name, NULL); + if (!pfunc) + return ret_val; + + PyObject* py_return = NULL; + auto argc = pfunc.GetNumArguments(); + if (argc.num_args == 1) + py_return = pfunc(); + else if (argc.num_args == 2) + py_return = pfunc(max); if (!py_return) return ret_val; @@ -675,6 +693,9 @@ LLDBSwigPython_CalculateNumChildren PyErr_Clear(); } + if (argc.num_args == 1 && ret_val > max) + ret_val = max; + return ret_val; } Modified: lldb/trunk/scripts/interface/SBValue.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBValue.i?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/scripts/interface/SBValue.i (original) +++ lldb/trunk/scripts/interface/SBValue.i Wed Oct 21 14:28:08 2015 @@ -238,7 +238,7 @@ public: GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic); - + lldb::SBValue CreateChildAtOffset (const char *name, uint32_t offset, lldb::SBType type); @@ -321,6 +321,21 @@ public: uint32_t GetNumChildren (); + %feature("doctstring", " + //------------------------------------------------------------------ + /// Returns the number for children. + /// + /// @param[in] max + /// If max is less the lldb.UINT32_MAX, then the returned value is + /// capped to max. + /// + /// @return + /// An integer value capped to the argument max. + //------------------------------------------------------------------ + ") GetNumChildren; + uint32_t + GetNumChildren (uint32_t max); + void * GetOpaqueType(); Modified: lldb/trunk/source/API/SBValue.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/source/API/SBValue.cpp (original) +++ lldb/trunk/source/API/SBValue.cpp Wed Oct 21 14:28:08 2015 @@ -1266,22 +1266,27 @@ SBValue::IsRuntimeSupportValue () uint32_t SBValue::GetNumChildren () { + return GetNumChildren (UINT32_MAX); +} + +uint32_t +SBValue::GetNumChildren (uint32_t max) +{ uint32_t num_children = 0; Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); ValueLocker locker; lldb::ValueObjectSP value_sp(GetSP(locker)); if (value_sp) - num_children = value_sp->GetNumChildren(); + num_children = value_sp->GetNumChildren(max); if (log) - log->Printf ("SBValue(%p)::GetNumChildren () => %u", - static_cast<void*>(value_sp.get()), num_children); + log->Printf ("SBValue(%p)::GetNumChildren (%u) => %u", + static_cast<void*>(value_sp.get()), max, num_children); return num_children; } - SBValue SBValue::Dereference () { Modified: lldb/trunk/source/API/SystemInitializerFull.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SystemInitializerFull.cpp?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/source/API/SystemInitializerFull.cpp (original) +++ lldb/trunk/source/API/SystemInitializerFull.cpp Wed Oct 21 14:28:08 2015 @@ -149,7 +149,7 @@ LLDBSWIGPythonCallThreadPlan (void *impl bool &got_error); extern "C" size_t -LLDBSwigPython_CalculateNumChildren (void *implementor); +LLDBSwigPython_CalculateNumChildren (void *implementor, uint32_t max); extern "C" void * LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx); Modified: lldb/trunk/source/Core/ValueObject.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObject.cpp (original) +++ lldb/trunk/source/Core/ValueObject.cpp Wed Oct 21 14:28:08 2015 @@ -770,9 +770,21 @@ ValueObject::GetChildMemberWithName (con size_t -ValueObject::GetNumChildren () +ValueObject::GetNumChildren (uint32_t max) { UpdateValueIfNeeded(); + + if (max < UINT32_MAX) + { + if (m_children_count_valid) + { + size_t children_count = m_children.GetChildrenCount(); + return children_count <= max ? children_count : max; + } + else + return CalculateNumChildren(max); + } + if (!m_children_count_valid) { SetNumChildren (CalculateNumChildren()); Modified: lldb/trunk/source/Core/ValueObjectCast.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectCast.cpp?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObjectCast.cpp (original) +++ lldb/trunk/source/Core/ValueObjectCast.cpp Wed Oct 21 14:28:08 2015 @@ -68,9 +68,10 @@ ValueObjectCast::GetCompilerTypeImpl () } size_t -ValueObjectCast::CalculateNumChildren() +ValueObjectCast::CalculateNumChildren(uint32_t max) { - return GetCompilerType().GetNumChildren (true); + auto children_count = GetCompilerType().GetNumChildren (true); + return children_count <= max ? children_count : max; } uint64_t Modified: lldb/trunk/source/Core/ValueObjectChild.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectChild.cpp?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObjectChild.cpp (original) +++ lldb/trunk/source/Core/ValueObjectChild.cpp Wed Oct 21 14:28:08 2015 @@ -62,9 +62,10 @@ ValueObjectChild::GetValueType() const } size_t -ValueObjectChild::CalculateNumChildren() +ValueObjectChild::CalculateNumChildren(uint32_t max) { - return GetCompilerType().GetNumChildren (true); + auto children_count = GetCompilerType().GetNumChildren (true); + return children_count <= max ? children_count : max; } static void Modified: lldb/trunk/source/Core/ValueObjectConstResult.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectConstResult.cpp?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObjectConstResult.cpp (original) +++ lldb/trunk/source/Core/ValueObjectConstResult.cpp Wed Oct 21 14:28:08 2015 @@ -270,9 +270,10 @@ ValueObjectConstResult::SetByteSize (siz } size_t -ValueObjectConstResult::CalculateNumChildren() +ValueObjectConstResult::CalculateNumChildren(uint32_t max) { - return GetCompilerType().GetNumChildren (true); + auto children_count = GetCompilerType().GetNumChildren (true); + return children_count <= max ? children_count : max; } ConstString Modified: lldb/trunk/source/Core/ValueObjectDynamicValue.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectDynamicValue.cpp?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObjectDynamicValue.cpp (original) +++ lldb/trunk/source/Core/ValueObjectDynamicValue.cpp Wed Oct 21 14:28:08 2015 @@ -113,13 +113,16 @@ ValueObjectDynamicValue::GetDisplayTypeN } size_t -ValueObjectDynamicValue::CalculateNumChildren() +ValueObjectDynamicValue::CalculateNumChildren(uint32_t max) { const bool success = UpdateValueIfNeeded(false); if (success && m_dynamic_type_info.HasType()) - return GetCompilerType().GetNumChildren (true); + { + auto children_count = GetCompilerType().GetNumChildren (true); + return children_count <= max ? children_count : max; + } else - return m_parent->GetNumChildren(); + return m_parent->GetNumChildren(max); } uint64_t Modified: lldb/trunk/source/Core/ValueObjectMemory.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectMemory.cpp?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObjectMemory.cpp (original) +++ lldb/trunk/source/Core/ValueObjectMemory.cpp Wed Oct 21 14:28:08 2015 @@ -156,12 +156,17 @@ ValueObjectMemory::GetDisplayTypeName() } size_t -ValueObjectMemory::CalculateNumChildren() +ValueObjectMemory::CalculateNumChildren(uint32_t max) { if (m_type_sp) - return m_type_sp->GetNumChildren(true); + { + auto child_count = m_type_sp->GetNumChildren(true); + return child_count <= max ? child_count : max; + } + const bool omit_empty_base_classes = true; - return m_compiler_type.GetNumChildren (omit_empty_base_classes); + auto child_count = m_compiler_type.GetNumChildren (omit_empty_base_classes); + return child_count <= max ? child_count : max; } uint64_t Modified: lldb/trunk/source/Core/ValueObjectRegister.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectRegister.cpp?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObjectRegister.cpp (original) +++ lldb/trunk/source/Core/ValueObjectRegister.cpp Wed Oct 21 14:28:08 2015 @@ -67,9 +67,10 @@ ValueObjectRegisterContext::GetQualified } size_t -ValueObjectRegisterContext::CalculateNumChildren() +ValueObjectRegisterContext::CalculateNumChildren(uint32_t max) { - return m_reg_ctx_sp->GetRegisterSetCount(); + auto reg_set_count = m_reg_ctx_sp->GetRegisterSetCount(); + return reg_set_count <= max ? reg_set_count : max; } uint64_t @@ -163,11 +164,14 @@ ValueObjectRegisterSet::GetQualifiedType } size_t -ValueObjectRegisterSet::CalculateNumChildren() +ValueObjectRegisterSet::CalculateNumChildren(uint32_t max) { const RegisterSet *reg_set = m_reg_ctx_sp->GetRegisterSet(m_reg_set_idx); if (reg_set) - return reg_set->num_registers; + { + auto reg_count = reg_set->num_registers; + return reg_count <= max ? reg_count : max; + } return 0; } @@ -338,9 +342,10 @@ ValueObjectRegister::GetTypeName() } size_t -ValueObjectRegister::CalculateNumChildren() +ValueObjectRegister::CalculateNumChildren(uint32_t max) { - return GetCompilerType().GetNumChildren(true); + auto children_count = GetCompilerType().GetNumChildren (true); + return children_count <= max ? children_count : max; } uint64_t Modified: lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp (original) +++ lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp Wed Oct 21 14:28:08 2015 @@ -26,7 +26,7 @@ public: {} size_t - CalculateNumChildren() + CalculateNumChildren () { return m_backend.GetNumChildren(); } @@ -36,7 +36,7 @@ public: { return m_backend.GetChildAtIndex(idx, true); } - + size_t GetIndexOfChildWithName (const ConstString &name) { @@ -107,12 +107,16 @@ ValueObjectSynthetic::GetDisplayTypeName } size_t -ValueObjectSynthetic::CalculateNumChildren() +ValueObjectSynthetic::CalculateNumChildren(uint32_t max) { UpdateValueIfNeeded(); if (m_synthetic_children_count < UINT32_MAX) - return m_synthetic_children_count; - return (m_synthetic_children_count = m_synth_filter_ap->CalculateNumChildren()); + return m_synthetic_children_count <= max ? m_synthetic_children_count : max; + + if (max < UINT32_MAX) + return m_synth_filter_ap->CalculateNumChildren(max); + else + return (m_synthetic_children_count = m_synth_filter_ap->CalculateNumChildren(max)); } lldb::ValueObjectSP Modified: lldb/trunk/source/Core/ValueObjectVariable.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectVariable.cpp?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObjectVariable.cpp (original) +++ lldb/trunk/source/Core/ValueObjectVariable.cpp Wed Oct 21 14:28:08 2015 @@ -91,7 +91,7 @@ ValueObjectVariable::GetQualifiedTypeNam } size_t -ValueObjectVariable::CalculateNumChildren() +ValueObjectVariable::CalculateNumChildren(uint32_t max) { CompilerType type(GetCompilerType()); @@ -99,7 +99,8 @@ ValueObjectVariable::CalculateNumChildre return 0; const bool omit_empty_base_classes = true; - return type.GetNumChildren(omit_empty_base_classes); + auto child_count = type.GetNumChildren(omit_empty_base_classes); + return child_count <= max ? child_count : max; } uint64_t Modified: lldb/trunk/source/DataFormatters/TypeSynthetic.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/TypeSynthetic.cpp?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/source/DataFormatters/TypeSynthetic.cpp (original) +++ lldb/trunk/source/DataFormatters/TypeSynthetic.cpp Wed Oct 21 14:28:08 2015 @@ -200,7 +200,15 @@ ScriptedSyntheticChildren::FrontEnd::Cal { if (!m_wrapper_sp || m_interpreter == NULL) return 0; - return m_interpreter->CalculateNumChildren(m_wrapper_sp); + return m_interpreter->CalculateNumChildren(m_wrapper_sp, UINT32_MAX); +} + +size_t +ScriptedSyntheticChildren::FrontEnd::CalculateNumChildren (uint32_t max) +{ + if (!m_wrapper_sp || m_interpreter == NULL) + return 0; + return m_interpreter->CalculateNumChildren(m_wrapper_sp, max); } bool Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (original) +++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp Wed Oct 21 14:28:08 2015 @@ -2199,7 +2199,7 @@ ScriptInterpreterPython::WatchpointCallb } size_t -ScriptInterpreterPython::CalculateNumChildren(const StructuredData::ObjectSP &implementor_sp) +ScriptInterpreterPython::CalculateNumChildren(const StructuredData::ObjectSP &implementor_sp, uint32_t max) { if (!implementor_sp) return 0; @@ -2217,7 +2217,7 @@ ScriptInterpreterPython::CalculateNumChi { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = g_swig_calc_children (implementor); + ret_val = g_swig_calc_children (implementor, max); } return ret_val; Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h (original) +++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h Wed Oct 21 14:28:08 2015 @@ -73,7 +73,7 @@ public: const char *session_dictionary_name, const lldb::ProcessSP& process_sp); - typedef size_t (*SWIGPythonCalculateNumChildren) (void *implementor); + typedef size_t (*SWIGPythonCalculateNumChildren) (void *implementor, uint32_t max); typedef void* (*SWIGPythonGetChildAtIndex) (void *implementor, uint32_t idx); typedef int (*SWIGPythonGetIndexOfChildWithName) (void *implementor, const char* child_name); typedef void* (*SWIGPythonCastPyObjectToSBValue) (void* data); @@ -200,7 +200,7 @@ public: StructuredData::DictionarySP GetDynamicSettings(StructuredData::ObjectSP plugin_module_sp, Target *target, const char *setting_name, lldb_private::Error &error) override; - size_t CalculateNumChildren(const StructuredData::ObjectSP &implementor) override; + size_t CalculateNumChildren(const StructuredData::ObjectSP &implementor, uint32_t max) override; lldb::ValueObjectSP GetChildAtIndex(const StructuredData::ObjectSP &implementor, uint32_t idx) override; Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py (original) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py Wed Oct 21 14:28:08 2015 @@ -66,6 +66,7 @@ class DataFormatterSynthValueTestCase(Te # now set up the synth self.runCmd("script from myIntSynthProvider import *") self.runCmd("type synth add -l myIntSynthProvider myInt") + self.runCmd("type synth add -l myArraySynthProvider myArray") if self.TraceOn(): print "x_val = %s; y_val = %s; z_val = %s" % (x_val(),y_val(),z_val()) @@ -85,6 +86,12 @@ class DataFormatterSynthValueTestCase(Te hi = self.frame().FindVariable("hi") self.assertEqual(hi.GetSummary(), "42") + ma = self.frame().FindVariable("ma") + self.assertTrue(ma.IsValid()) + self.assertEqual(ma.GetNumChildren(15), 15) + self.assertEqual(ma.GetNumChildren(16), 16) + self.assertEqual(ma.GetNumChildren(17), 16) + if __name__ == '__main__': import atexit lldb.SBDebugger.Initialize() Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/main.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/main.cpp?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/main.cpp (original) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/main.cpp Wed Oct 21 14:28:08 2015 @@ -5,6 +5,11 @@ class myInt { int val() { return theValue; } }; +class myArray { +public: + int array[16]; +}; + class hasAnInt { public: myInt theInt; @@ -18,5 +23,7 @@ int main() { myInt y{4}; myInt z {x+y}; hasAnInt hi; + myArray ma; + return z.val(); // break here } Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/myIntSynthProvider.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/myIntSynthProvider.py?rev=250930&r1=250929&r2=250930&view=diff ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/myIntSynthProvider.py (original) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-synthval/myIntSynthProvider.py Wed Oct 21 14:28:08 2015 @@ -15,3 +15,22 @@ class myIntSynthProvider(object): def get_value(self): return self.val + +class myArraySynthProvider(object): + def __init__(self, valobj, dict): + self.valobj = valobj + self.array = self.valobj.GetChildMemberWithName("array") + + def num_children(self, max_count): + if 16 < max_count: + return 16 + return max_count + + def get_child_at_index(self, index): + return None # Keep it simple when this is not tested here. + + def get_child_index(self, name): + return None # Keep it simple when this is not tested here. + + def has_children(self): + return True _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits