From: Tamas Berghammer Date: Fri, 31 Mar 2017 20:48:00 +0000 (+0000) Subject: Stop calling ValueObject::SetName from synthetic child providers X-Git-Tag: llvmorg-5.0.0-rc1~8724 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4fbb55b7b1b87cf22c05e73ce6e8207e25f02205;p=platform%2Fupstream%2Fllvm.git 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 llvm-svn: 299259 --- diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index 63ba328..5016e49 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -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; } diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index 1c504a2..970a8dc 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -2962,6 +2962,10 @@ ValueObjectSP ValueObject::Cast(const CompilerType &compiler_type) { 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; diff --git a/lldb/source/DataFormatters/VectorType.cpp b/lldb/source/DataFormatters/VectorType.cpp index 652bde7..4fb92ca 100644 --- a/lldb/source/DataFormatters/VectorType.cpp +++ b/lldb/source/DataFormatters/VectorType.cpp @@ -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); diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp index 9a94e12..50d4510 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp @@ -406,7 +406,7 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex( 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::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex( 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; diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp index 7537a82..943af6e 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp @@ -73,9 +73,7 @@ bool LibStdcppTupleSyntheticFrontEnd::Update() { 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()))); } } } diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp index 8d7ce65..7693961 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp @@ -70,19 +70,19 @@ bool LibStdcppUniquePtrSyntheticFrontEnd::Update() { std::unique_ptr 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")); } }