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
This commit is contained in:
Tamas Berghammer 2017-03-31 20:48:00 +00:00
parent b326411fdc
commit 4fbb55b7b1
6 changed files with 28 additions and 20 deletions

View File

@ -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; }

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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())));
}
}
}

View File

@ -70,19 +70,19 @@ bool LibStdcppUniquePtrSyntheticFrontEnd::Update() {
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"));
}
}