Skip to content

[lldb] Upgrade GetIndexOfChildWithName to use llvm::Expected #136693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ StdlibCoroutineHandleSyntheticFrontEnd::GetIndexOfChildWithName(
"'SyntheticChildrenFrontend::StdlibCoroutineHandleSyntheticFrontEnd' "
"cannot find index of child '%s'. (m_resume_ptr_sp='%p', "
"m_destroy_ptr_sp='%p')",
name.AsCString(), static_cast<void *>(m_resume_ptr_sp.get()),
static_cast<void *>(m_destroy_ptr_sp.get()));
name.AsCString(), m_resume_ptr_sp.get(), m_destroy_ptr_sp.get());

if (name == ConstString("resume"))
return 0;
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ ExtractLibcxxStringInfo(ValueObject &valobj) {

auto index_or_err = l->GetIndexOfChildWithName("__data_");
if (!index_or_err) {
LLDB_LOG_ERROR(GetLog(LLDBLog::Types), index_or_err.takeError(), "{0}");
LLDB_LOG_ERROR(GetLog(LLDBLog::DataFormatters), index_or_err.takeError(),
"{0}");
return {};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
if (!m_start) {
return llvm::createStringError(
"'SyntheticChildrenFrontend::LibcxxInitializerListSyntheticFrontEnd' "
"cannot find index of child '%s'",
"cannot find index of child '%s': Invalid start pointer.",
name.AsCString());
}
size_t idx = ExtractIndexFromString(name.GetCString());
Expand Down
5 changes: 2 additions & 3 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,8 @@ lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::
if (!m_pair_sp)
return llvm::createStringError(
"'SyntheticChildrenFrontend::LibCxxMapIteratorSyntheticFrontEnd' "
"cannot find index of child '%s'. Underlying pair is invalid: "
"m_pair_sp=%p",
name.AsCString(), static_cast<void *>(m_pair_sp.get()));
"cannot find index of child '%s': Invalid underlying pair.",
name.AsCString());

return m_pair_sp->GetIndexOfChildWithName(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ lldb_private::formatters::LibcxxStdProxyArraySyntheticFrontEnd::
if (!m_base)
return llvm::createStringError(
"'SyntheticChildrenFrontend::LibcxxStdProxyArraySyntheticFrontEnd' "
"cannot find index of child '%s'",
"cannot find index of child '%s': Invalid base pointer.",
name.AsCString());
size_t idx = ExtractIndexFromString(name.GetCString());
if (idx == UINT32_MAX) {
Expand Down
7 changes: 4 additions & 3 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxxQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ class QueueFrontEnd : public SyntheticChildrenFrontEnd {
llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override {
if (m_container_sp)
return m_container_sp->GetIndexOfChildWithName(name);
return llvm::createStringError("'SyntheticChildrenFrontend::QueueFrontEnd' "
"cannot find index of child '%s'",
name.AsCString());
return llvm::createStringError(
"'SyntheticChildrenFrontend::QueueFrontEnd' "
"cannot find index of child '%s': Invalid underlying container.",
name.AsCString());
}

lldb::ChildCacheState Update() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ lldb_private::formatters::LibcxxStdSliceArraySyntheticFrontEnd::
if (!m_start)
return llvm::createStringError(
"'SyntheticChildrenFrontend::LibcxxStdSliceArraySyntheticFrontEnd' "
"cannot find index of child '%s'",
"cannot find index of child '%s': Invalid start pointer.",
name.AsCString());
size_t idx = ExtractIndexFromString(name.GetCString());
if (idx == UINT32_MAX) {
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Language/CPlusPlus/LibCxxSpan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ llvm::Expected<size_t> lldb_private::formatters::
if (!m_start)
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::LibcxxStdSpanSyntheticFrontEnd' cannot "
"find index of child '%s'",
"find index of child '%s': Invalid start pointer.",
name.AsCString());
size_t idx = ExtractIndexFromString(name.GetCString());
if (idx == UINT32_MAX) {
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxxValarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ lldb_private::formatters::LibcxxStdValarraySyntheticFrontEnd::
if (!m_start || !m_finish)
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::LibcxxStdValarraySyntheticFrontEnd' "
"cannot find index of child '%s'",
name.AsCString());
"cannot find index of child '%s'. (m_start='%d', m_finish='%d')",
name.AsCString(), m_start, m_finish);
size_t idx = ExtractIndexFromString(name.GetCString());
if (idx == UINT32_MAX) {
return llvm::createStringError(
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ lldb_private::formatters::LibcxxStdVectorSyntheticFrontEnd::
if (!m_start || !m_finish)
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::LibcxxStdVectorSyntheticFrontEnd' cannot "
"find index of child '%s'",
name.AsCString());
"find index of child '%s'. (m_start='%d', m_finish='%d')",
name.AsCString(), m_start, m_finish);
size_t index = formatters::ExtractIndexFromString(name.GetCString());
if (index == UINT32_MAX) {
return llvm::createStringError(
Expand Down Expand Up @@ -277,8 +277,8 @@ lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::
if (!m_count || !m_base_data_address)
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::LibcxxVectorBoolSyntheticFrontEnd' cannot "
"find index of child '%s'",
name.AsCString());
"find index of child '%s'. (m_count='%d', m_base_data_address='%d')",
name.AsCString(), m_count, m_base_data_address);
const char *item_name = name.GetCString();
uint32_t idx = ExtractIndexFromString(item_name);
if (idx == UINT32_MAX ||
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Plugins/Language/ObjC/NSArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@ llvm::Expected<size_t> lldb_private::formatters::NSArrayMSyntheticFrontEndBase::
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
return llvm::createStringError(
"'SyntheticChildrenFrontend::NSArrayMSyntheticFrontEndBase' cannot "
"find index of child '%s'",
name.AsCString());
"find index of child '%s'. (idx='%d')",
name.AsCString(), idx);
return idx;
}

Expand Down Expand Up @@ -624,8 +624,8 @@ lldb_private::formatters::GenericNSArrayISyntheticFrontEnd<
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::ObjCClassSyntheticChildrenFrontEnd' "
"cannot find index of child '%s'",
name.AsCString());
"cannot find index of child '%s'. (idx='%d')",
name.AsCString(), idx);
return idx;
}

Expand Down
20 changes: 10 additions & 10 deletions lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ llvm::Expected<size_t> lldb_private::formatters::
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::NSDictionaryISyntheticFrontEnd' cannot "
"find index of child '%s'",
name.AsCString());
"find index of child '%s'. (idx='%d')",
name.AsCString(), idx);
return idx;
}

Expand Down Expand Up @@ -730,8 +730,8 @@ llvm::Expected<size_t> lldb_private::formatters::
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log idx here

return llvm::createStringError(
"'SyntheticChildrenFrontEnd::NSCFDictionarySyntheticFrontEnd' cannot "
"find index of child '%s'",
name.AsCString());
"find index of child '%s'. (idx='%d')",
name.AsCString(), idx);
return idx;
}

Expand Down Expand Up @@ -866,8 +866,8 @@ lldb_private::formatters::NSConstantDictionarySyntheticFrontEnd::
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::NSConstantDictionarySyntheticFrontEnd' "
"cannot find index of child '%s'",
name.AsCString());
"cannot find index of child '%s'. (idx='%d')",
name.AsCString(), idx);
return idx;
}

Expand Down Expand Up @@ -1072,8 +1072,8 @@ lldb_private::formatters::GenericNSDictionaryMSyntheticFrontEnd<
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log idx here

return llvm::createStringError(
"'SyntheticChildrenFrontEnd::GenericNSDictionaryMSyntheticFrontEnd' "
"cannot find index of child '%s'",
name.AsCString());
"cannot find index of child '%s'. (idx='%d')",
name.AsCString(), idx);
return idx;
}

Expand Down Expand Up @@ -1233,8 +1233,8 @@ llvm::Expected<size_t> lldb_private::formatters::Foundation1100::
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::NSDictionaryMSyntheticFrontEnd' cannot "
"find index of child '%s'",
name.AsCString());
"find index of child '%s'. (idx='%d')",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets change all the index logging to:

Suggested change
"find index of child '%s'. (idx='%d')",
"find index of child '%s'. (idx='%" PRIu32 "')",

name.AsCString(), idx);
return idx;
}

Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ class NSIndexPathSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::NSIndexPathSyntheticFrontEnd' cannot "
"find index of child '%s'",
name.AsCString());
"find index of child '%s'. (idx='%d')",
name.AsCString(), idx);
return idx;
}

Expand Down
12 changes: 6 additions & 6 deletions lldb/source/Plugins/Language/ObjC/NSSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ lldb_private::formatters::NSSetISyntheticFrontEnd::GetIndexOfChildWithName(
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::NSSetISyntheticFrontEnd' cannot find "
"index of child '%s'",
name.AsCString());
"index of child '%s'. (idx='%d')",
name.AsCString(), idx);
return idx;
}

Expand Down Expand Up @@ -532,8 +532,8 @@ lldb_private::formatters::NSCFSetSyntheticFrontEnd::GetIndexOfChildWithName(
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
return llvm::createStringError(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets log idx here

"'SyntheticChildrenFrontEnd::NSCFSetSyntheticFrontEnd' cannot find "
"index of child '%s'",
name.AsCString());
"index of child '%s'. (idx='%d')",
name.AsCString(), idx);
return idx;
}

Expand Down Expand Up @@ -670,8 +670,8 @@ llvm::Expected<size_t> lldb_private::formatters::GenericNSSetMSyntheticFrontEnd<
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets log idx here

return llvm::createStringError(
"'SyntheticChildrenFrontEnd::GenericNSSetMSyntheticFrontEnd' cannot "
"find index of child '%s'",
name.AsCString());
"find index of child '%s'. (idx='%d')",
name.AsCString(), idx);
return idx;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2042,21 +2042,21 @@ llvm::Expected<int> ScriptInterpreterPythonImpl::GetIndexOfChildWithName(
if (!implementor_sp)
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::ScriptInterpreterPythonImpl' cannot find "
"index of child '%s'",
child_name);
"index of child '%s'. Invalid implementor (implementor_sp='%p').",
child_name, implementor_sp.get());

StructuredData::Generic *generic = implementor_sp->GetAsGeneric();
if (!generic)
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::ScriptInterpreterPythonImpl' cannot find "
"index of child '%s'",
child_name);
"'ScriptInterpreterPythonImpl' cannot find index of child '%s'. Could "
"not get generic from implementor (generic='%p').",
child_name, generic);
auto *implementor = static_cast<PyObject *>(generic->GetValue());
if (!implementor)
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::ScriptInterpreterPythonImpl' cannot find "
"index of child '%s'",
child_name);
"'ScriptInterpreterPythonImpl' cannot find index of child '%s'. Could "
"not cast to PyObject (implementor='%p')",
child_name, implementor);

int ret_val = INT32_MAX;

Expand All @@ -2069,8 +2069,7 @@ llvm::Expected<int> ScriptInterpreterPythonImpl::GetIndexOfChildWithName(

if (ret_val == INT32_MAX)
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::ScriptInterpreterPythonImpl' cannot find "
"index of child '%s'",
"'ScriptInterpreterPythonImpl' cannot find index of child '%s'",
child_name);
return ret_val;
}
Expand Down
5 changes: 2 additions & 3 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7159,9 +7159,8 @@ TypeSystemClang::GetIndexOfChildWithName(lldb::opaque_compiler_type_t type,
break;
}
}
return llvm::createStringError("'SyntheticChildrenFrontEnd::TypeSystemClang' "
"cannot find index of child '%s'",
name.str().c_str());
return llvm::createStringError(
"'TypeSystemClang' cannot find index of child '%s'", name.str().c_str());
}

CompilerType
Expand Down
5 changes: 2 additions & 3 deletions lldb/source/Symbol/CompilerType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,9 +1031,8 @@ CompilerType::GetIndexOfChildWithName(llvm::StringRef name,
return type_system_sp->GetIndexOfChildWithName(m_type, name,
omit_empty_base_classes);
}
return llvm::createStringError("'SyntheticChildrenFrontEnd::CompilerType' "
"cannot find index of child '%s'",
name.str().c_str());
return llvm::createStringError(
"'CompilerType' cannot find index of child '%s'", name.str().c_str());
}

// Dumping types
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/ValueObject/ValueObjectRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ ValueObjectRegisterSet::GetIndexOfChildWithName(llvm::StringRef name) {
return reg_info->kinds[eRegisterKindLLDB];
}
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::ValueObjectRegisterSet' cannot find index "
"of child '%s'",
"'ValueObjectRegisterSet' cannot find index of child '%s'",
name.str().c_str());
}

Expand Down
11 changes: 8 additions & 3 deletions lldb/source/ValueObject/ValueObjectSyntheticFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,18 @@ ValueObjectSynthetic::GetIndexOfChildWithName(llvm::StringRef name_ref) {
std::lock_guard<std::mutex> guard(m_child_mutex);
m_name_toindex[name.GetCString()] = *index_or_err;
return *index_or_err;
} else if (!found_index && m_synth_filter_up == nullptr)
} else if (!found_index && m_synth_filter_up == nullptr) {
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::ValueObjectSynthetic' cannot find index "
"of child '%s'",
"of child '%s'. m_synth_filter_up is null.",
name.AsCString());
else /*if (iter != m_name_toindex.end())*/
} else if (found_index) {
return *found_index;
} else /*if (iter != m_name_toindex.end())*/
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::ValueObjectSynthetic' cannot find index "
"of child '%s'",
name.AsCString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else /*if (iter != m_name_toindex.end())*/
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::ValueObjectSynthetic' cannot find index "
"of child '%s'",
name.AsCString());
}
return llvm::createStringError(
"'SyntheticChildrenFrontEnd::ValueObjectSynthetic' cannot find index "
"of child '%s'",
name.AsCString());

}

bool ValueObjectSynthetic::IsInScope() { return m_parent->IsInScope(); }
Expand Down
Loading