[lldb] Default can_create to true in GetChildAtIndex (NFC)

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
This commit is contained in:
Dave Lee 2023-05-28 19:16:49 -07:00
parent 53e3380786
commit a1a74f7cde
26 changed files with 56 additions and 56 deletions

View File

@ -469,7 +469,8 @@ public:
/// 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,

View File

@ -51,7 +51,8 @@ public:
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;

View File

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

View File

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

View File

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

View File

@ -34,7 +34,7 @@ public:
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 {

View File

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

View File

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

View File

@ -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()) &&

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -33,7 +33,7 @@ public:
}
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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -540,7 +540,7 @@ ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException(
};
for (size_t idx = 0; idx < reserved_dict->GetNumChildren(); idx++) {
ValueObjectSP dict_entry = reserved_dict->GetChildAtIndex(idx, true);
ValueObjectSP dict_entry = reserved_dict->GetChildAtIndex(idx);
DataExtractor data;
data.SetAddressByteSize(dict_entry->GetProcessSP()->GetAddressByteSize());

View File

@ -120,7 +120,7 @@ static void CreateHistoryThreadFromValueObject(ProcessSP process_sp,
std::vector<lldb::addr_t> pcs;
for (int i = 0; i < count; i++) {
addr_t pc = trace_sp->GetChildAtIndex(i, true)->GetValueAsUnsigned(0);
addr_t pc = trace_sp->GetChildAtIndex(i)->GetValueAsUnsigned(0);
if (pc == 0 || pc == 1 || pc == LLDB_INVALID_ADDRESS)
continue;
pcs.push_back(pc);

View File

@ -814,7 +814,7 @@ ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
// extract bit low out of it. reading array item low would be done by
// saying arr[low], without a deref * sign
Status error;
ValueObjectSP temp(valobj_sp->GetChildAtIndex(0, true));
ValueObjectSP temp(valobj_sp->GetChildAtIndex(0));
if (error.Fail()) {
valobj_sp->GetExpressionPath(var_expr_path_strm);
error.SetErrorStringWithFormat(
@ -868,7 +868,7 @@ ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
valobj_sp->GetTypeName().AsCString("<invalid type>"),
var_expr_path_strm.GetData());
} else {
child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
child_valobj_sp = synthetic->GetChildAtIndex(child_index);
if (!child_valobj_sp) {
valobj_sp->GetExpressionPath(var_expr_path_strm);
error.SetErrorStringWithFormat(
@ -894,7 +894,7 @@ ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
nullptr, nullptr, &is_incomplete_array)) {
// Pass false to dynamic_value here so we can tell the difference
// between no dynamic value and no member of this type...
child_valobj_sp = valobj_sp->GetChildAtIndex(child_index, true);
child_valobj_sp = valobj_sp->GetChildAtIndex(child_index);
if (!child_valobj_sp && (is_incomplete_array || !no_synth_child))
child_valobj_sp =
valobj_sp->GetSyntheticArrayMember(child_index, true);
@ -940,7 +940,7 @@ ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
valobj_sp->GetTypeName().AsCString("<invalid type>"),
var_expr_path_strm.GetData());
} else {
child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
child_valobj_sp = synthetic->GetChildAtIndex(child_index);
if (!child_valobj_sp) {
valobj_sp->GetExpressionPath(var_expr_path_strm);
error.SetErrorStringWithFormat(
@ -1012,7 +1012,7 @@ ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
// extract bits low thru high out of it. reading array items low thru
// high would be done by saying arr[low-high], without a deref * sign
Status error;
ValueObjectSP temp(valobj_sp->GetChildAtIndex(0, true));
ValueObjectSP temp(valobj_sp->GetChildAtIndex(0));
if (error.Fail()) {
valobj_sp->GetExpressionPath(var_expr_path_strm);
error.SetErrorStringWithFormat(
@ -1400,8 +1400,7 @@ ValueObjectSP GetValueForOffset(StackFrame &frame, ValueObjectSP &parent,
}
for (int ci = 0, ce = parent->GetNumChildren(); ci != ce; ++ci) {
const bool can_create = true;
ValueObjectSP child_sp = parent->GetChildAtIndex(ci, can_create);
ValueObjectSP child_sp = parent->GetChildAtIndex(ci);
if (!child_sp) {
return ValueObjectSP();