Skip to content

[lldb] Prevent Task formatter from showing bogus children #10495

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 all commits
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
21 changes: 17 additions & 4 deletions lldb/source/Plugins/Language/Swift/SwiftFormatters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,20 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
case 3: {
if (!m_child_tasks_sp) {
using task_type = decltype(m_task_info.childTasks)::value_type;
const std::vector<task_type> &tasks = m_task_info.childTasks;
std::vector<task_type> tasks = m_task_info.childTasks;

// Remove any bogus child tasks.
// Very rarely, the child tasks include a bogus task which has an
// invalid task id of 0.
llvm::erase_if(tasks, [&](auto task_ptr) {
if (auto task_info =
expectedToOptional(m_reflection_ctx->asyncTaskInfo(task_ptr)))
return task_info->id == 0;
// Don't filter children with errors here. Let these tasks reach the
// formatter's existing error handling.
return false;
});

std::string mangled_typename =
mangledTypenameForTasksTuple(tasks.size());
CompilerType tasks_tuple_type =
Expand Down Expand Up @@ -928,15 +941,14 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {

lldb::ChildCacheState Update() override {
if (auto *runtime = SwiftLanguageRuntime::Get(m_backend.GetProcessSP())) {
ThreadSafeReflectionContext reflection_ctx =
runtime->GetReflectionContext();
m_reflection_ctx = runtime->GetReflectionContext();
ValueObjectSP task_obj_sp = m_backend.GetChildMemberWithName("_task");
if (!task_obj_sp)
return ChildCacheState::eRefetch;
m_task_ptr = task_obj_sp->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
if (m_task_ptr != LLDB_INVALID_ADDRESS) {
llvm::Expected<ReflectionContextInterface::AsyncTaskInfo> task_info =
reflection_ctx->asyncTaskInfo(m_task_ptr);
m_reflection_ctx->asyncTaskInfo(m_task_ptr);
if (auto err = task_info.takeError()) {
LLDB_LOG_ERROR(
GetLog(LLDBLog::DataFormatters | LLDBLog::Types), std::move(err),
Expand Down Expand Up @@ -968,6 +980,7 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
}

private:
ThreadSafeReflectionContext m_reflection_ctx;
TypeSystemSwiftTypeRef *m_ts = nullptr;
addr_t m_task_ptr = LLDB_INVALID_ADDRESS;
ReflectionContextInterface::AsyncTaskInfo m_task_info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_unsafe_continuation_printing(self):
textwrap.dedent(
r"""
\(UnsafeContinuation<Void, Never>\) cont = \{
task = id:(\d+) flags:(?:running|enqueued) \{
task = id:([1-9]\d*) flags:(?:running|enqueued) \{
address = 0x[0-9a-f]+
id = \1
enqueuePriority = 0
Expand All @@ -45,7 +45,7 @@ def test_checked_continuation_printing(self):
textwrap.dedent(
r"""
\(CheckedContinuation<Int, Never>\) cont = \{
task = id:(\d+) flags:(?:running|enqueued) \{
task = id:([1-9]\d*) flags:(?:running|enqueued) \{
address = 0x[0-9a-f]+
id = \1
enqueuePriority = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_top_level_task(self):
patterns=[
textwrap.dedent(
r"""
\(Task<\(\), Error>\) task = id:(\d+) flags:(?:running|enqueued) \{
\(Task<\(\), Error>\) task = id:([1-9]\d*) flags:(?:running|enqueued) \{
address = 0x[0-9a-f]+
id = \1
enqueuePriority = \.medium
Expand All @@ -45,7 +45,7 @@ def test_current_task(self):
patterns=[
textwrap.dedent(
r"""
\(UnsafeCurrentTask\) currentTask = id:(\d+) flags:(?:running\|)?(?:enqueued\|)?asyncLetTask \{
\(UnsafeCurrentTask\) currentTask = id:([1-9]\d*) flags:(?:running\|)?(?:enqueued\|)?asyncLetTask \{
address = 0x[0-9a-f]+
id = \1
enqueuePriority = \.medium
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ def do_test_print(self):
textwrap.dedent(
r"""
\((?:Throwing)?TaskGroup<\(\)\??(?:, Error)?>\) group = \{
\[0\] = id:(\d+) flags:(?:running\|)?(?:enqueued\|)?groupChildTask \{
\[0\] = id:([1-9]\d*) flags:(?:running\|)?(?:enqueued\|)?groupChildTask \{
address = 0x[0-9a-f]+
id = \1
enqueuePriority = \.medium
children = \{\}
\}
\[1\] = id:(\d+) flags:(?:running\|)?(?:enqueued\|)?groupChildTask \{
\[1\] = id:([1-9]\d*) flags:(?:running\|)?(?:enqueued\|)?groupChildTask \{
address = 0x[0-9a-f]+
id = \2
enqueuePriority = \.medium
children = \{\}
\}
\[2\] = id:(\d+) flags:(?:running\|)?(?:enqueued\|)?groupChildTask \{
\[2\] = id:([1-9]\d*) flags:(?:running\|)?(?:enqueued\|)?groupChildTask \{
address = 0x[0-9a-f]+
id = \3
enqueuePriority = \.medium
Expand Down