Author: tberghammer Date: Fri Mar 31 15:48:00 2017 New Revision: 299259 URL: http://llvm.org/viewvc/llvm-project?rev=299259&view=rev Log: Stop calling ValueObject::SetName from synthetic child providers
Summary: Calling ValueObject::SetName from a sythetic child provider would change the underying value object used for the non-synthetic child as well what is clearly unintentional. Reviewers: jingham, labath Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D31371 Modified: lldb/trunk/include/lldb/Core/ValueObject.h lldb/trunk/source/Core/ValueObject.cpp lldb/trunk/source/DataFormatters/VectorType.cpp lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp Modified: lldb/trunk/include/lldb/Core/ValueObject.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=299259&r1=299258&r2=299259&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObject.h (original) +++ lldb/trunk/include/lldb/Core/ValueObject.h Fri Mar 31 15:48:00 2017 @@ -553,6 +553,9 @@ public: lldb::ValueObjectSP GetSP() { return m_manager->GetSharedPointer(this); } + // Change the name of the current ValueObject. Should *not* be used from a + // synthetic child provider as it would change the name of the non synthetic + // child as well. void SetName(const ConstString &name); virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address = true, @@ -601,6 +604,12 @@ public: virtual lldb::ValueObjectSP Dereference(Error &error); + // Creates a copy of the ValueObject with a new name and setting the current + // ValueObject as its parent. It should be used when we want to change the + // name of a ValueObject without modifying the actual ValueObject itself + // (e.g. sythetic child provider). + virtual lldb::ValueObjectSP Clone(const ConstString &new_name); + virtual lldb::ValueObjectSP AddressOf(Error &error); virtual lldb::addr_t GetLiveAddress() { return LLDB_INVALID_ADDRESS; } Modified: lldb/trunk/source/Core/ValueObject.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=299259&r1=299258&r2=299259&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObject.cpp (original) +++ lldb/trunk/source/Core/ValueObject.cpp Fri Mar 31 15:48:00 2017 @@ -2962,6 +2962,10 @@ ValueObjectSP ValueObject::Cast(const Co return ValueObjectCast::Create(*this, GetName(), compiler_type); } +lldb::ValueObjectSP ValueObject::Clone(const ConstString &new_name) { + return ValueObjectCast::Create(*this, new_name, GetCompilerType()); +} + ValueObjectSP ValueObject::CastPointerType(const char *name, CompilerType &compiler_type) { ValueObjectSP valobj_sp; Modified: lldb/trunk/source/DataFormatters/VectorType.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/VectorType.cpp?rev=299259&r1=299258&r2=299259&view=diff ============================================================================== --- lldb/trunk/source/DataFormatters/VectorType.cpp (original) +++ lldb/trunk/source/DataFormatters/VectorType.cpp Fri Mar 31 15:48:00 2017 @@ -204,14 +204,12 @@ public: if (idx >= CalculateNumChildren()) return lldb::ValueObjectSP(); auto offset = idx * m_child_type.GetByteSize(nullptr); - ValueObjectSP child_sp( - m_backend.GetSyntheticChildAtOffset(offset, m_child_type, true)); - if (!child_sp) - return child_sp; - StreamString idx_name; idx_name.Printf("[%" PRIu64 "]", (uint64_t)idx); - child_sp->SetName(ConstString(idx_name.GetString())); + ValueObjectSP child_sp(m_backend.GetSyntheticChildAtOffset( + offset, m_child_type, true, ConstString(idx_name.GetString()))); + if (!child_sp) + return child_sp; child_sp->SetFormat(m_item_format); Modified: lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp?rev=299259&r1=299258&r2=299259&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp (original) +++ lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp Fri Mar 31 15:48:00 2017 @@ -406,7 +406,7 @@ lldb_private::formatters::LibcxxStdMapSy case 1: { auto child0_sp = potential_child_sp->GetChildAtIndex(0, true); if (child0_sp && child0_sp->GetName() == g___cc) - potential_child_sp = child0_sp; + potential_child_sp = child0_sp->Clone(ConstString(name.GetString())); break; } case 2: { @@ -414,11 +414,10 @@ lldb_private::formatters::LibcxxStdMapSy auto child1_sp = potential_child_sp->GetChildAtIndex(1, true); if (child0_sp && child0_sp->GetName() == g___cc && child1_sp && child1_sp->GetName() == g___nc) - potential_child_sp = child0_sp; + potential_child_sp = child0_sp->Clone(ConstString(name.GetString())); break; } } - potential_child_sp->SetName(ConstString(name.GetString())); } m_iterators[idx] = iterator; return potential_child_sp; Modified: lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp?rev=299259&r1=299258&r2=299259&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp (original) +++ lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp Fri Mar 31 15:48:00 2017 @@ -73,9 +73,7 @@ bool LibStdcppTupleSyntheticFrontEnd::Up if (value_sp) { StreamString name; name.Printf("[%zd]", m_members.size()); - value_sp->SetName(ConstString(name.GetString())); - - m_members.push_back(value_sp); + m_members.push_back(value_sp->Clone(ConstString(name.GetString()))); } } } Modified: lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp?rev=299259&r1=299258&r2=299259&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp (original) +++ lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp Fri Mar 31 15:48:00 2017 @@ -70,19 +70,19 @@ bool LibStdcppUniquePtrSyntheticFrontEnd std::unique_ptr<SyntheticChildrenFrontEnd> tuple_frontend( LibStdcppTupleSyntheticFrontEndCreator(nullptr, tuple_sp)); - m_ptr_obj = tuple_frontend->GetChildAtIndex(0); - if (m_ptr_obj) - m_ptr_obj->SetName(ConstString("pointer")); + ValueObjectSP ptr_obj = tuple_frontend->GetChildAtIndex(0); + if (ptr_obj) + m_ptr_obj = ptr_obj->Clone(ConstString("pointer")); - m_del_obj = tuple_frontend->GetChildAtIndex(1); - if (m_del_obj) - m_del_obj->SetName(ConstString("deleter")); + ValueObjectSP del_obj = tuple_frontend->GetChildAtIndex(1); + if (del_obj) + m_del_obj = del_obj->Clone(ConstString("deleter")); if (m_ptr_obj) { Error error; - m_obj_obj = m_ptr_obj->Dereference(error); + ValueObjectSP obj_obj = m_ptr_obj->Dereference(error); if (error.Success()) { - m_obj_obj->SetName(ConstString("object")); + m_obj_obj = obj_obj->Clone(ConstString("object")); } } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits