Skip to content

Commit

Permalink
[lldb] Default can_create to true in GetChildAtIndex (NFC)
Browse files Browse the repository at this point in the history
Existing callers of `GetChildAtIndex` pass true for can_create. This change
makes true the default value, callers don't have to pass an opaque true.

See also D151966 for the same change to `GetChildMemberWithName`.

Differential Revision: https://reviews.llvm.org/D152031
  • Loading branch information
kastiglione committed Jun 13, 2023
1 parent 53e3380 commit a1a74f7
Show file tree
Hide file tree
Showing 26 changed files with 56 additions and 56 deletions.
3 changes: 2 additions & 1 deletion lldb/include/lldb/Core/ValueObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ class ValueObject {
/// Returns a unique id for this ValueObject.
lldb::user_id_t GetID() const { return m_id.GetID(); }

virtual lldb::ValueObjectSP GetChildAtIndex(size_t idx, bool can_create);
virtual lldb::ValueObjectSP GetChildAtIndex(size_t idx,
bool can_create = true);

// this will always create the children if necessary
lldb::ValueObjectSP GetChildAtIndexPath(llvm::ArrayRef<size_t> idxs,
Expand Down
3 changes: 2 additions & 1 deletion lldb/include/lldb/Core/ValueObjectSyntheticFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class ValueObjectSynthetic : public ValueObject {

lldb::ValueType GetValueType() const override;

lldb::ValueObjectSP GetChildAtIndex(size_t idx, bool can_create) override;
lldb::ValueObjectSP GetChildAtIndex(size_t idx,
bool can_create = true) override;

lldb::ValueObjectSP GetChildMemberWithName(llvm::StringRef name,
bool can_create = true) override;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/API/SBValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ SBValue SBValue::GetChildAtIndex(uint32_t idx,
lldb::ValueObjectSP value_sp(GetSP(locker));
if (value_sp) {
const bool can_create = true;
child_sp = value_sp->GetChildAtIndex(idx, can_create);
child_sp = value_sp->GetChildAtIndex(idx);
if (can_create_synthetic && !child_sp) {
child_sp = value_sp->GetSyntheticArrayMember(idx, can_create);
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/IOHandlerCursesGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4522,7 +4522,7 @@ struct Row {
if (valobj) {
const size_t num_children = valobj->GetNumChildren();
for (size_t i = 0; i < num_children; ++i) {
children.push_back(Row(valobj->GetChildAtIndex(i, true), this));
children.push_back(Row(valobj->GetChildAtIndex(i), this));
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions lldb/source/Core/ValueObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ ValueObject::GetChildAtIndexPath(llvm::ArrayRef<size_t> idxs,
return GetSP();
ValueObjectSP root(GetSP());
for (size_t idx : idxs) {
root = root->GetChildAtIndex(idx, true);
root = root->GetChildAtIndex(idx);
if (!root) {
if (index_of_error)
*index_of_error = idx;
Expand Down Expand Up @@ -697,7 +697,7 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx,
return 0;
return pointee_sp->GetData(data, error);
} else {
ValueObjectSP child_sp = GetChildAtIndex(0, true);
ValueObjectSP child_sp = GetChildAtIndex(0);
if (child_sp.get() == nullptr)
return 0;
Status error;
Expand Down Expand Up @@ -1236,7 +1236,7 @@ bool ValueObject::DumpPrintableRepresentation(
if (low)
s << ',';

ValueObjectSP child = GetChildAtIndex(low, true);
ValueObjectSP child = GetChildAtIndex(low);
if (!child.get()) {
s << "<invalid child>";
continue;
Expand Down Expand Up @@ -1277,7 +1277,7 @@ bool ValueObject::DumpPrintableRepresentation(
if (low)
s << ',';

ValueObjectSP child = GetChildAtIndex(low, true);
ValueObjectSP child = GetChildAtIndex(low);
if (!child.get()) {
s << "<invalid child>";
continue;
Expand Down Expand Up @@ -2367,14 +2367,14 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl(

// from here on we do have a valid index
if (root_compiler_type_info.Test(eTypeIsArray)) {
ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index);
if (!child_valobj_sp)
child_valobj_sp = root->GetSyntheticArrayMember(index, true);
if (!child_valobj_sp)
if (root->HasSyntheticValue() &&
root->GetSyntheticValue()->GetNumChildren() > index)
child_valobj_sp =
root->GetSyntheticValue()->GetChildAtIndex(index, true);
root->GetSyntheticValue()->GetChildAtIndex(index);
if (child_valobj_sp) {
root = child_valobj_sp;
remainder =
Expand Down Expand Up @@ -2422,7 +2422,7 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl(
options.m_synthetic_children_traversal ==
GetValueForExpressionPathOptions::
SyntheticChildrenTraversal::Both)) {
root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
root = root->GetSyntheticValue()->GetChildAtIndex(index);
} else
root = root->GetSyntheticArrayMember(index, true);
if (!root) {
Expand Down Expand Up @@ -2453,7 +2453,7 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl(
return root;
}
} else if (root_compiler_type_info.Test(eTypeIsVector)) {
root = root->GetChildAtIndex(index, true);
root = root->GetChildAtIndex(index);
if (!root) {
*reason_to_stop =
ValueObject::eExpressionPathScanEndReasonNoSuchChild;
Expand Down Expand Up @@ -2488,7 +2488,7 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl(
*final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
return nullptr;
}
root = root->GetChildAtIndex(index, true);
root = root->GetChildAtIndex(index);
if (!root) {
*reason_to_stop =
ValueObject::eExpressionPathScanEndReasonNoSuchChild;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/ValueObjectSyntheticFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DummySyntheticFrontEnd : public SyntheticChildrenFrontEnd {
size_t CalculateNumChildren() override { return m_backend.GetNumChildren(); }

lldb::ValueObjectSP GetChildAtIndex(size_t idx) override {
return m_backend.GetChildAtIndex(idx, true);
return m_backend.GetChildAtIndex(idx);
}

size_t GetIndexOfChildWithName(ConstString name) override {
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/DataFormatters/FormatManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ bool FormatManager::ShouldPrintAsOneLiner(ValueObject &valobj) {

for (size_t idx = 0; idx < valobj.GetNumChildren(); idx++) {
bool is_synth_val = false;
ValueObjectSP child_sp(valobj.GetChildAtIndex(idx, true));
ValueObjectSP child_sp(valobj.GetChildAtIndex(idx));
// something is wrong here - bail out
if (!child_sp)
return false;
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/DataFormatters/ValueObjectPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ ValueObjectSP ValueObjectPrinter::GenerateChild(ValueObject *synth_valobj,
true);
} else {
// otherwise, do the usual thing
return synth_valobj->GetChildAtIndex(idx, true);
return synth_valobj->GetChildAtIndex(idx);
}
}

Expand Down Expand Up @@ -759,7 +759,7 @@ bool ValueObjectPrinter::PrintChildrenOneLiner(bool hide_names) {

bool did_print_children = false;
for (uint32_t idx = 0; idx < num_children; ++idx) {
lldb::ValueObjectSP child_sp(synth_m_valobj->GetChildAtIndex(idx, true));
lldb::ValueObjectSP child_sp(synth_m_valobj->GetChildAtIndex(idx));
if (child_sp)
child_sp = child_sp->GetQualifiedRepresentationIfAvailable(
m_options.m_use_dynamic, m_options.m_use_synthetic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void AddLambdaCaptureDecls(StreamString &stream, StackFrame *frame,
if (auto thisValSP = ClangExpressionUtil::GetLambdaValueObject(frame)) {
uint32_t numChildren = thisValSP->GetNumChildren();
for (uint32_t i = 0; i < numChildren; ++i) {
auto childVal = thisValSP->GetChildAtIndex(i, true);
auto childVal = thisValSP->GetChildAtIndex(i);
ConstString childName(childVal ? childVal->GetName() : ConstString(""));

if (!childName.IsEmpty() && verifier.hasToken(childName.GetStringRef()) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ CreateStackTrace(ValueObjectSP o,
size_t count = trace_value_object->GetNumChildren();
for (size_t j = 0; j < count; j++) {
addr_t trace_addr =
trace_value_object->GetChildAtIndex(j, true)->GetValueAsUnsigned(0);
trace_value_object->GetChildAtIndex(j)->GetValueAsUnsigned(0);
if (trace_addr == 0)
break;
trace_sp->AddIntegerItem(trace_addr);
Expand All @@ -235,7 +235,7 @@ static StructuredData::ArraySP ConvertToStructuredArray(
ValueObjectSP objects =
return_value_sp->GetValueForExpressionPath(items_name.c_str());
for (unsigned int i = 0; i < count; i++) {
ValueObjectSP o = objects->GetChildAtIndex(i, true);
ValueObjectSP o = objects->GetChildAtIndex(i);
auto dict_sp = std::make_shared<StructuredData::Dictionary>();

callback(o, dict_sp);
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static lldb::addr_t GetCoroFramePtrFromHandle(ValueObjectSP valobj_sp) {
// We don't care about its name.
if (valobj_sp->GetNumChildren() != 1)
return LLDB_INVALID_ADDRESS;
ValueObjectSP ptr_sp(valobj_sp->GetChildAtIndex(0, true));
ValueObjectSP ptr_sp(valobj_sp->GetChildAtIndex(0));
if (!ptr_sp)
return LLDB_INVALID_ADDRESS;
if (!ptr_sp->GetCompilerType().IsPointerType())
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Language/CPlusPlus/GenericBitset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ ValueObjectSP GenericBitsetFrontEnd::GetChildAtIndex(size_t idx) {
type.GetBitSize(ctx.GetBestExecutionContextScope());
if (!bit_size || *bit_size == 0)
return {};
chunk = m_first->GetChildAtIndex(idx / *bit_size, true);
chunk = m_first->GetChildAtIndex(idx / *bit_size);
} else {
type = m_first->GetCompilerType();
chunk = m_first->GetSP();
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ ValueObjectSP GenericOptionalFrontend::GetChildAtIndex(size_t _idx) {
// at the parent itself. We can obtain the parent through __engaged_.
val_sp = m_backend.GetChildMemberWithName("__engaged_")
->GetParent()
->GetChildAtIndex(0, true)
->GetChildAtIndex(0)
->GetChildMemberWithName("__val_");
else if (m_stdlib == StdLib::LibStdcpp) {
val_sp = m_backend.GetChildMemberWithName("_M_payload")
Expand Down
17 changes: 8 additions & 9 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ lldb::ValueObjectSP
lldb_private::formatters::GetFirstValueOfLibCXXCompressedPair(
ValueObject &pair) {
ValueObjectSP value;
ValueObjectSP first_child = pair.GetChildAtIndex(0, true);
ValueObjectSP first_child = pair.GetChildAtIndex(0);
if (first_child)
value = first_child->GetChildMemberWithName("__value_");
if (!value) {
Expand All @@ -65,7 +65,7 @@ lldb_private::formatters::GetSecondValueOfLibCXXCompressedPair(
ValueObject &pair) {
ValueObjectSP value;
if (pair.GetNumChildren() > 1) {
ValueObjectSP second_child = pair.GetChildAtIndex(1, true);
ValueObjectSP second_child = pair.GetChildAtIndex(1);
if (second_child) {
value = second_child->GetChildMemberWithName("__value_");
}
Expand Down Expand Up @@ -364,7 +364,7 @@ bool lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::Update() {
"pair", extractor, valobj_sp->GetExecutionContextRef(),
tree_node_type);
if (pair_sp)
m_pair_sp = pair_sp->GetChildAtIndex(4, true);
m_pair_sp = pair_sp->GetChildAtIndex(4);
}
}
}
Expand All @@ -381,9 +381,9 @@ lldb::ValueObjectSP
lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::GetChildAtIndex(
size_t idx) {
if (m_pair_ptr)
return m_pair_ptr->GetChildAtIndex(idx, true);
return m_pair_ptr->GetChildAtIndex(idx);
if (m_pair_sp)
return m_pair_sp->GetChildAtIndex(idx, true);
return m_pair_sp->GetChildAtIndex(idx);
return lldb::ValueObjectSP();
}

Expand Down Expand Up @@ -524,7 +524,7 @@ bool lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd::
auto pair_sp = CreateValueObjectFromData(
"pair", extractor, valobj_sp->GetExecutionContextRef(), tree_node_type);
if (pair_sp)
m_pair_sp = pair_sp->GetChildAtIndex(2, true);
m_pair_sp = pair_sp->GetChildAtIndex(2);
}

return false;
Expand All @@ -538,7 +538,7 @@ size_t lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd::
lldb::ValueObjectSP lldb_private::formatters::
LibCxxUnorderedMapIteratorSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
if (m_pair_sp)
return m_pair_sp->GetChildAtIndex(idx, true);
return m_pair_sp->GetChildAtIndex(idx);
return lldb::ValueObjectSP();
}

Expand Down Expand Up @@ -775,8 +775,7 @@ ExtractLibcxxStringInfo(ValueObject &valobj) {

// __r_ is a compressed_pair of the actual data and the allocator. The data we
// want is in the first base class.
ValueObjectSP valobj_r_base_sp =
valobj_r_sp->GetChildAtIndex(0, /*can_create=*/true);
ValueObjectSP valobj_r_base_sp = valobj_r_sp->GetChildAtIndex(0);
if (!valobj_r_base_sp)
return {};

Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ ValueObjectSP ForwardListFrontEnd::GetChildAtIndex(size_t idx) {
if (!current_sp)
return nullptr;

current_sp = current_sp->GetChildAtIndex(1, true); // get the __value_ child
current_sp = current_sp->GetChildAtIndex(1); // get the __value_ child
if (!current_sp)
return nullptr;

Expand Down Expand Up @@ -360,7 +360,7 @@ lldb::ValueObjectSP ListFrontEnd::GetChildAtIndex(size_t idx) {
if (!current_sp)
return lldb::ValueObjectSP();

current_sp = current_sp->GetChildAtIndex(1, true); // get the __value_ child
current_sp = current_sp->GetChildAtIndex(1); // get the __value_ child
if (!current_sp)
return lldb::ValueObjectSP();

Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ size_t lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::
break;
case 2: {
// Assume a post llvm r300140 __compressed_pair implementation:
ValueObjectSP first_elem_parent = m_item->GetChildAtIndex(0, true);
ValueObjectSP first_elem_parent = m_item->GetChildAtIndex(0);
m_item = first_elem_parent->GetChildMemberWithName("__value_");
break;
}
Expand Down Expand Up @@ -394,15 +394,15 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex(
if (potential_child_sp) {
switch (potential_child_sp->GetNumChildren()) {
case 1: {
auto child0_sp = potential_child_sp->GetChildAtIndex(0, true);
auto child0_sp = potential_child_sp->GetChildAtIndex(0);
if (child0_sp &&
(child0_sp->GetName() == g_cc_ || child0_sp->GetName() == g_cc))
potential_child_sp = child0_sp->Clone(ConstString(name.GetString()));
break;
}
case 2: {
auto child0_sp = potential_child_sp->GetChildAtIndex(0, true);
auto child1_sp = potential_child_sp->GetChildAtIndex(1, true);
auto child0_sp = potential_child_sp->GetChildAtIndex(0);
auto child1_sp = potential_child_sp->GetChildAtIndex(1);
if (child0_sp &&
(child0_sp->GetName() == g_cc_ || child0_sp->GetName() == g_cc) &&
child1_sp && child1_sp->GetName() == g_nc)
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Language/CPlusPlus/LibCxxQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class QueueFrontEnd : public SyntheticChildrenFrontEnd {
}

ValueObjectSP GetChildAtIndex(size_t idx) override {
return m_container_sp ? m_container_sp->GetChildAtIndex(idx, true)
return m_container_sp ? m_container_sp->GetChildAtIndex(idx)
: nullptr;
}

Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxxTuple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ ValueObjectSP TupleFrontEnd::GetChildAtIndex(size_t idx) {
m_base->GetCompilerType().GetDirectBaseClassAtIndex(idx, nullptr);
if (!holder_type)
return ValueObjectSP();
ValueObjectSP holder_sp = m_base->GetChildAtIndex(idx, true);
ValueObjectSP holder_sp = m_base->GetChildAtIndex(idx);
if (!holder_sp)
return ValueObjectSP();

ValueObjectSP elem_sp = holder_sp->GetChildAtIndex(0, true);
ValueObjectSP elem_sp = holder_sp->GetChildAtIndex(0);
if (elem_sp)
m_elements[idx] =
elem_sp->Clone(ConstString(llvm::formatv("[{0}]", idx).str())).get();
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ lldb::ValueObjectSP lldb_private::formatters::
case 2: {
// Assume a post llvm r300140 __compressed_pair implementation:
ValueObjectSP first_elem_parent_sp =
p1_sp->GetChildAtIndex(0, true);
p1_sp->GetChildAtIndex(0);
first_sp = p1_sp->GetChildMemberWithName("__value_");
break;
}
Expand Down Expand Up @@ -207,7 +207,7 @@ bool lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::
break;
case 2: {
// Assume a post llvm r300140 __compressed_pair implementation:
ValueObjectSP first_elem_parent = p2_sp->GetChildAtIndex(0, true);
ValueObjectSP first_elem_parent = p2_sp->GetChildAtIndex(0);
num_elements_sp = first_elem_parent->GetChildMemberWithName("__value_");
next_path.append({"__p1_", "__value_", "__next_"});
break;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ bool lldb_private::formatters::LibcxxStdVectorSyntheticFrontEnd::Update() {
case 2: {
// Assume a post llvm r300140 __compressed_pair implementation:
ValueObjectSP first_elem_parent_sp =
data_type_finder_sp->GetChildAtIndex(0, true);
data_type_finder_sp->GetChildAtIndex(0);
data_type_finder_sp =
first_elem_parent_sp->GetChildMemberWithName("__value_");
break;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ LibstdcppMapIteratorSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
m_pair_sp = CreateValueObjectFromAddress("pair", m_pair_address,
m_exe_ctx_ref, m_pair_type);
if (m_pair_sp)
return m_pair_sp->GetChildAtIndex(idx, true);
return m_pair_sp->GetChildAtIndex(idx);
}
return lldb::ValueObjectSP();
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool LibStdcppTupleSyntheticFrontEnd::Update() {

size_t child_count = current_child->GetNumChildren();
for (size_t i = 0; i < child_count; ++i) {
ValueObjectSP child_sp = current_child->GetChildAtIndex(i, true);
ValueObjectSP child_sp = current_child->GetChildAtIndex(i);
llvm::StringRef name_str = child_sp->GetName().GetStringRef();
if (name_str.startswith("std::_Tuple_impl<")) {
next_child_sp = child_sp;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Language/ObjC/Cocoa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ bool lldb_private::formatters::ObjCBOOLSummaryProvider(
if (err.Fail() || !real_guy_sp)
return false;
} else if (type_info & eTypeIsReference) {
real_guy_sp = valobj.GetChildAtIndex(0, true);
real_guy_sp = valobj.GetChildAtIndex(0);
if (!real_guy_sp)
return false;
}
Expand Down

0 comments on commit a1a74f7

Please sign in to comment.